-
Notifications
You must be signed in to change notification settings - Fork 37
/
api.go
executable file
·2368 lines (2095 loc) · 84.5 KB
/
api.go
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
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT.
// These APIs allow you to manage Account Access Control, Account Access Control Proxy, Account Groups, Account Service Principals, Account Users, Current User, Groups, Permission Migration, Permissions, Service Principals, Users, Workspace Assignment, etc.
package iam
import (
"context"
"fmt"
"github.com/databricks/databricks-sdk-go/client"
"github.com/databricks/databricks-sdk-go/listing"
"github.com/databricks/databricks-sdk-go/useragent"
)
type AccountAccessControlInterface interface {
// WithImpl could be used to override low-level API implementations for unit
// testing purposes with [github.com/golang/mock] or other mocking frameworks.
// Deprecated: use MockAccountAccessControlInterface instead.
WithImpl(impl AccountAccessControlService) AccountAccessControlInterface
// Impl returns low-level AccountAccessControl API implementation
// Deprecated: use MockAccountAccessControlInterface instead.
Impl() AccountAccessControlService
// Get assignable roles for a resource.
//
// Gets all the roles that can be granted on an account level resource. A role
// is grantable if the rule set on the resource can contain an access rule of
// the role.
GetAssignableRolesForResource(ctx context.Context, request GetAssignableRolesForResourceRequest) (*GetAssignableRolesForResourceResponse, error)
// Get a rule set.
//
// Get a rule set by its name. A rule set is always attached to a resource and
// contains a list of access rules on the said resource. Currently only a
// default rule set for each resource is supported.
GetRuleSet(ctx context.Context, request GetRuleSetRequest) (*RuleSetResponse, error)
// Update a rule set.
//
// Replace the rules of a rule set. First, use get to read the current version
// of the rule set before modifying it. This pattern helps prevent conflicts
// between concurrent updates.
UpdateRuleSet(ctx context.Context, request UpdateRuleSetRequest) (*RuleSetResponse, error)
}
func NewAccountAccessControl(client *client.DatabricksClient) *AccountAccessControlAPI {
return &AccountAccessControlAPI{
impl: &accountAccessControlImpl{
client: client,
},
}
}
// These APIs manage access rules on resources in an account. Currently, only
// grant rules are supported. A grant rule specifies a role assigned to a set of
// principals. A list of rules attached to a resource is called a rule set.
type AccountAccessControlAPI struct {
// impl contains low-level REST API interface, that could be overridden
// through WithImpl(AccountAccessControlService)
impl AccountAccessControlService
}
// WithImpl could be used to override low-level API implementations for unit
// testing purposes with [github.com/golang/mock] or other mocking frameworks.
// Deprecated: use MockAccountAccessControlInterface instead.
func (a *AccountAccessControlAPI) WithImpl(impl AccountAccessControlService) AccountAccessControlInterface {
a.impl = impl
return a
}
// Impl returns low-level AccountAccessControl API implementation
// Deprecated: use MockAccountAccessControlInterface instead.
func (a *AccountAccessControlAPI) Impl() AccountAccessControlService {
return a.impl
}
// Get assignable roles for a resource.
//
// Gets all the roles that can be granted on an account level resource. A role
// is grantable if the rule set on the resource can contain an access rule of
// the role.
func (a *AccountAccessControlAPI) GetAssignableRolesForResource(ctx context.Context, request GetAssignableRolesForResourceRequest) (*GetAssignableRolesForResourceResponse, error) {
return a.impl.GetAssignableRolesForResource(ctx, request)
}
// Get a rule set.
//
// Get a rule set by its name. A rule set is always attached to a resource and
// contains a list of access rules on the said resource. Currently only a
// default rule set for each resource is supported.
func (a *AccountAccessControlAPI) GetRuleSet(ctx context.Context, request GetRuleSetRequest) (*RuleSetResponse, error) {
return a.impl.GetRuleSet(ctx, request)
}
// Update a rule set.
//
// Replace the rules of a rule set. First, use get to read the current version
// of the rule set before modifying it. This pattern helps prevent conflicts
// between concurrent updates.
func (a *AccountAccessControlAPI) UpdateRuleSet(ctx context.Context, request UpdateRuleSetRequest) (*RuleSetResponse, error) {
return a.impl.UpdateRuleSet(ctx, request)
}
type AccountAccessControlProxyInterface interface {
// WithImpl could be used to override low-level API implementations for unit
// testing purposes with [github.com/golang/mock] or other mocking frameworks.
// Deprecated: use MockAccountAccessControlProxyInterface instead.
WithImpl(impl AccountAccessControlProxyService) AccountAccessControlProxyInterface
// Impl returns low-level AccountAccessControlProxy API implementation
// Deprecated: use MockAccountAccessControlProxyInterface instead.
Impl() AccountAccessControlProxyService
// Get assignable roles for a resource.
//
// Gets all the roles that can be granted on an account-level resource. A role
// is grantable if the rule set on the resource can contain an access rule of
// the role.
GetAssignableRolesForResource(ctx context.Context, request GetAssignableRolesForResourceRequest) (*GetAssignableRolesForResourceResponse, error)
// Get a rule set.
//
// Get a rule set by its name. A rule set is always attached to a resource and
// contains a list of access rules on the said resource. Currently only a
// default rule set for each resource is supported.
GetRuleSet(ctx context.Context, request GetRuleSetRequest) (*RuleSetResponse, error)
// Update a rule set.
//
// Replace the rules of a rule set. First, use a GET rule set request to read
// the current version of the rule set before modifying it. This pattern helps
// prevent conflicts between concurrent updates.
UpdateRuleSet(ctx context.Context, request UpdateRuleSetRequest) (*RuleSetResponse, error)
}
func NewAccountAccessControlProxy(client *client.DatabricksClient) *AccountAccessControlProxyAPI {
return &AccountAccessControlProxyAPI{
impl: &accountAccessControlProxyImpl{
client: client,
},
}
}
// These APIs manage access rules on resources in an account. Currently, only
// grant rules are supported. A grant rule specifies a role assigned to a set of
// principals. A list of rules attached to a resource is called a rule set. A
// workspace must belong to an account for these APIs to work.
type AccountAccessControlProxyAPI struct {
// impl contains low-level REST API interface, that could be overridden
// through WithImpl(AccountAccessControlProxyService)
impl AccountAccessControlProxyService
}
// WithImpl could be used to override low-level API implementations for unit
// testing purposes with [github.com/golang/mock] or other mocking frameworks.
// Deprecated: use MockAccountAccessControlProxyInterface instead.
func (a *AccountAccessControlProxyAPI) WithImpl(impl AccountAccessControlProxyService) AccountAccessControlProxyInterface {
a.impl = impl
return a
}
// Impl returns low-level AccountAccessControlProxy API implementation
// Deprecated: use MockAccountAccessControlProxyInterface instead.
func (a *AccountAccessControlProxyAPI) Impl() AccountAccessControlProxyService {
return a.impl
}
// Get assignable roles for a resource.
//
// Gets all the roles that can be granted on an account-level resource. A role
// is grantable if the rule set on the resource can contain an access rule of
// the role.
func (a *AccountAccessControlProxyAPI) GetAssignableRolesForResource(ctx context.Context, request GetAssignableRolesForResourceRequest) (*GetAssignableRolesForResourceResponse, error) {
return a.impl.GetAssignableRolesForResource(ctx, request)
}
// Get a rule set.
//
// Get a rule set by its name. A rule set is always attached to a resource and
// contains a list of access rules on the said resource. Currently only a
// default rule set for each resource is supported.
func (a *AccountAccessControlProxyAPI) GetRuleSet(ctx context.Context, request GetRuleSetRequest) (*RuleSetResponse, error) {
return a.impl.GetRuleSet(ctx, request)
}
// Update a rule set.
//
// Replace the rules of a rule set. First, use a GET rule set request to read
// the current version of the rule set before modifying it. This pattern helps
// prevent conflicts between concurrent updates.
func (a *AccountAccessControlProxyAPI) UpdateRuleSet(ctx context.Context, request UpdateRuleSetRequest) (*RuleSetResponse, error) {
return a.impl.UpdateRuleSet(ctx, request)
}
type AccountGroupsInterface interface {
// WithImpl could be used to override low-level API implementations for unit
// testing purposes with [github.com/golang/mock] or other mocking frameworks.
// Deprecated: use MockAccountGroupsInterface instead.
WithImpl(impl AccountGroupsService) AccountGroupsInterface
// Impl returns low-level AccountGroups API implementation
// Deprecated: use MockAccountGroupsInterface instead.
Impl() AccountGroupsService
// Create a new group.
//
// Creates a group in the Databricks account with a unique name, using the
// supplied group details.
Create(ctx context.Context, request Group) (*Group, error)
// Delete a group.
//
// Deletes a group from the Databricks account.
Delete(ctx context.Context, request DeleteAccountGroupRequest) error
// Delete a group.
//
// Deletes a group from the Databricks account.
DeleteById(ctx context.Context, id string) error
// Get group details.
//
// Gets the information for a specific group in the Databricks account.
Get(ctx context.Context, request GetAccountGroupRequest) (*Group, error)
// Get group details.
//
// Gets the information for a specific group in the Databricks account.
GetById(ctx context.Context, id string) (*Group, error)
// List group details.
//
// Gets all details of the groups associated with the Databricks account.
//
// This method is generated by Databricks SDK Code Generator.
List(ctx context.Context, request ListAccountGroupsRequest) listing.Iterator[Group]
// List group details.
//
// Gets all details of the groups associated with the Databricks account.
//
// This method is generated by Databricks SDK Code Generator.
ListAll(ctx context.Context, request ListAccountGroupsRequest) ([]Group, error)
// GroupDisplayNameToIdMap calls [AccountGroupsAPI.ListAll] and creates a map of results with [Group].DisplayName as key and [Group].Id as value.
//
// Returns an error if there's more than one [Group] with the same .DisplayName.
//
// Note: All [Group] instances are loaded into memory before creating a map.
//
// This method is generated by Databricks SDK Code Generator.
GroupDisplayNameToIdMap(ctx context.Context, request ListAccountGroupsRequest) (map[string]string, error)
// GetByDisplayName calls [AccountGroupsAPI.GroupDisplayNameToIdMap] and returns a single [Group].
//
// Returns an error if there's more than one [Group] with the same .DisplayName.
//
// Note: All [Group] instances are loaded into memory before returning matching by name.
//
// This method is generated by Databricks SDK Code Generator.
GetByDisplayName(ctx context.Context, name string) (*Group, error)
// Update group details.
//
// Partially updates the details of a group.
Patch(ctx context.Context, request PartialUpdate) error
// Replace a group.
//
// Updates the details of a group by replacing the entire group entity.
Update(ctx context.Context, request Group) error
}
func NewAccountGroups(client *client.DatabricksClient) *AccountGroupsAPI {
return &AccountGroupsAPI{
impl: &accountGroupsImpl{
client: client,
},
}
}
// Groups simplify identity management, making it easier to assign access to
// Databricks account, data, and other securable objects.
//
// It is best practice to assign access to workspaces and access-control
// policies in Unity Catalog to groups, instead of to users individually. All
// Databricks account identities can be assigned as members of groups, and
// members inherit permissions that are assigned to their group.
type AccountGroupsAPI struct {
// impl contains low-level REST API interface, that could be overridden
// through WithImpl(AccountGroupsService)
impl AccountGroupsService
}
// WithImpl could be used to override low-level API implementations for unit
// testing purposes with [github.com/golang/mock] or other mocking frameworks.
// Deprecated: use MockAccountGroupsInterface instead.
func (a *AccountGroupsAPI) WithImpl(impl AccountGroupsService) AccountGroupsInterface {
a.impl = impl
return a
}
// Impl returns low-level AccountGroups API implementation
// Deprecated: use MockAccountGroupsInterface instead.
func (a *AccountGroupsAPI) Impl() AccountGroupsService {
return a.impl
}
// Create a new group.
//
// Creates a group in the Databricks account with a unique name, using the
// supplied group details.
func (a *AccountGroupsAPI) Create(ctx context.Context, request Group) (*Group, error) {
return a.impl.Create(ctx, request)
}
// Delete a group.
//
// Deletes a group from the Databricks account.
func (a *AccountGroupsAPI) Delete(ctx context.Context, request DeleteAccountGroupRequest) error {
return a.impl.Delete(ctx, request)
}
// Delete a group.
//
// Deletes a group from the Databricks account.
func (a *AccountGroupsAPI) DeleteById(ctx context.Context, id string) error {
return a.impl.Delete(ctx, DeleteAccountGroupRequest{
Id: id,
})
}
// Get group details.
//
// Gets the information for a specific group in the Databricks account.
func (a *AccountGroupsAPI) Get(ctx context.Context, request GetAccountGroupRequest) (*Group, error) {
return a.impl.Get(ctx, request)
}
// Get group details.
//
// Gets the information for a specific group in the Databricks account.
func (a *AccountGroupsAPI) GetById(ctx context.Context, id string) (*Group, error) {
return a.impl.Get(ctx, GetAccountGroupRequest{
Id: id,
})
}
// List group details.
//
// Gets all details of the groups associated with the Databricks account.
//
// This method is generated by Databricks SDK Code Generator.
func (a *AccountGroupsAPI) List(ctx context.Context, request ListAccountGroupsRequest) listing.Iterator[Group] {
request.StartIndex = 1 // SCIM offset starts from 1
if request.Count == 0 {
request.Count = 100
}
getNextPage := func(ctx context.Context, req ListAccountGroupsRequest) (*ListGroupsResponse, error) {
ctx = useragent.InContext(ctx, "sdk-feature", "pagination")
return a.impl.List(ctx, req)
}
getItems := func(resp *ListGroupsResponse) []Group {
return resp.Resources
}
getNextReq := func(resp *ListGroupsResponse) *ListAccountGroupsRequest {
if len(getItems(resp)) == 0 {
return nil
}
request.StartIndex = resp.StartIndex + int64(len(resp.Resources))
return &request
}
iterator := listing.NewIterator(
&request,
getNextPage,
getItems,
getNextReq)
dedupedIterator := listing.NewDedupeIterator[Group, string](
iterator,
func(item Group) string {
return item.Id
})
return dedupedIterator
}
// List group details.
//
// Gets all details of the groups associated with the Databricks account.
//
// This method is generated by Databricks SDK Code Generator.
func (a *AccountGroupsAPI) ListAll(ctx context.Context, request ListAccountGroupsRequest) ([]Group, error) {
iterator := a.List(ctx, request)
return listing.ToSliceN[Group, int64](ctx, iterator, request.Count)
}
// GroupDisplayNameToIdMap calls [AccountGroupsAPI.ListAll] and creates a map of results with [Group].DisplayName as key and [Group].Id as value.
//
// Returns an error if there's more than one [Group] with the same .DisplayName.
//
// Note: All [Group] instances are loaded into memory before creating a map.
//
// This method is generated by Databricks SDK Code Generator.
func (a *AccountGroupsAPI) GroupDisplayNameToIdMap(ctx context.Context, request ListAccountGroupsRequest) (map[string]string, error) {
ctx = useragent.InContext(ctx, "sdk-feature", "name-to-id")
mapping := map[string]string{}
result, err := a.ListAll(ctx, request)
if err != nil {
return nil, err
}
for _, v := range result {
key := v.DisplayName
_, duplicate := mapping[key]
if duplicate {
return nil, fmt.Errorf("duplicate .DisplayName: %s", key)
}
mapping[key] = v.Id
}
return mapping, nil
}
// GetByDisplayName calls [AccountGroupsAPI.GroupDisplayNameToIdMap] and returns a single [Group].
//
// Returns an error if there's more than one [Group] with the same .DisplayName.
//
// Note: All [Group] instances are loaded into memory before returning matching by name.
//
// This method is generated by Databricks SDK Code Generator.
func (a *AccountGroupsAPI) GetByDisplayName(ctx context.Context, name string) (*Group, error) {
ctx = useragent.InContext(ctx, "sdk-feature", "get-by-name")
result, err := a.ListAll(ctx, ListAccountGroupsRequest{})
if err != nil {
return nil, err
}
tmp := map[string][]Group{}
for _, v := range result {
key := v.DisplayName
tmp[key] = append(tmp[key], v)
}
alternatives, ok := tmp[name]
if !ok || len(alternatives) == 0 {
return nil, fmt.Errorf("Group named '%s' does not exist", name)
}
if len(alternatives) > 1 {
return nil, fmt.Errorf("there are %d instances of Group named '%s'", len(alternatives), name)
}
return &alternatives[0], nil
}
// Update group details.
//
// Partially updates the details of a group.
func (a *AccountGroupsAPI) Patch(ctx context.Context, request PartialUpdate) error {
return a.impl.Patch(ctx, request)
}
// Replace a group.
//
// Updates the details of a group by replacing the entire group entity.
func (a *AccountGroupsAPI) Update(ctx context.Context, request Group) error {
return a.impl.Update(ctx, request)
}
type AccountServicePrincipalsInterface interface {
// WithImpl could be used to override low-level API implementations for unit
// testing purposes with [github.com/golang/mock] or other mocking frameworks.
// Deprecated: use MockAccountServicePrincipalsInterface instead.
WithImpl(impl AccountServicePrincipalsService) AccountServicePrincipalsInterface
// Impl returns low-level AccountServicePrincipals API implementation
// Deprecated: use MockAccountServicePrincipalsInterface instead.
Impl() AccountServicePrincipalsService
// Create a service principal.
//
// Creates a new service principal in the Databricks account.
Create(ctx context.Context, request ServicePrincipal) (*ServicePrincipal, error)
// Delete a service principal.
//
// Delete a single service principal in the Databricks account.
Delete(ctx context.Context, request DeleteAccountServicePrincipalRequest) error
// Delete a service principal.
//
// Delete a single service principal in the Databricks account.
DeleteById(ctx context.Context, id string) error
// Get service principal details.
//
// Gets the details for a single service principal define in the Databricks
// account.
Get(ctx context.Context, request GetAccountServicePrincipalRequest) (*ServicePrincipal, error)
// Get service principal details.
//
// Gets the details for a single service principal define in the Databricks
// account.
GetById(ctx context.Context, id string) (*ServicePrincipal, error)
// List service principals.
//
// Gets the set of service principals associated with a Databricks account.
//
// This method is generated by Databricks SDK Code Generator.
List(ctx context.Context, request ListAccountServicePrincipalsRequest) listing.Iterator[ServicePrincipal]
// List service principals.
//
// Gets the set of service principals associated with a Databricks account.
//
// This method is generated by Databricks SDK Code Generator.
ListAll(ctx context.Context, request ListAccountServicePrincipalsRequest) ([]ServicePrincipal, error)
// ServicePrincipalDisplayNameToIdMap calls [AccountServicePrincipalsAPI.ListAll] and creates a map of results with [ServicePrincipal].DisplayName as key and [ServicePrincipal].Id as value.
//
// Returns an error if there's more than one [ServicePrincipal] with the same .DisplayName.
//
// Note: All [ServicePrincipal] instances are loaded into memory before creating a map.
//
// This method is generated by Databricks SDK Code Generator.
ServicePrincipalDisplayNameToIdMap(ctx context.Context, request ListAccountServicePrincipalsRequest) (map[string]string, error)
// GetByDisplayName calls [AccountServicePrincipalsAPI.ServicePrincipalDisplayNameToIdMap] and returns a single [ServicePrincipal].
//
// Returns an error if there's more than one [ServicePrincipal] with the same .DisplayName.
//
// Note: All [ServicePrincipal] instances are loaded into memory before returning matching by name.
//
// This method is generated by Databricks SDK Code Generator.
GetByDisplayName(ctx context.Context, name string) (*ServicePrincipal, error)
// Update service principal details.
//
// Partially updates the details of a single service principal in the Databricks
// account.
Patch(ctx context.Context, request PartialUpdate) error
// Replace service principal.
//
// Updates the details of a single service principal.
//
// This action replaces the existing service principal with the same name.
Update(ctx context.Context, request ServicePrincipal) error
}
func NewAccountServicePrincipals(client *client.DatabricksClient) *AccountServicePrincipalsAPI {
return &AccountServicePrincipalsAPI{
impl: &accountServicePrincipalsImpl{
client: client,
},
}
}
// Identities for use with jobs, automated tools, and systems such as scripts,
// apps, and CI/CD platforms. Databricks recommends creating service principals
// to run production jobs or modify production data. If all processes that act
// on production data run with service principals, interactive users do not need
// any write, delete, or modify privileges in production. This eliminates the
// risk of a user overwriting production data by accident.
type AccountServicePrincipalsAPI struct {
// impl contains low-level REST API interface, that could be overridden
// through WithImpl(AccountServicePrincipalsService)
impl AccountServicePrincipalsService
}
// WithImpl could be used to override low-level API implementations for unit
// testing purposes with [github.com/golang/mock] or other mocking frameworks.
// Deprecated: use MockAccountServicePrincipalsInterface instead.
func (a *AccountServicePrincipalsAPI) WithImpl(impl AccountServicePrincipalsService) AccountServicePrincipalsInterface {
a.impl = impl
return a
}
// Impl returns low-level AccountServicePrincipals API implementation
// Deprecated: use MockAccountServicePrincipalsInterface instead.
func (a *AccountServicePrincipalsAPI) Impl() AccountServicePrincipalsService {
return a.impl
}
// Create a service principal.
//
// Creates a new service principal in the Databricks account.
func (a *AccountServicePrincipalsAPI) Create(ctx context.Context, request ServicePrincipal) (*ServicePrincipal, error) {
return a.impl.Create(ctx, request)
}
// Delete a service principal.
//
// Delete a single service principal in the Databricks account.
func (a *AccountServicePrincipalsAPI) Delete(ctx context.Context, request DeleteAccountServicePrincipalRequest) error {
return a.impl.Delete(ctx, request)
}
// Delete a service principal.
//
// Delete a single service principal in the Databricks account.
func (a *AccountServicePrincipalsAPI) DeleteById(ctx context.Context, id string) error {
return a.impl.Delete(ctx, DeleteAccountServicePrincipalRequest{
Id: id,
})
}
// Get service principal details.
//
// Gets the details for a single service principal define in the Databricks
// account.
func (a *AccountServicePrincipalsAPI) Get(ctx context.Context, request GetAccountServicePrincipalRequest) (*ServicePrincipal, error) {
return a.impl.Get(ctx, request)
}
// Get service principal details.
//
// Gets the details for a single service principal define in the Databricks
// account.
func (a *AccountServicePrincipalsAPI) GetById(ctx context.Context, id string) (*ServicePrincipal, error) {
return a.impl.Get(ctx, GetAccountServicePrincipalRequest{
Id: id,
})
}
// List service principals.
//
// Gets the set of service principals associated with a Databricks account.
//
// This method is generated by Databricks SDK Code Generator.
func (a *AccountServicePrincipalsAPI) List(ctx context.Context, request ListAccountServicePrincipalsRequest) listing.Iterator[ServicePrincipal] {
request.StartIndex = 1 // SCIM offset starts from 1
if request.Count == 0 {
request.Count = 100
}
getNextPage := func(ctx context.Context, req ListAccountServicePrincipalsRequest) (*ListServicePrincipalResponse, error) {
ctx = useragent.InContext(ctx, "sdk-feature", "pagination")
return a.impl.List(ctx, req)
}
getItems := func(resp *ListServicePrincipalResponse) []ServicePrincipal {
return resp.Resources
}
getNextReq := func(resp *ListServicePrincipalResponse) *ListAccountServicePrincipalsRequest {
if len(getItems(resp)) == 0 {
return nil
}
request.StartIndex = resp.StartIndex + int64(len(resp.Resources))
return &request
}
iterator := listing.NewIterator(
&request,
getNextPage,
getItems,
getNextReq)
dedupedIterator := listing.NewDedupeIterator[ServicePrincipal, string](
iterator,
func(item ServicePrincipal) string {
return item.Id
})
return dedupedIterator
}
// List service principals.
//
// Gets the set of service principals associated with a Databricks account.
//
// This method is generated by Databricks SDK Code Generator.
func (a *AccountServicePrincipalsAPI) ListAll(ctx context.Context, request ListAccountServicePrincipalsRequest) ([]ServicePrincipal, error) {
iterator := a.List(ctx, request)
return listing.ToSliceN[ServicePrincipal, int64](ctx, iterator, request.Count)
}
// ServicePrincipalDisplayNameToIdMap calls [AccountServicePrincipalsAPI.ListAll] and creates a map of results with [ServicePrincipal].DisplayName as key and [ServicePrincipal].Id as value.
//
// Returns an error if there's more than one [ServicePrincipal] with the same .DisplayName.
//
// Note: All [ServicePrincipal] instances are loaded into memory before creating a map.
//
// This method is generated by Databricks SDK Code Generator.
func (a *AccountServicePrincipalsAPI) ServicePrincipalDisplayNameToIdMap(ctx context.Context, request ListAccountServicePrincipalsRequest) (map[string]string, error) {
ctx = useragent.InContext(ctx, "sdk-feature", "name-to-id")
mapping := map[string]string{}
result, err := a.ListAll(ctx, request)
if err != nil {
return nil, err
}
for _, v := range result {
key := v.DisplayName
_, duplicate := mapping[key]
if duplicate {
return nil, fmt.Errorf("duplicate .DisplayName: %s", key)
}
mapping[key] = v.Id
}
return mapping, nil
}
// GetByDisplayName calls [AccountServicePrincipalsAPI.ServicePrincipalDisplayNameToIdMap] and returns a single [ServicePrincipal].
//
// Returns an error if there's more than one [ServicePrincipal] with the same .DisplayName.
//
// Note: All [ServicePrincipal] instances are loaded into memory before returning matching by name.
//
// This method is generated by Databricks SDK Code Generator.
func (a *AccountServicePrincipalsAPI) GetByDisplayName(ctx context.Context, name string) (*ServicePrincipal, error) {
ctx = useragent.InContext(ctx, "sdk-feature", "get-by-name")
result, err := a.ListAll(ctx, ListAccountServicePrincipalsRequest{})
if err != nil {
return nil, err
}
tmp := map[string][]ServicePrincipal{}
for _, v := range result {
key := v.DisplayName
tmp[key] = append(tmp[key], v)
}
alternatives, ok := tmp[name]
if !ok || len(alternatives) == 0 {
return nil, fmt.Errorf("ServicePrincipal named '%s' does not exist", name)
}
if len(alternatives) > 1 {
return nil, fmt.Errorf("there are %d instances of ServicePrincipal named '%s'", len(alternatives), name)
}
return &alternatives[0], nil
}
// Update service principal details.
//
// Partially updates the details of a single service principal in the Databricks
// account.
func (a *AccountServicePrincipalsAPI) Patch(ctx context.Context, request PartialUpdate) error {
return a.impl.Patch(ctx, request)
}
// Replace service principal.
//
// Updates the details of a single service principal.
//
// This action replaces the existing service principal with the same name.
func (a *AccountServicePrincipalsAPI) Update(ctx context.Context, request ServicePrincipal) error {
return a.impl.Update(ctx, request)
}
type AccountUsersInterface interface {
// WithImpl could be used to override low-level API implementations for unit
// testing purposes with [github.com/golang/mock] or other mocking frameworks.
// Deprecated: use MockAccountUsersInterface instead.
WithImpl(impl AccountUsersService) AccountUsersInterface
// Impl returns low-level AccountUsers API implementation
// Deprecated: use MockAccountUsersInterface instead.
Impl() AccountUsersService
// Create a new user.
//
// Creates a new user in the Databricks account. This new user will also be
// added to the Databricks account.
Create(ctx context.Context, request User) (*User, error)
// Delete a user.
//
// Deletes a user. Deleting a user from a Databricks account also removes
// objects associated with the user.
Delete(ctx context.Context, request DeleteAccountUserRequest) error
// Delete a user.
//
// Deletes a user. Deleting a user from a Databricks account also removes
// objects associated with the user.
DeleteById(ctx context.Context, id string) error
// Get user details.
//
// Gets information for a specific user in Databricks account.
Get(ctx context.Context, request GetAccountUserRequest) (*User, error)
// Get user details.
//
// Gets information for a specific user in Databricks account.
GetById(ctx context.Context, id string) (*User, error)
// List users.
//
// Gets details for all the users associated with a Databricks account.
//
// This method is generated by Databricks SDK Code Generator.
List(ctx context.Context, request ListAccountUsersRequest) listing.Iterator[User]
// List users.
//
// Gets details for all the users associated with a Databricks account.
//
// This method is generated by Databricks SDK Code Generator.
ListAll(ctx context.Context, request ListAccountUsersRequest) ([]User, error)
// UserUserNameToIdMap calls [AccountUsersAPI.ListAll] and creates a map of results with [User].UserName as key and [User].Id as value.
//
// Returns an error if there's more than one [User] with the same .UserName.
//
// Note: All [User] instances are loaded into memory before creating a map.
//
// This method is generated by Databricks SDK Code Generator.
UserUserNameToIdMap(ctx context.Context, request ListAccountUsersRequest) (map[string]string, error)
// GetByUserName calls [AccountUsersAPI.UserUserNameToIdMap] and returns a single [User].
//
// Returns an error if there's more than one [User] with the same .UserName.
//
// Note: All [User] instances are loaded into memory before returning matching by name.
//
// This method is generated by Databricks SDK Code Generator.
GetByUserName(ctx context.Context, name string) (*User, error)
// Update user details.
//
// Partially updates a user resource by applying the supplied operations on
// specific user attributes.
Patch(ctx context.Context, request PartialUpdate) error
// Replace a user.
//
// Replaces a user's information with the data supplied in request.
Update(ctx context.Context, request User) error
}
func NewAccountUsers(client *client.DatabricksClient) *AccountUsersAPI {
return &AccountUsersAPI{
impl: &accountUsersImpl{
client: client,
},
}
}
// User identities recognized by Databricks and represented by email addresses.
//
// Databricks recommends using SCIM provisioning to sync users and groups
// automatically from your identity provider to your Databricks account. SCIM
// streamlines onboarding a new employee or team by using your identity provider
// to create users and groups in Databricks account and give them the proper
// level of access. When a user leaves your organization or no longer needs
// access to Databricks account, admins can terminate the user in your identity
// provider and that user’s account will also be removed from Databricks
// account. This ensures a consistent offboarding process and prevents
// unauthorized users from accessing sensitive data.
type AccountUsersAPI struct {
// impl contains low-level REST API interface, that could be overridden
// through WithImpl(AccountUsersService)
impl AccountUsersService
}
// WithImpl could be used to override low-level API implementations for unit
// testing purposes with [github.com/golang/mock] or other mocking frameworks.
// Deprecated: use MockAccountUsersInterface instead.
func (a *AccountUsersAPI) WithImpl(impl AccountUsersService) AccountUsersInterface {
a.impl = impl
return a
}
// Impl returns low-level AccountUsers API implementation
// Deprecated: use MockAccountUsersInterface instead.
func (a *AccountUsersAPI) Impl() AccountUsersService {
return a.impl
}
// Create a new user.
//
// Creates a new user in the Databricks account. This new user will also be
// added to the Databricks account.
func (a *AccountUsersAPI) Create(ctx context.Context, request User) (*User, error) {
return a.impl.Create(ctx, request)
}
// Delete a user.
//
// Deletes a user. Deleting a user from a Databricks account also removes
// objects associated with the user.
func (a *AccountUsersAPI) Delete(ctx context.Context, request DeleteAccountUserRequest) error {
return a.impl.Delete(ctx, request)
}
// Delete a user.
//
// Deletes a user. Deleting a user from a Databricks account also removes
// objects associated with the user.
func (a *AccountUsersAPI) DeleteById(ctx context.Context, id string) error {
return a.impl.Delete(ctx, DeleteAccountUserRequest{
Id: id,
})
}
// Get user details.
//
// Gets information for a specific user in Databricks account.
func (a *AccountUsersAPI) Get(ctx context.Context, request GetAccountUserRequest) (*User, error) {
return a.impl.Get(ctx, request)
}
// Get user details.
//
// Gets information for a specific user in Databricks account.
func (a *AccountUsersAPI) GetById(ctx context.Context, id string) (*User, error) {
return a.impl.Get(ctx, GetAccountUserRequest{
Id: id,
})
}
// List users.
//
// Gets details for all the users associated with a Databricks account.
//
// This method is generated by Databricks SDK Code Generator.
func (a *AccountUsersAPI) List(ctx context.Context, request ListAccountUsersRequest) listing.Iterator[User] {
request.StartIndex = 1 // SCIM offset starts from 1
if request.Count == 0 {
request.Count = 100
}
getNextPage := func(ctx context.Context, req ListAccountUsersRequest) (*ListUsersResponse, error) {
ctx = useragent.InContext(ctx, "sdk-feature", "pagination")
return a.impl.List(ctx, req)
}
getItems := func(resp *ListUsersResponse) []User {
return resp.Resources
}
getNextReq := func(resp *ListUsersResponse) *ListAccountUsersRequest {
if len(getItems(resp)) == 0 {
return nil
}
request.StartIndex = resp.StartIndex + int64(len(resp.Resources))
return &request
}
iterator := listing.NewIterator(
&request,
getNextPage,
getItems,
getNextReq)
dedupedIterator := listing.NewDedupeIterator[User, string](
iterator,
func(item User) string {
return item.Id
})
return dedupedIterator
}
// List users.
//
// Gets details for all the users associated with a Databricks account.
//
// This method is generated by Databricks SDK Code Generator.
func (a *AccountUsersAPI) ListAll(ctx context.Context, request ListAccountUsersRequest) ([]User, error) {
iterator := a.List(ctx, request)
return listing.ToSliceN[User, int64](ctx, iterator, request.Count)
}
// UserUserNameToIdMap calls [AccountUsersAPI.ListAll] and creates a map of results with [User].UserName as key and [User].Id as value.
//
// Returns an error if there's more than one [User] with the same .UserName.
//
// Note: All [User] instances are loaded into memory before creating a map.
//
// This method is generated by Databricks SDK Code Generator.
func (a *AccountUsersAPI) UserUserNameToIdMap(ctx context.Context, request ListAccountUsersRequest) (map[string]string, error) {
ctx = useragent.InContext(ctx, "sdk-feature", "name-to-id")
mapping := map[string]string{}
result, err := a.ListAll(ctx, request)
if err != nil {
return nil, err
}
for _, v := range result {
key := v.UserName
_, duplicate := mapping[key]
if duplicate {
return nil, fmt.Errorf("duplicate .UserName: %s", key)
}
mapping[key] = v.Id
}
return mapping, nil
}
// GetByUserName calls [AccountUsersAPI.UserUserNameToIdMap] and returns a single [User].
//
// Returns an error if there's more than one [User] with the same .UserName.
//
// Note: All [User] instances are loaded into memory before returning matching by name.
//
// This method is generated by Databricks SDK Code Generator.
func (a *AccountUsersAPI) GetByUserName(ctx context.Context, name string) (*User, error) {
ctx = useragent.InContext(ctx, "sdk-feature", "get-by-name")
result, err := a.ListAll(ctx, ListAccountUsersRequest{})
if err != nil {
return nil, err
}
tmp := map[string][]User{}
for _, v := range result {
key := v.UserName
tmp[key] = append(tmp[key], v)
}
alternatives, ok := tmp[name]
if !ok || len(alternatives) == 0 {
return nil, fmt.Errorf("User named '%s' does not exist", name)