-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathadmin_methods.go
More file actions
941 lines (866 loc) · 35.6 KB
/
Copy pathadmin_methods.go
File metadata and controls
941 lines (866 loc) · 35.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
package authorizer
import (
"context"
"net/http"
authorizerv1 "github.com/authorizerdev/authorizer-go/internal/genpb/authorizer/v1"
)
// GraphQL selection-set fragments for the admin response types. Kept here so
// each method's query stays readable. Field names mirror the GraphQL schema.
const (
adminUserFields = UserFragment
adminPaginationFields = `pagination { limit page offset total }`
adminWebhookFields = `id event_name event_description endpoint enabled headers created_at updated_at`
adminWebhookLogFields = `id http_status response request webhook_id created_at updated_at`
adminEmailTplFields = `id event_name template design subject created_at updated_at`
adminAuditLogFields = `id actor_id actor_type actor_email action resource_type resource_id ip_address user_agent metadata created_at`
adminVerifReqFields = `id identifier token email expires created_at updated_at nonce redirect_uri`
adminFgaModelFields = `id dsl`
adminFgaTupleFields = `user relation object`
)
// ---------------------------------------------------------------------------
// 1. AdminLogin — establishes an admin session. grpc, rest, gql.
// ---------------------------------------------------------------------------
// AdminLogin validates the admin secret and establishes an admin session.
func (c *AuthorizerAdminClient) AdminLogin(req *authorizerv1.AdminLoginRequest) (*Response, error) {
var res Response
err := c.execute(adminMethodSpec{
name: "AdminLogin",
graphql: &GraphQLRequest{
Query: `mutation adminLogin($data: AdminLoginRequest!) { _admin_login(params: $data) { message } }`,
Variables: map[string]interface{}{"data": req},
},
graphqlField: "_admin_login",
restMethod: http.MethodPost,
restPath: "/v1/admin/login",
restBody: req,
grpcCall: func(ctx context.Context, cli authorizerv1.AuthorizerAdminServiceClient) (interface{}, error) {
return cli.AdminLogin(ctx, req)
},
}, &res)
if err != nil {
return nil, err
}
return &res, nil
}
// ---------------------------------------------------------------------------
// 2. AdminLogout — grpc, rest (no gql).
// ---------------------------------------------------------------------------
// AdminLogout clears the admin session.
func (c *AuthorizerAdminClient) AdminLogout() (*authorizerv1.AdminLogoutResponse, error) {
var res authorizerv1.AdminLogoutResponse
err := c.execute(adminMethodSpec{
name: "AdminLogout",
restMethod: http.MethodPost,
restPath: "/v1/admin/logout",
restBody: &authorizerv1.AdminLogoutRequest{},
grpcCall: func(ctx context.Context, cli authorizerv1.AuthorizerAdminServiceClient) (interface{}, error) {
return cli.AdminLogout(ctx, &authorizerv1.AdminLogoutRequest{})
},
}, &res)
if err != nil {
return nil, err
}
return &res, nil
}
// ---------------------------------------------------------------------------
// 3. AdminSession — grpc, rest (no gql).
// ---------------------------------------------------------------------------
// AdminSession refreshes the admin session.
func (c *AuthorizerAdminClient) AdminSession() (*authorizerv1.AdminSessionResponse, error) {
var res authorizerv1.AdminSessionResponse
err := c.execute(adminMethodSpec{
name: "AdminSession",
restMethod: http.MethodGet,
restPath: "/v1/admin/session",
grpcCall: func(ctx context.Context, cli authorizerv1.AuthorizerAdminServiceClient) (interface{}, error) {
return cli.AdminSession(ctx, &authorizerv1.AdminSessionRequest{})
},
}, &res)
if err != nil {
return nil, err
}
return &res, nil
}
// ---------------------------------------------------------------------------
// 4. AdminMeta — grpc, rest (no gql).
// ---------------------------------------------------------------------------
// AdminMeta returns admin-only configuration metadata (roles, default roles,
// protected roles).
func (c *AuthorizerAdminClient) AdminMeta() (*authorizerv1.AdminMetaResponse, error) {
var res authorizerv1.AdminMetaResponse
err := c.execute(adminMethodSpec{
name: "AdminMeta",
restMethod: http.MethodGet,
restPath: "/v1/admin/meta",
grpcCall: func(ctx context.Context, cli authorizerv1.AuthorizerAdminServiceClient) (interface{}, error) {
return cli.AdminMeta(ctx, &authorizerv1.AdminMetaRequest{})
},
}, &res)
if err != nil {
return nil, err
}
return &res, nil
}
// ---------------------------------------------------------------------------
// 5. Users — grpc, rest, gql.
// ---------------------------------------------------------------------------
// Users returns a paginated list of users.
func (c *AuthorizerAdminClient) Users(req *authorizerv1.UsersRequest) (*authorizerv1.UsersResponse, error) {
var res authorizerv1.UsersResponse
err := c.execute(adminMethodSpec{
name: "Users",
graphql: &GraphQLRequest{
Query: "query users($data: PaginatedRequest) { _users(params: $data) { " + adminPaginationFields + " users { " + adminUserFields + " } } }",
Variables: map[string]interface{}{"data": req},
},
graphqlField: "_users",
restMethod: http.MethodPost,
restPath: "/v1/admin/users",
restBody: req,
grpcCall: func(ctx context.Context, cli authorizerv1.AuthorizerAdminServiceClient) (interface{}, error) {
return cli.Users(ctx, req)
},
}, &res)
if err != nil {
return nil, err
}
return &res, nil
}
// ---------------------------------------------------------------------------
// 6. User — grpc, rest, gql.
// ---------------------------------------------------------------------------
// User returns a single user by id or email.
func (c *AuthorizerAdminClient) User(req *authorizerv1.UserRequest) (*authorizerv1.UserResponse, error) {
var res authorizerv1.UserResponse
err := c.execute(adminMethodSpec{
name: "User",
graphql: &GraphQLRequest{
Query: "query user($data: GetUserRequest!) { _user(params: $data) { " + adminUserFields + " } }",
Variables: map[string]interface{}{"data": req},
},
graphqlField: "_user",
restMethod: http.MethodPost,
restPath: "/v1/admin/user",
restBody: req,
grpcCall: func(ctx context.Context, cli authorizerv1.AuthorizerAdminServiceClient) (interface{}, error) {
return cli.User(ctx, req)
},
}, &res)
if err != nil {
return nil, err
}
return &res, nil
}
// ---------------------------------------------------------------------------
// 7. UpdateUser — grpc, rest, gql.
// ---------------------------------------------------------------------------
// UpdateUser updates an existing user.
func (c *AuthorizerAdminClient) UpdateUser(req *authorizerv1.UpdateUserRequest) (*authorizerv1.UpdateUserResponse, error) {
var res authorizerv1.UpdateUserResponse
err := c.execute(adminMethodSpec{
name: "UpdateUser",
graphql: &GraphQLRequest{
Query: "mutation updateUser($data: UpdateUserRequest!) { _update_user(params: $data) { " + adminUserFields + " } }",
Variables: map[string]interface{}{"data": req},
},
graphqlField: "_update_user",
restMethod: http.MethodPost,
restPath: "/v1/admin/update_user",
restBody: req,
grpcCall: func(ctx context.Context, cli authorizerv1.AuthorizerAdminServiceClient) (interface{}, error) {
return cli.UpdateUser(ctx, req)
},
}, &res)
if err != nil {
return nil, err
}
return &res, nil
}
// ---------------------------------------------------------------------------
// 8. DeleteUser — grpc, rest, gql.
// ---------------------------------------------------------------------------
// DeleteUser deletes a user. DESTRUCTIVE: permanently removes the user account.
func (c *AuthorizerAdminClient) DeleteUser(req *authorizerv1.DeleteUserRequest) (*authorizerv1.DeleteUserResponse, error) {
var res authorizerv1.DeleteUserResponse
err := c.execute(adminMethodSpec{
name: "DeleteUser",
graphql: &GraphQLRequest{
Query: `mutation deleteUser($data: DeleteUserRequest!) { _delete_user(params: $data) { message } }`,
Variables: map[string]interface{}{"data": req},
},
graphqlField: "_delete_user",
restMethod: http.MethodPost,
restPath: "/v1/admin/delete_user",
restBody: req,
grpcCall: func(ctx context.Context, cli authorizerv1.AuthorizerAdminServiceClient) (interface{}, error) {
return cli.DeleteUser(ctx, req)
},
}, &res)
if err != nil {
return nil, err
}
return &res, nil
}
// ---------------------------------------------------------------------------
// 9. VerificationRequests — grpc, rest, gql.
// ---------------------------------------------------------------------------
// VerificationRequests returns a paginated list of pending verification requests.
func (c *AuthorizerAdminClient) VerificationRequests(req *authorizerv1.VerificationRequestsRequest) (*authorizerv1.VerificationRequestsResponse, error) {
var res authorizerv1.VerificationRequestsResponse
err := c.execute(adminMethodSpec{
name: "VerificationRequests",
graphql: &GraphQLRequest{
Query: "query verificationRequests($data: PaginatedRequest) { _verification_requests(params: $data) { " + adminPaginationFields + " verification_requests { " + adminVerifReqFields + " } } }",
Variables: map[string]interface{}{"data": req},
},
graphqlField: "_verification_requests",
restMethod: http.MethodPost,
restPath: "/v1/admin/verification_requests",
restBody: req,
grpcCall: func(ctx context.Context, cli authorizerv1.AuthorizerAdminServiceClient) (interface{}, error) {
return cli.VerificationRequests(ctx, req)
},
}, &res)
if err != nil {
return nil, err
}
return &res, nil
}
// ---------------------------------------------------------------------------
// 10. RevokeAccess — grpc, rest, gql.
// ---------------------------------------------------------------------------
// RevokeAccess revokes a user's access to the application.
func (c *AuthorizerAdminClient) RevokeAccess(req *authorizerv1.RevokeAccessRequest) (*authorizerv1.RevokeAccessResponse, error) {
var res authorizerv1.RevokeAccessResponse
err := c.execute(adminMethodSpec{
name: "RevokeAccess",
graphql: &GraphQLRequest{
Query: `mutation revokeAccess($data: UpdateAccessRequest!) { _revoke_access(param: $data) { message } }`,
Variables: map[string]interface{}{"data": req},
},
graphqlField: "_revoke_access",
restMethod: http.MethodPost,
restPath: "/v1/admin/revoke_access",
restBody: req,
grpcCall: func(ctx context.Context, cli authorizerv1.AuthorizerAdminServiceClient) (interface{}, error) {
return cli.RevokeAccess(ctx, req)
},
}, &res)
if err != nil {
return nil, err
}
return &res, nil
}
// ---------------------------------------------------------------------------
// 11. EnableAccess — grpc, rest, gql.
// ---------------------------------------------------------------------------
// EnableAccess re-enables a previously revoked user's access.
func (c *AuthorizerAdminClient) EnableAccess(req *authorizerv1.EnableAccessRequest) (*authorizerv1.EnableAccessResponse, error) {
var res authorizerv1.EnableAccessResponse
err := c.execute(adminMethodSpec{
name: "EnableAccess",
graphql: &GraphQLRequest{
Query: `mutation enableAccess($data: UpdateAccessRequest!) { _enable_access(param: $data) { message } }`,
Variables: map[string]interface{}{"data": req},
},
graphqlField: "_enable_access",
restMethod: http.MethodPost,
restPath: "/v1/admin/enable_access",
restBody: req,
grpcCall: func(ctx context.Context, cli authorizerv1.AuthorizerAdminServiceClient) (interface{}, error) {
return cli.EnableAccess(ctx, req)
},
}, &res)
if err != nil {
return nil, err
}
return &res, nil
}
// ---------------------------------------------------------------------------
// 12. InviteMembers — grpc, rest, gql.
// ---------------------------------------------------------------------------
// InviteMembers sends invitations to one or more email addresses.
func (c *AuthorizerAdminClient) InviteMembers(req *authorizerv1.InviteMembersRequest) (*authorizerv1.InviteMembersResponse, error) {
var res authorizerv1.InviteMembersResponse
err := c.execute(adminMethodSpec{
name: "InviteMembers",
graphql: &GraphQLRequest{
Query: "mutation inviteMembers($data: InviteMemberRequest!) { _invite_members(params: $data) { message Users { " + adminUserFields + " } } }",
Variables: map[string]interface{}{"data": req},
},
graphqlField: "_invite_members",
restMethod: http.MethodPost,
restPath: "/v1/admin/invite_members",
restBody: req,
grpcCall: func(ctx context.Context, cli authorizerv1.AuthorizerAdminServiceClient) (interface{}, error) {
return cli.InviteMembers(ctx, req)
},
}, &res)
if err != nil {
return nil, err
}
return &res, nil
}
// ---------------------------------------------------------------------------
// 13. AddWebhook — grpc, rest, gql.
// ---------------------------------------------------------------------------
// AddWebhook registers a new webhook endpoint.
func (c *AuthorizerAdminClient) AddWebhook(req *authorizerv1.AddWebhookRequest) (*authorizerv1.AddWebhookResponse, error) {
var res authorizerv1.AddWebhookResponse
err := c.execute(adminMethodSpec{
name: "AddWebhook",
graphql: &GraphQLRequest{
Query: `mutation addWebhook($data: AddWebhookRequest!) { _add_webhook(params: $data) { message } }`,
Variables: map[string]interface{}{"data": req},
},
graphqlField: "_add_webhook",
restMethod: http.MethodPost,
restPath: "/v1/admin/add_webhook",
restBody: req,
grpcCall: func(ctx context.Context, cli authorizerv1.AuthorizerAdminServiceClient) (interface{}, error) {
return cli.AddWebhook(ctx, req)
},
}, &res)
if err != nil {
return nil, err
}
return &res, nil
}
// ---------------------------------------------------------------------------
// 14. UpdateWebhook — grpc, rest, gql.
// ---------------------------------------------------------------------------
// UpdateWebhook updates an existing webhook.
func (c *AuthorizerAdminClient) UpdateWebhook(req *authorizerv1.UpdateWebhookRequest) (*authorizerv1.UpdateWebhookResponse, error) {
var res authorizerv1.UpdateWebhookResponse
err := c.execute(adminMethodSpec{
name: "UpdateWebhook",
graphql: &GraphQLRequest{
Query: `mutation updateWebhook($data: UpdateWebhookRequest!) { _update_webhook(params: $data) { message } }`,
Variables: map[string]interface{}{"data": req},
},
graphqlField: "_update_webhook",
restMethod: http.MethodPost,
restPath: "/v1/admin/update_webhook",
restBody: req,
grpcCall: func(ctx context.Context, cli authorizerv1.AuthorizerAdminServiceClient) (interface{}, error) {
return cli.UpdateWebhook(ctx, req)
},
}, &res)
if err != nil {
return nil, err
}
return &res, nil
}
// ---------------------------------------------------------------------------
// 15. DeleteWebhook — grpc, rest, gql.
// ---------------------------------------------------------------------------
// DeleteWebhook deletes a webhook. DESTRUCTIVE: permanently removes the webhook
// and its logs.
func (c *AuthorizerAdminClient) DeleteWebhook(req *authorizerv1.DeleteWebhookRequest) (*authorizerv1.DeleteWebhookResponse, error) {
var res authorizerv1.DeleteWebhookResponse
err := c.execute(adminMethodSpec{
name: "DeleteWebhook",
graphql: &GraphQLRequest{
Query: `mutation deleteWebhook($data: WebhookRequest!) { _delete_webhook(params: $data) { message } }`,
Variables: map[string]interface{}{"data": req},
},
graphqlField: "_delete_webhook",
restMethod: http.MethodPost,
restPath: "/v1/admin/delete_webhook",
restBody: req,
grpcCall: func(ctx context.Context, cli authorizerv1.AuthorizerAdminServiceClient) (interface{}, error) {
return cli.DeleteWebhook(ctx, req)
},
}, &res)
if err != nil {
return nil, err
}
return &res, nil
}
// ---------------------------------------------------------------------------
// 16. GetWebhook — grpc, rest, gql.
// ---------------------------------------------------------------------------
// GetWebhook returns a single webhook by id.
func (c *AuthorizerAdminClient) GetWebhook(req *authorizerv1.GetWebhookRequest) (*authorizerv1.GetWebhookResponse, error) {
var res authorizerv1.GetWebhookResponse
err := c.execute(adminMethodSpec{
name: "GetWebhook",
graphql: &GraphQLRequest{
Query: "query webhook($data: WebhookRequest!) { _webhook(params: $data) { " + adminWebhookFields + " } }",
Variables: map[string]interface{}{"data": req},
},
graphqlField: "_webhook",
restMethod: http.MethodPost,
restPath: "/v1/admin/webhook",
restBody: req,
grpcCall: func(ctx context.Context, cli authorizerv1.AuthorizerAdminServiceClient) (interface{}, error) {
return cli.GetWebhook(ctx, req)
},
}, &res)
if err != nil {
return nil, err
}
return &res, nil
}
// ---------------------------------------------------------------------------
// 17. Webhooks — grpc, rest, gql.
// ---------------------------------------------------------------------------
// Webhooks returns a paginated list of webhooks.
func (c *AuthorizerAdminClient) Webhooks(req *authorizerv1.WebhooksRequest) (*authorizerv1.WebhooksResponse, error) {
var res authorizerv1.WebhooksResponse
err := c.execute(adminMethodSpec{
name: "Webhooks",
graphql: &GraphQLRequest{
Query: "query webhooks($data: PaginatedRequest) { _webhooks(params: $data) { " + adminPaginationFields + " webhooks { " + adminWebhookFields + " } } }",
Variables: map[string]interface{}{"data": req},
},
graphqlField: "_webhooks",
restMethod: http.MethodPost,
restPath: "/v1/admin/webhooks",
restBody: req,
grpcCall: func(ctx context.Context, cli authorizerv1.AuthorizerAdminServiceClient) (interface{}, error) {
return cli.Webhooks(ctx, req)
},
}, &res)
if err != nil {
return nil, err
}
return &res, nil
}
// ---------------------------------------------------------------------------
// 18. WebhookLogs — grpc, rest, gql.
// ---------------------------------------------------------------------------
// WebhookLogs returns a paginated list of webhook delivery logs.
func (c *AuthorizerAdminClient) WebhookLogs(req *authorizerv1.WebhookLogsRequest) (*authorizerv1.WebhookLogsResponse, error) {
var res authorizerv1.WebhookLogsResponse
err := c.execute(adminMethodSpec{
name: "WebhookLogs",
graphql: &GraphQLRequest{
Query: "query webhookLogs($data: ListWebhookLogRequest) { _webhook_logs(params: $data) { " + adminPaginationFields + " webhook_logs { " + adminWebhookLogFields + " } } }",
Variables: map[string]interface{}{"data": req},
},
graphqlField: "_webhook_logs",
restMethod: http.MethodPost,
restPath: "/v1/admin/webhook_logs",
restBody: req,
grpcCall: func(ctx context.Context, cli authorizerv1.AuthorizerAdminServiceClient) (interface{}, error) {
return cli.WebhookLogs(ctx, req)
},
}, &res)
if err != nil {
return nil, err
}
return &res, nil
}
// ---------------------------------------------------------------------------
// 19. TestEndpoint — grpc, rest, gql.
// ---------------------------------------------------------------------------
// TestEndpoint sends a test event to a webhook endpoint.
func (c *AuthorizerAdminClient) TestEndpoint(req *authorizerv1.TestEndpointRequest) (*authorizerv1.TestEndpointResponse, error) {
var res authorizerv1.TestEndpointResponse
err := c.execute(adminMethodSpec{
name: "TestEndpoint",
graphql: &GraphQLRequest{
Query: `mutation testEndpoint($data: TestEndpointRequest!) { _test_endpoint(params: $data) { http_status response } }`,
Variables: map[string]interface{}{"data": req},
},
graphqlField: "_test_endpoint",
restMethod: http.MethodPost,
restPath: "/v1/admin/test_endpoint",
restBody: req,
grpcCall: func(ctx context.Context, cli authorizerv1.AuthorizerAdminServiceClient) (interface{}, error) {
return cli.TestEndpoint(ctx, req)
},
}, &res)
if err != nil {
return nil, err
}
return &res, nil
}
// ---------------------------------------------------------------------------
// 20. AddEmailTemplate — grpc, rest, gql.
// ---------------------------------------------------------------------------
// AddEmailTemplate creates a new email template.
func (c *AuthorizerAdminClient) AddEmailTemplate(req *authorizerv1.AddEmailTemplateRequest) (*authorizerv1.AddEmailTemplateResponse, error) {
var res authorizerv1.AddEmailTemplateResponse
err := c.execute(adminMethodSpec{
name: "AddEmailTemplate",
graphql: &GraphQLRequest{
Query: `mutation addEmailTemplate($data: AddEmailTemplateRequest!) { _add_email_template(params: $data) { message } }`,
Variables: map[string]interface{}{"data": req},
},
graphqlField: "_add_email_template",
restMethod: http.MethodPost,
restPath: "/v1/admin/add_email_template",
restBody: req,
grpcCall: func(ctx context.Context, cli authorizerv1.AuthorizerAdminServiceClient) (interface{}, error) {
return cli.AddEmailTemplate(ctx, req)
},
}, &res)
if err != nil {
return nil, err
}
return &res, nil
}
// ---------------------------------------------------------------------------
// 21. UpdateEmailTemplate — grpc, rest, gql.
// ---------------------------------------------------------------------------
// UpdateEmailTemplate updates an existing email template.
func (c *AuthorizerAdminClient) UpdateEmailTemplate(req *authorizerv1.UpdateEmailTemplateRequest) (*authorizerv1.UpdateEmailTemplateResponse, error) {
var res authorizerv1.UpdateEmailTemplateResponse
err := c.execute(adminMethodSpec{
name: "UpdateEmailTemplate",
graphql: &GraphQLRequest{
Query: `mutation updateEmailTemplate($data: UpdateEmailTemplateRequest!) { _update_email_template(params: $data) { message } }`,
Variables: map[string]interface{}{"data": req},
},
graphqlField: "_update_email_template",
restMethod: http.MethodPost,
restPath: "/v1/admin/update_email_template",
restBody: req,
grpcCall: func(ctx context.Context, cli authorizerv1.AuthorizerAdminServiceClient) (interface{}, error) {
return cli.UpdateEmailTemplate(ctx, req)
},
}, &res)
if err != nil {
return nil, err
}
return &res, nil
}
// ---------------------------------------------------------------------------
// 22. DeleteEmailTemplate — grpc, rest, gql.
// ---------------------------------------------------------------------------
// DeleteEmailTemplate deletes an email template. DESTRUCTIVE: permanently
// removes the template.
func (c *AuthorizerAdminClient) DeleteEmailTemplate(req *authorizerv1.DeleteEmailTemplateRequest) (*authorizerv1.DeleteEmailTemplateResponse, error) {
var res authorizerv1.DeleteEmailTemplateResponse
err := c.execute(adminMethodSpec{
name: "DeleteEmailTemplate",
graphql: &GraphQLRequest{
Query: `mutation deleteEmailTemplate($data: DeleteEmailTemplateRequest!) { _delete_email_template(params: $data) { message } }`,
Variables: map[string]interface{}{"data": req},
},
graphqlField: "_delete_email_template",
restMethod: http.MethodPost,
restPath: "/v1/admin/delete_email_template",
restBody: req,
grpcCall: func(ctx context.Context, cli authorizerv1.AuthorizerAdminServiceClient) (interface{}, error) {
return cli.DeleteEmailTemplate(ctx, req)
},
}, &res)
if err != nil {
return nil, err
}
return &res, nil
}
// ---------------------------------------------------------------------------
// 23. EmailTemplates — grpc, rest, gql.
// ---------------------------------------------------------------------------
// EmailTemplates returns a paginated list of email templates.
func (c *AuthorizerAdminClient) EmailTemplates(req *authorizerv1.EmailTemplatesRequest) (*authorizerv1.EmailTemplatesResponse, error) {
var res authorizerv1.EmailTemplatesResponse
err := c.execute(adminMethodSpec{
name: "EmailTemplates",
graphql: &GraphQLRequest{
Query: "query emailTemplates($data: PaginatedRequest) { _email_templates(params: $data) { " + adminPaginationFields + " email_templates { " + adminEmailTplFields + " } } }",
Variables: map[string]interface{}{"data": req},
},
graphqlField: "_email_templates",
restMethod: http.MethodPost,
restPath: "/v1/admin/email_templates",
restBody: req,
grpcCall: func(ctx context.Context, cli authorizerv1.AuthorizerAdminServiceClient) (interface{}, error) {
return cli.EmailTemplates(ctx, req)
},
}, &res)
if err != nil {
return nil, err
}
return &res, nil
}
// ---------------------------------------------------------------------------
// 24. AuditLogs — grpc, rest, gql.
// ---------------------------------------------------------------------------
// AuditLogs returns a paginated list of audit log entries.
func (c *AuthorizerAdminClient) AuditLogs(req *authorizerv1.AuditLogsRequest) (*authorizerv1.AuditLogsResponse, error) {
var res authorizerv1.AuditLogsResponse
err := c.execute(adminMethodSpec{
name: "AuditLogs",
graphql: &GraphQLRequest{
Query: "query auditLogs($data: ListAuditLogRequest) { _audit_logs(params: $data) { " + adminPaginationFields + " audit_logs { " + adminAuditLogFields + " } } }",
Variables: map[string]interface{}{"data": req},
},
graphqlField: "_audit_logs",
restMethod: http.MethodPost,
restPath: "/v1/admin/audit_logs",
restBody: req,
grpcCall: func(ctx context.Context, cli authorizerv1.AuthorizerAdminServiceClient) (interface{}, error) {
return cli.AuditLogs(ctx, req)
},
}, &res)
if err != nil {
return nil, err
}
return &res, nil
}
// ---------------------------------------------------------------------------
// 25. FgaGetModel — grpc, rest (no gql).
// ---------------------------------------------------------------------------
// FgaGetModel returns the active fine-grained authorization model as DSL.
func (c *AuthorizerAdminClient) FgaGetModel() (*authorizerv1.FgaGetModelResponse, error) {
var res authorizerv1.FgaGetModelResponse
err := c.execute(adminMethodSpec{
name: "FgaGetModel",
restMethod: http.MethodGet,
restPath: "/v1/admin/fga/model",
grpcCall: func(ctx context.Context, cli authorizerv1.AuthorizerAdminServiceClient) (interface{}, error) {
return cli.FgaGetModel(ctx, &authorizerv1.FgaGetModelRequest{})
},
}, &res)
if err != nil {
return nil, err
}
return &res, nil
}
// ---------------------------------------------------------------------------
// 26. FgaWriteModel — grpc, rest, gql.
// ---------------------------------------------------------------------------
// FgaWriteModel replaces the fine-grained authorization model. DESTRUCTIVE:
// overwrites the existing authorization model.
func (c *AuthorizerAdminClient) FgaWriteModel(req *authorizerv1.FgaWriteModelRequest) (*authorizerv1.FgaWriteModelResponse, error) {
var res authorizerv1.FgaWriteModelResponse
err := c.execute(adminMethodSpec{
name: "FgaWriteModel",
graphql: &GraphQLRequest{
Query: "mutation fgaWriteModel($data: FgaWriteModelInput!) { _fga_write_model(params: $data) { " + adminFgaModelFields + " } }",
Variables: map[string]interface{}{"data": req},
},
graphqlField: "_fga_write_model",
restMethod: http.MethodPost,
restPath: "/v1/admin/fga/model",
restBody: req,
grpcCall: func(ctx context.Context, cli authorizerv1.AuthorizerAdminServiceClient) (interface{}, error) {
return cli.FgaWriteModel(ctx, req)
},
}, &res)
if err != nil {
return nil, err
}
return &res, nil
}
// ---------------------------------------------------------------------------
// 27. FgaWriteTuples — grpc, rest, gql.
// ---------------------------------------------------------------------------
// FgaWriteTuples writes relationship tuples to the authorization store.
func (c *AuthorizerAdminClient) FgaWriteTuples(req *authorizerv1.FgaWriteTuplesRequest) (*authorizerv1.FgaWriteTuplesResponse, error) {
var res authorizerv1.FgaWriteTuplesResponse
err := c.execute(adminMethodSpec{
name: "FgaWriteTuples",
graphql: &GraphQLRequest{
Query: `mutation fgaWriteTuples($data: FgaWriteTuplesInput!) { _fga_write_tuples(params: $data) { message } }`,
Variables: map[string]interface{}{"data": req},
},
graphqlField: "_fga_write_tuples",
restMethod: http.MethodPost,
restPath: "/v1/admin/fga/tuples",
restBody: req,
grpcCall: func(ctx context.Context, cli authorizerv1.AuthorizerAdminServiceClient) (interface{}, error) {
return cli.FgaWriteTuples(ctx, req)
},
}, &res)
if err != nil {
return nil, err
}
return &res, nil
}
// ---------------------------------------------------------------------------
// 28. FgaDeleteTuples — grpc, rest, gql.
// ---------------------------------------------------------------------------
// FgaDeleteTuples deletes relationship tuples from the authorization store.
// DESTRUCTIVE: permanently removes the specified tuples.
func (c *AuthorizerAdminClient) FgaDeleteTuples(req *authorizerv1.FgaDeleteTuplesRequest) (*authorizerv1.FgaDeleteTuplesResponse, error) {
var res authorizerv1.FgaDeleteTuplesResponse
err := c.execute(adminMethodSpec{
name: "FgaDeleteTuples",
graphql: &GraphQLRequest{
Query: `mutation fgaDeleteTuples($data: FgaWriteTuplesInput!) { _fga_delete_tuples(params: $data) { message } }`,
Variables: map[string]interface{}{"data": req},
},
graphqlField: "_fga_delete_tuples",
restMethod: http.MethodPost,
restPath: "/v1/admin/fga/tuples/delete",
restBody: req,
grpcCall: func(ctx context.Context, cli authorizerv1.AuthorizerAdminServiceClient) (interface{}, error) {
return cli.FgaDeleteTuples(ctx, req)
},
}, &res)
if err != nil {
return nil, err
}
return &res, nil
}
// ---------------------------------------------------------------------------
// 29. FgaReadTuples — grpc, rest, gql.
// ---------------------------------------------------------------------------
// FgaReadTuples reads relationship tuples from the authorization store.
func (c *AuthorizerAdminClient) FgaReadTuples(req *authorizerv1.FgaReadTuplesRequest) (*authorizerv1.FgaReadTuplesResponse, error) {
var res authorizerv1.FgaReadTuplesResponse
err := c.execute(adminMethodSpec{
name: "FgaReadTuples",
graphql: &GraphQLRequest{
Query: "query fgaReadTuples($data: FgaReadTuplesInput!) { _fga_read_tuples(params: $data) { tuples { " + adminFgaTupleFields + " } continuation_token } }",
Variables: map[string]interface{}{"data": req},
},
graphqlField: "_fga_read_tuples",
restMethod: http.MethodPost,
restPath: "/v1/admin/fga/tuples/read",
restBody: req,
grpcCall: func(ctx context.Context, cli authorizerv1.AuthorizerAdminServiceClient) (interface{}, error) {
return cli.FgaReadTuples(ctx, req)
},
}, &res)
if err != nil {
return nil, err
}
return &res, nil
}
// ---------------------------------------------------------------------------
// 30. FgaListUsers — grpc, rest, gql.
// ---------------------------------------------------------------------------
// FgaListUsers lists users that have a given relation to an object.
func (c *AuthorizerAdminClient) FgaListUsers(req *authorizerv1.FgaListUsersRequest) (*authorizerv1.FgaListUsersResponse, error) {
var res authorizerv1.FgaListUsersResponse
err := c.execute(adminMethodSpec{
name: "FgaListUsers",
graphql: &GraphQLRequest{
Query: `query fgaListUsers($data: FgaListUsersInput!) { _fga_list_users(params: $data) { users } }`,
Variables: map[string]interface{}{"data": req},
},
graphqlField: "_fga_list_users",
restMethod: http.MethodPost,
restPath: "/v1/admin/fga/list_users",
restBody: req,
grpcCall: func(ctx context.Context, cli authorizerv1.AuthorizerAdminServiceClient) (interface{}, error) {
return cli.FgaListUsers(ctx, req)
},
}, &res)
if err != nil {
return nil, err
}
return &res, nil
}
// ---------------------------------------------------------------------------
// 31. FgaExpand — grpc, rest, gql.
// ---------------------------------------------------------------------------
// FgaExpand expands the relationship tree for a given object and relation.
func (c *AuthorizerAdminClient) FgaExpand(req *authorizerv1.FgaExpandRequest) (*authorizerv1.FgaExpandResponse, error) {
var res authorizerv1.FgaExpandResponse
err := c.execute(adminMethodSpec{
name: "FgaExpand",
graphql: &GraphQLRequest{
Query: `query fgaExpand($data: FgaExpandInput!) { _fga_expand(params: $data) { tree } }`,
Variables: map[string]interface{}{"data": req},
},
graphqlField: "_fga_expand",
restMethod: http.MethodPost,
restPath: "/v1/admin/fga/expand",
restBody: req,
grpcCall: func(ctx context.Context, cli authorizerv1.AuthorizerAdminServiceClient) (interface{}, error) {
return cli.FgaExpand(ctx, req)
},
}, &res)
if err != nil {
return nil, err
}
return &res, nil
}
// ---------------------------------------------------------------------------
// 32. FgaReset — grpc, rest (no gql).
// ---------------------------------------------------------------------------
// FgaReset deletes the entire fine-grained authorization store. DESTRUCTIVE:
// permanently removes the model and all relationship tuples.
func (c *AuthorizerAdminClient) FgaReset() (*authorizerv1.FgaResetResponse, error) {
var res authorizerv1.FgaResetResponse
err := c.execute(adminMethodSpec{
name: "FgaReset",
restMethod: http.MethodPost,
restPath: "/v1/admin/fga/reset",
restBody: &authorizerv1.FgaResetRequest{},
grpcCall: func(ctx context.Context, cli authorizerv1.AuthorizerAdminServiceClient) (interface{}, error) {
return cli.FgaReset(ctx, &authorizerv1.FgaResetRequest{})
},
}, &res)
if err != nil {
return nil, err
}
return &res, nil
}
// ---------------------------------------------------------------------------
// GraphQL-only admin operations. These have no gRPC stub or REST endpoint, so
// only the graphql protocol is supported. The proto definitions do not include
// these operations, so local request/response types are declared here.
// ---------------------------------------------------------------------------
// AdminSignupRequest is the request for AdminSignup.
type AdminSignupRequest struct {
AdminSecret string `json:"admin_secret"`
}
// AdminSignup sets the admin secret for a fresh instance (gql only).
func (c *AuthorizerAdminClient) AdminSignup(req *AdminSignupRequest) (*Response, error) {
var res Response
err := c.execute(adminMethodSpec{
name: "AdminSignup",
graphql: &GraphQLRequest{
Query: `mutation adminSignup($data: AdminSignupRequest!) { _admin_signup(params: $data) { message } }`,
Variables: map[string]interface{}{"data": req},
},
graphqlField: "_admin_signup",
}, &res)
if err != nil {
return nil, err
}
return &res, nil
}
// UpdateEnvRequest is a flexible map of environment keys to update.
type UpdateEnvRequest map[string]interface{}
// UpdateEnv updates the instance environment configuration (gql only).
func (c *AuthorizerAdminClient) UpdateEnv(req *UpdateEnvRequest) (*Response, error) {
var res Response
err := c.execute(adminMethodSpec{
name: "UpdateEnv",
graphql: &GraphQLRequest{
Query: `mutation updateEnv($data: UpdateEnvInput!) { _update_env(params: $data) { message } }`,
Variables: map[string]interface{}{"data": req},
},
graphqlField: "_update_env",
}, &res)
if err != nil {
return nil, err
}
return &res, nil
}
// GenerateJWTKeysRequest is the request for GenerateJWTKeys.
type GenerateJWTKeysRequest struct {
Type string `json:"type"`
}
// GenerateJWTKeysResponse is the response for GenerateJWTKeys.
type GenerateJWTKeysResponse struct {
Secret *string `json:"secret"`
PublicKey *string `json:"public_key"`
PrivateKey *string `json:"private_key"`
}
// GenerateJWTKeys generates a new set of JWT signing keys (gql only).
func (c *AuthorizerAdminClient) GenerateJWTKeys(req *GenerateJWTKeysRequest) (*GenerateJWTKeysResponse, error) {
var res GenerateJWTKeysResponse
err := c.execute(adminMethodSpec{
name: "GenerateJWTKeys",
graphql: &GraphQLRequest{
Query: `query generateJwtKeys($data: GenerateJWTKeysRequest!) { _generate_jwt_keys(params: $data) { secret public_key private_key } }`,
Variables: map[string]interface{}{"data": req},
},
graphqlField: "_generate_jwt_keys",
}, &res)
if err != nil {
return nil, err
}
return &res, nil
}