-
Notifications
You must be signed in to change notification settings - Fork 38
/
api.go
executable file
·1207 lines (1070 loc) · 44.2 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 Clean Rooms, Providers, Recipient Activation, Recipients, Shares, etc.
package sharing
import (
"context"
"fmt"
"github.com/databricks/databricks-sdk-go/client"
"github.com/databricks/databricks-sdk-go/listing"
"github.com/databricks/databricks-sdk-go/service/catalog"
"github.com/databricks/databricks-sdk-go/useragent"
)
type CleanRoomsInterface 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 MockCleanRoomsInterface instead.
WithImpl(impl CleanRoomsService) CleanRoomsInterface
// Impl returns low-level CleanRooms API implementation
// Deprecated: use MockCleanRoomsInterface instead.
Impl() CleanRoomsService
// Create a clean room.
//
// Creates a new clean room with specified colaborators. The caller must be a
// metastore admin or have the **CREATE_CLEAN_ROOM** privilege on the metastore.
Create(ctx context.Context, request CreateCleanRoom) (*CleanRoomInfo, error)
// Delete a clean room.
//
// Deletes a data object clean room from the metastore. The caller must be an
// owner of the clean room.
Delete(ctx context.Context, request DeleteCleanRoomRequest) error
// Delete a clean room.
//
// Deletes a data object clean room from the metastore. The caller must be an
// owner of the clean room.
DeleteByName(ctx context.Context, name string) error
// Get a clean room.
//
// Gets a data object clean room from the metastore. The caller must be a
// metastore admin or the owner of the clean room.
Get(ctx context.Context, request GetCleanRoomRequest) (*CleanRoomInfo, error)
// Get a clean room.
//
// Gets a data object clean room from the metastore. The caller must be a
// metastore admin or the owner of the clean room.
GetByName(ctx context.Context, name string) (*CleanRoomInfo, error)
// List clean rooms.
//
// Gets an array of data object clean rooms from the metastore. The caller must
// be a metastore admin or the owner of the clean room. There is no guarantee of
// a specific ordering of the elements in the array.
//
// This method is generated by Databricks SDK Code Generator.
List(ctx context.Context, request ListCleanRoomsRequest) listing.Iterator[CleanRoomInfo]
// List clean rooms.
//
// Gets an array of data object clean rooms from the metastore. The caller must
// be a metastore admin or the owner of the clean room. There is no guarantee of
// a specific ordering of the elements in the array.
//
// This method is generated by Databricks SDK Code Generator.
ListAll(ctx context.Context, request ListCleanRoomsRequest) ([]CleanRoomInfo, error)
// Update a clean room.
//
// Updates the clean room with the changes and data objects in the request. The
// caller must be the owner of the clean room or a metastore admin.
//
// When the caller is a metastore admin, only the __owner__ field can be
// updated.
//
// In the case that the clean room name is changed **updateCleanRoom** requires
// that the caller is both the clean room owner and a metastore admin.
//
// For each table that is added through this method, the clean room owner must
// also have **SELECT** privilege on the table. The privilege must be maintained
// indefinitely for recipients to be able to access the table. Typically, you
// should use a group as the clean room owner.
//
// Table removals through **update** do not require additional privileges.
Update(ctx context.Context, request UpdateCleanRoom) (*CleanRoomInfo, error)
}
func NewCleanRooms(client *client.DatabricksClient) *CleanRoomsAPI {
return &CleanRoomsAPI{
impl: &cleanRoomsImpl{
client: client,
},
}
}
// A clean room is a secure, privacy-protecting environment where two or more
// parties can share sensitive enterprise data, including customer data, for
// measurements, insights, activation and other use cases.
//
// To create clean rooms, you must be a metastore admin or a user with the
// **CREATE_CLEAN_ROOM** privilege.
type CleanRoomsAPI struct {
// impl contains low-level REST API interface, that could be overridden
// through WithImpl(CleanRoomsService)
impl CleanRoomsService
}
// 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 MockCleanRoomsInterface instead.
func (a *CleanRoomsAPI) WithImpl(impl CleanRoomsService) CleanRoomsInterface {
a.impl = impl
return a
}
// Impl returns low-level CleanRooms API implementation
// Deprecated: use MockCleanRoomsInterface instead.
func (a *CleanRoomsAPI) Impl() CleanRoomsService {
return a.impl
}
// Create a clean room.
//
// Creates a new clean room with specified colaborators. The caller must be a
// metastore admin or have the **CREATE_CLEAN_ROOM** privilege on the metastore.
func (a *CleanRoomsAPI) Create(ctx context.Context, request CreateCleanRoom) (*CleanRoomInfo, error) {
return a.impl.Create(ctx, request)
}
// Delete a clean room.
//
// Deletes a data object clean room from the metastore. The caller must be an
// owner of the clean room.
func (a *CleanRoomsAPI) Delete(ctx context.Context, request DeleteCleanRoomRequest) error {
return a.impl.Delete(ctx, request)
}
// Delete a clean room.
//
// Deletes a data object clean room from the metastore. The caller must be an
// owner of the clean room.
func (a *CleanRoomsAPI) DeleteByName(ctx context.Context, name string) error {
return a.impl.Delete(ctx, DeleteCleanRoomRequest{
Name: name,
})
}
// Get a clean room.
//
// Gets a data object clean room from the metastore. The caller must be a
// metastore admin or the owner of the clean room.
func (a *CleanRoomsAPI) Get(ctx context.Context, request GetCleanRoomRequest) (*CleanRoomInfo, error) {
return a.impl.Get(ctx, request)
}
// Get a clean room.
//
// Gets a data object clean room from the metastore. The caller must be a
// metastore admin or the owner of the clean room.
func (a *CleanRoomsAPI) GetByName(ctx context.Context, name string) (*CleanRoomInfo, error) {
return a.impl.Get(ctx, GetCleanRoomRequest{
Name: name,
})
}
// List clean rooms.
//
// Gets an array of data object clean rooms from the metastore. The caller must
// be a metastore admin or the owner of the clean room. There is no guarantee of
// a specific ordering of the elements in the array.
//
// This method is generated by Databricks SDK Code Generator.
func (a *CleanRoomsAPI) List(ctx context.Context, request ListCleanRoomsRequest) listing.Iterator[CleanRoomInfo] {
getNextPage := func(ctx context.Context, req ListCleanRoomsRequest) (*ListCleanRoomsResponse, error) {
ctx = useragent.InContext(ctx, "sdk-feature", "pagination")
return a.impl.List(ctx, req)
}
getItems := func(resp *ListCleanRoomsResponse) []CleanRoomInfo {
return resp.CleanRooms
}
getNextReq := func(resp *ListCleanRoomsResponse) *ListCleanRoomsRequest {
if resp.NextPageToken == "" {
return nil
}
request.PageToken = resp.NextPageToken
return &request
}
iterator := listing.NewIterator(
&request,
getNextPage,
getItems,
getNextReq)
return iterator
}
// List clean rooms.
//
// Gets an array of data object clean rooms from the metastore. The caller must
// be a metastore admin or the owner of the clean room. There is no guarantee of
// a specific ordering of the elements in the array.
//
// This method is generated by Databricks SDK Code Generator.
func (a *CleanRoomsAPI) ListAll(ctx context.Context, request ListCleanRoomsRequest) ([]CleanRoomInfo, error) {
iterator := a.List(ctx, request)
return listing.ToSliceN[CleanRoomInfo, int](ctx, iterator, request.MaxResults)
}
// Update a clean room.
//
// Updates the clean room with the changes and data objects in the request. The
// caller must be the owner of the clean room or a metastore admin.
//
// When the caller is a metastore admin, only the __owner__ field can be
// updated.
//
// In the case that the clean room name is changed **updateCleanRoom** requires
// that the caller is both the clean room owner and a metastore admin.
//
// For each table that is added through this method, the clean room owner must
// also have **SELECT** privilege on the table. The privilege must be maintained
// indefinitely for recipients to be able to access the table. Typically, you
// should use a group as the clean room owner.
//
// Table removals through **update** do not require additional privileges.
func (a *CleanRoomsAPI) Update(ctx context.Context, request UpdateCleanRoom) (*CleanRoomInfo, error) {
return a.impl.Update(ctx, request)
}
type ProvidersInterface 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 MockProvidersInterface instead.
WithImpl(impl ProvidersService) ProvidersInterface
// Impl returns low-level Providers API implementation
// Deprecated: use MockProvidersInterface instead.
Impl() ProvidersService
// Create an auth provider.
//
// Creates a new authentication provider minimally based on a name and
// authentication type. The caller must be an admin on the metastore.
Create(ctx context.Context, request CreateProvider) (*ProviderInfo, error)
// Delete a provider.
//
// Deletes an authentication provider, if the caller is a metastore admin or is
// the owner of the provider.
Delete(ctx context.Context, request DeleteProviderRequest) error
// Delete a provider.
//
// Deletes an authentication provider, if the caller is a metastore admin or is
// the owner of the provider.
DeleteByName(ctx context.Context, name string) error
// Get a provider.
//
// Gets a specific authentication provider. The caller must supply the name of
// the provider, and must either be a metastore admin or the owner of the
// provider.
Get(ctx context.Context, request GetProviderRequest) (*ProviderInfo, error)
// Get a provider.
//
// Gets a specific authentication provider. The caller must supply the name of
// the provider, and must either be a metastore admin or the owner of the
// provider.
GetByName(ctx context.Context, name string) (*ProviderInfo, error)
// List providers.
//
// Gets an array of available authentication providers. The caller must either
// be a metastore admin or the owner of the providers. Providers not owned by
// the caller are not included in the response. There is no guarantee of a
// specific ordering of the elements in the array.
//
// This method is generated by Databricks SDK Code Generator.
List(ctx context.Context, request ListProvidersRequest) listing.Iterator[ProviderInfo]
// List providers.
//
// Gets an array of available authentication providers. The caller must either
// be a metastore admin or the owner of the providers. Providers not owned by
// the caller are not included in the response. There is no guarantee of a
// specific ordering of the elements in the array.
//
// This method is generated by Databricks SDK Code Generator.
ListAll(ctx context.Context, request ListProvidersRequest) ([]ProviderInfo, error)
// ProviderInfoNameToMetastoreIdMap calls [ProvidersAPI.ListAll] and creates a map of results with [ProviderInfo].Name as key and [ProviderInfo].MetastoreId as value.
//
// Returns an error if there's more than one [ProviderInfo] with the same .Name.
//
// Note: All [ProviderInfo] instances are loaded into memory before creating a map.
//
// This method is generated by Databricks SDK Code Generator.
ProviderInfoNameToMetastoreIdMap(ctx context.Context, request ListProvidersRequest) (map[string]string, error)
// List shares by Provider.
//
// Gets an array of a specified provider's shares within the metastore where:
//
// * the caller is a metastore admin, or * the caller is the owner.
//
// This method is generated by Databricks SDK Code Generator.
ListShares(ctx context.Context, request ListSharesRequest) listing.Iterator[ProviderShare]
// List shares by Provider.
//
// Gets an array of a specified provider's shares within the metastore where:
//
// * the caller is a metastore admin, or * the caller is the owner.
//
// This method is generated by Databricks SDK Code Generator.
ListSharesAll(ctx context.Context, request ListSharesRequest) ([]ProviderShare, error)
// List shares by Provider.
//
// Gets an array of a specified provider's shares within the metastore where:
//
// * the caller is a metastore admin, or * the caller is the owner.
ListSharesByName(ctx context.Context, name string) (*ListProviderSharesResponse, error)
// Update a provider.
//
// Updates the information for an authentication provider, if the caller is a
// metastore admin or is the owner of the provider. If the update changes the
// provider name, the caller must be both a metastore admin and the owner of the
// provider.
Update(ctx context.Context, request UpdateProvider) (*ProviderInfo, error)
}
func NewProviders(client *client.DatabricksClient) *ProvidersAPI {
return &ProvidersAPI{
impl: &providersImpl{
client: client,
},
}
}
// A data provider is an object representing the organization in the real world
// who shares the data. A provider contains shares which further contain the
// shared data.
type ProvidersAPI struct {
// impl contains low-level REST API interface, that could be overridden
// through WithImpl(ProvidersService)
impl ProvidersService
}
// 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 MockProvidersInterface instead.
func (a *ProvidersAPI) WithImpl(impl ProvidersService) ProvidersInterface {
a.impl = impl
return a
}
// Impl returns low-level Providers API implementation
// Deprecated: use MockProvidersInterface instead.
func (a *ProvidersAPI) Impl() ProvidersService {
return a.impl
}
// Create an auth provider.
//
// Creates a new authentication provider minimally based on a name and
// authentication type. The caller must be an admin on the metastore.
func (a *ProvidersAPI) Create(ctx context.Context, request CreateProvider) (*ProviderInfo, error) {
return a.impl.Create(ctx, request)
}
// Delete a provider.
//
// Deletes an authentication provider, if the caller is a metastore admin or is
// the owner of the provider.
func (a *ProvidersAPI) Delete(ctx context.Context, request DeleteProviderRequest) error {
return a.impl.Delete(ctx, request)
}
// Delete a provider.
//
// Deletes an authentication provider, if the caller is a metastore admin or is
// the owner of the provider.
func (a *ProvidersAPI) DeleteByName(ctx context.Context, name string) error {
return a.impl.Delete(ctx, DeleteProviderRequest{
Name: name,
})
}
// Get a provider.
//
// Gets a specific authentication provider. The caller must supply the name of
// the provider, and must either be a metastore admin or the owner of the
// provider.
func (a *ProvidersAPI) Get(ctx context.Context, request GetProviderRequest) (*ProviderInfo, error) {
return a.impl.Get(ctx, request)
}
// Get a provider.
//
// Gets a specific authentication provider. The caller must supply the name of
// the provider, and must either be a metastore admin or the owner of the
// provider.
func (a *ProvidersAPI) GetByName(ctx context.Context, name string) (*ProviderInfo, error) {
return a.impl.Get(ctx, GetProviderRequest{
Name: name,
})
}
// List providers.
//
// Gets an array of available authentication providers. The caller must either
// be a metastore admin or the owner of the providers. Providers not owned by
// the caller are not included in the response. There is no guarantee of a
// specific ordering of the elements in the array.
//
// This method is generated by Databricks SDK Code Generator.
func (a *ProvidersAPI) List(ctx context.Context, request ListProvidersRequest) listing.Iterator[ProviderInfo] {
getNextPage := func(ctx context.Context, req ListProvidersRequest) (*ListProvidersResponse, error) {
ctx = useragent.InContext(ctx, "sdk-feature", "pagination")
return a.impl.List(ctx, req)
}
getItems := func(resp *ListProvidersResponse) []ProviderInfo {
return resp.Providers
}
iterator := listing.NewIterator(
&request,
getNextPage,
getItems,
nil)
return iterator
}
// List providers.
//
// Gets an array of available authentication providers. The caller must either
// be a metastore admin or the owner of the providers. Providers not owned by
// the caller are not included in the response. There is no guarantee of a
// specific ordering of the elements in the array.
//
// This method is generated by Databricks SDK Code Generator.
func (a *ProvidersAPI) ListAll(ctx context.Context, request ListProvidersRequest) ([]ProviderInfo, error) {
iterator := a.List(ctx, request)
return listing.ToSlice[ProviderInfo](ctx, iterator)
}
// ProviderInfoNameToMetastoreIdMap calls [ProvidersAPI.ListAll] and creates a map of results with [ProviderInfo].Name as key and [ProviderInfo].MetastoreId as value.
//
// Returns an error if there's more than one [ProviderInfo] with the same .Name.
//
// Note: All [ProviderInfo] instances are loaded into memory before creating a map.
//
// This method is generated by Databricks SDK Code Generator.
func (a *ProvidersAPI) ProviderInfoNameToMetastoreIdMap(ctx context.Context, request ListProvidersRequest) (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.Name
_, duplicate := mapping[key]
if duplicate {
return nil, fmt.Errorf("duplicate .Name: %s", key)
}
mapping[key] = v.MetastoreId
}
return mapping, nil
}
// List shares by Provider.
//
// Gets an array of a specified provider's shares within the metastore where:
//
// * the caller is a metastore admin, or * the caller is the owner.
//
// This method is generated by Databricks SDK Code Generator.
func (a *ProvidersAPI) ListShares(ctx context.Context, request ListSharesRequest) listing.Iterator[ProviderShare] {
getNextPage := func(ctx context.Context, req ListSharesRequest) (*ListProviderSharesResponse, error) {
ctx = useragent.InContext(ctx, "sdk-feature", "pagination")
return a.impl.ListShares(ctx, req)
}
getItems := func(resp *ListProviderSharesResponse) []ProviderShare {
return resp.Shares
}
iterator := listing.NewIterator(
&request,
getNextPage,
getItems,
nil)
return iterator
}
// List shares by Provider.
//
// Gets an array of a specified provider's shares within the metastore where:
//
// * the caller is a metastore admin, or * the caller is the owner.
//
// This method is generated by Databricks SDK Code Generator.
func (a *ProvidersAPI) ListSharesAll(ctx context.Context, request ListSharesRequest) ([]ProviderShare, error) {
iterator := a.ListShares(ctx, request)
return listing.ToSlice[ProviderShare](ctx, iterator)
}
// List shares by Provider.
//
// Gets an array of a specified provider's shares within the metastore where:
//
// * the caller is a metastore admin, or * the caller is the owner.
func (a *ProvidersAPI) ListSharesByName(ctx context.Context, name string) (*ListProviderSharesResponse, error) {
return a.impl.ListShares(ctx, ListSharesRequest{
Name: name,
})
}
// Update a provider.
//
// Updates the information for an authentication provider, if the caller is a
// metastore admin or is the owner of the provider. If the update changes the
// provider name, the caller must be both a metastore admin and the owner of the
// provider.
func (a *ProvidersAPI) Update(ctx context.Context, request UpdateProvider) (*ProviderInfo, error) {
return a.impl.Update(ctx, request)
}
type RecipientActivationInterface 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 MockRecipientActivationInterface instead.
WithImpl(impl RecipientActivationService) RecipientActivationInterface
// Impl returns low-level RecipientActivation API implementation
// Deprecated: use MockRecipientActivationInterface instead.
Impl() RecipientActivationService
// Get a share activation URL.
//
// Gets an activation URL for a share.
GetActivationUrlInfo(ctx context.Context, request GetActivationUrlInfoRequest) error
// Get a share activation URL.
//
// Gets an activation URL for a share.
GetActivationUrlInfoByActivationUrl(ctx context.Context, activationUrl string) error
// Get an access token.
//
// Retrieve access token with an activation url. This is a public API without
// any authentication.
RetrieveToken(ctx context.Context, request RetrieveTokenRequest) (*RetrieveTokenResponse, error)
// Get an access token.
//
// Retrieve access token with an activation url. This is a public API without
// any authentication.
RetrieveTokenByActivationUrl(ctx context.Context, activationUrl string) (*RetrieveTokenResponse, error)
}
func NewRecipientActivation(client *client.DatabricksClient) *RecipientActivationAPI {
return &RecipientActivationAPI{
impl: &recipientActivationImpl{
client: client,
},
}
}
// The Recipient Activation API is only applicable in the open sharing model
// where the recipient object has the authentication type of `TOKEN`. The data
// recipient follows the activation link shared by the data provider to download
// the credential file that includes the access token. The recipient will then
// use the credential file to establish a secure connection with the provider to
// receive the shared data.
//
// Note that you can download the credential file only once. Recipients should
// treat the downloaded credential as a secret and must not share it outside of
// their organization.
type RecipientActivationAPI struct {
// impl contains low-level REST API interface, that could be overridden
// through WithImpl(RecipientActivationService)
impl RecipientActivationService
}
// 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 MockRecipientActivationInterface instead.
func (a *RecipientActivationAPI) WithImpl(impl RecipientActivationService) RecipientActivationInterface {
a.impl = impl
return a
}
// Impl returns low-level RecipientActivation API implementation
// Deprecated: use MockRecipientActivationInterface instead.
func (a *RecipientActivationAPI) Impl() RecipientActivationService {
return a.impl
}
// Get a share activation URL.
//
// Gets an activation URL for a share.
func (a *RecipientActivationAPI) GetActivationUrlInfo(ctx context.Context, request GetActivationUrlInfoRequest) error {
return a.impl.GetActivationUrlInfo(ctx, request)
}
// Get a share activation URL.
//
// Gets an activation URL for a share.
func (a *RecipientActivationAPI) GetActivationUrlInfoByActivationUrl(ctx context.Context, activationUrl string) error {
return a.impl.GetActivationUrlInfo(ctx, GetActivationUrlInfoRequest{
ActivationUrl: activationUrl,
})
}
// Get an access token.
//
// Retrieve access token with an activation url. This is a public API without
// any authentication.
func (a *RecipientActivationAPI) RetrieveToken(ctx context.Context, request RetrieveTokenRequest) (*RetrieveTokenResponse, error) {
return a.impl.RetrieveToken(ctx, request)
}
// Get an access token.
//
// Retrieve access token with an activation url. This is a public API without
// any authentication.
func (a *RecipientActivationAPI) RetrieveTokenByActivationUrl(ctx context.Context, activationUrl string) (*RetrieveTokenResponse, error) {
return a.impl.RetrieveToken(ctx, RetrieveTokenRequest{
ActivationUrl: activationUrl,
})
}
type RecipientsInterface 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 MockRecipientsInterface instead.
WithImpl(impl RecipientsService) RecipientsInterface
// Impl returns low-level Recipients API implementation
// Deprecated: use MockRecipientsInterface instead.
Impl() RecipientsService
// Create a share recipient.
//
// Creates a new recipient with the delta sharing authentication type in the
// metastore. The caller must be a metastore admin or has the
// **CREATE_RECIPIENT** privilege on the metastore.
Create(ctx context.Context, request CreateRecipient) (*RecipientInfo, error)
// Delete a share recipient.
//
// Deletes the specified recipient from the metastore. The caller must be the
// owner of the recipient.
Delete(ctx context.Context, request DeleteRecipientRequest) error
// Delete a share recipient.
//
// Deletes the specified recipient from the metastore. The caller must be the
// owner of the recipient.
DeleteByName(ctx context.Context, name string) error
// Get a share recipient.
//
// Gets a share recipient from the metastore if:
//
// * the caller is the owner of the share recipient, or: * is a metastore admin
Get(ctx context.Context, request GetRecipientRequest) (*RecipientInfo, error)
// Get a share recipient.
//
// Gets a share recipient from the metastore if:
//
// * the caller is the owner of the share recipient, or: * is a metastore admin
GetByName(ctx context.Context, name string) (*RecipientInfo, error)
// List share recipients.
//
// Gets an array of all share recipients within the current metastore where:
//
// * the caller is a metastore admin, or * the caller is the owner. There is no
// guarantee of a specific ordering of the elements in the array.
//
// This method is generated by Databricks SDK Code Generator.
List(ctx context.Context, request ListRecipientsRequest) listing.Iterator[RecipientInfo]
// List share recipients.
//
// Gets an array of all share recipients within the current metastore where:
//
// * the caller is a metastore admin, or * the caller is the owner. There is no
// guarantee of a specific ordering of the elements in the array.
//
// This method is generated by Databricks SDK Code Generator.
ListAll(ctx context.Context, request ListRecipientsRequest) ([]RecipientInfo, error)
// RecipientInfoNameToMetastoreIdMap calls [RecipientsAPI.ListAll] and creates a map of results with [RecipientInfo].Name as key and [RecipientInfo].MetastoreId as value.
//
// Returns an error if there's more than one [RecipientInfo] with the same .Name.
//
// Note: All [RecipientInfo] instances are loaded into memory before creating a map.
//
// This method is generated by Databricks SDK Code Generator.
RecipientInfoNameToMetastoreIdMap(ctx context.Context, request ListRecipientsRequest) (map[string]string, error)
// Rotate a token.
//
// Refreshes the specified recipient's delta sharing authentication token with
// the provided token info. The caller must be the owner of the recipient.
RotateToken(ctx context.Context, request RotateRecipientToken) (*RecipientInfo, error)
// Get recipient share permissions.
//
// Gets the share permissions for the specified Recipient. The caller must be a
// metastore admin or the owner of the Recipient.
SharePermissions(ctx context.Context, request SharePermissionsRequest) (*GetRecipientSharePermissionsResponse, error)
// Get recipient share permissions.
//
// Gets the share permissions for the specified Recipient. The caller must be a
// metastore admin or the owner of the Recipient.
SharePermissionsByName(ctx context.Context, name string) (*GetRecipientSharePermissionsResponse, error)
// Update a share recipient.
//
// Updates an existing recipient in the metastore. The caller must be a
// metastore admin or the owner of the recipient. If the recipient name will be
// updated, the user must be both a metastore admin and the owner of the
// recipient.
Update(ctx context.Context, request UpdateRecipient) error
}
func NewRecipients(client *client.DatabricksClient) *RecipientsAPI {
return &RecipientsAPI{
impl: &recipientsImpl{
client: client,
},
}
}
// A recipient is an object you create using :method:recipients/create to
// represent an organization which you want to allow access shares. The way how
// sharing works differs depending on whether or not your recipient has access
// to a Databricks workspace that is enabled for Unity Catalog:
//
// - For recipients with access to a Databricks workspace that is enabled for
// Unity Catalog, you can create a recipient object along with a unique sharing
// identifier you get from the recipient. The sharing identifier is the key
// identifier that enables the secure connection. This sharing mode is called
// **Databricks-to-Databricks sharing**.
//
// - For recipients without access to a Databricks workspace that is enabled for
// Unity Catalog, when you create a recipient object, Databricks generates an
// activation link you can send to the recipient. The recipient follows the
// activation link to download the credential file, and then uses the credential
// file to establish a secure connection to receive the shared data. This
// sharing mode is called **open sharing**.
type RecipientsAPI struct {
// impl contains low-level REST API interface, that could be overridden
// through WithImpl(RecipientsService)
impl RecipientsService
}
// 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 MockRecipientsInterface instead.
func (a *RecipientsAPI) WithImpl(impl RecipientsService) RecipientsInterface {
a.impl = impl
return a
}
// Impl returns low-level Recipients API implementation
// Deprecated: use MockRecipientsInterface instead.
func (a *RecipientsAPI) Impl() RecipientsService {
return a.impl
}
// Create a share recipient.
//
// Creates a new recipient with the delta sharing authentication type in the
// metastore. The caller must be a metastore admin or has the
// **CREATE_RECIPIENT** privilege on the metastore.
func (a *RecipientsAPI) Create(ctx context.Context, request CreateRecipient) (*RecipientInfo, error) {
return a.impl.Create(ctx, request)
}
// Delete a share recipient.
//
// Deletes the specified recipient from the metastore. The caller must be the
// owner of the recipient.
func (a *RecipientsAPI) Delete(ctx context.Context, request DeleteRecipientRequest) error {
return a.impl.Delete(ctx, request)
}
// Delete a share recipient.
//
// Deletes the specified recipient from the metastore. The caller must be the
// owner of the recipient.
func (a *RecipientsAPI) DeleteByName(ctx context.Context, name string) error {
return a.impl.Delete(ctx, DeleteRecipientRequest{
Name: name,
})
}
// Get a share recipient.
//
// Gets a share recipient from the metastore if:
//
// * the caller is the owner of the share recipient, or: * is a metastore admin
func (a *RecipientsAPI) Get(ctx context.Context, request GetRecipientRequest) (*RecipientInfo, error) {
return a.impl.Get(ctx, request)
}
// Get a share recipient.
//
// Gets a share recipient from the metastore if:
//
// * the caller is the owner of the share recipient, or: * is a metastore admin
func (a *RecipientsAPI) GetByName(ctx context.Context, name string) (*RecipientInfo, error) {
return a.impl.Get(ctx, GetRecipientRequest{
Name: name,
})
}
// List share recipients.
//
// Gets an array of all share recipients within the current metastore where:
//
// * the caller is a metastore admin, or * the caller is the owner. There is no
// guarantee of a specific ordering of the elements in the array.
//
// This method is generated by Databricks SDK Code Generator.
func (a *RecipientsAPI) List(ctx context.Context, request ListRecipientsRequest) listing.Iterator[RecipientInfo] {
getNextPage := func(ctx context.Context, req ListRecipientsRequest) (*ListRecipientsResponse, error) {
ctx = useragent.InContext(ctx, "sdk-feature", "pagination")
return a.impl.List(ctx, req)
}
getItems := func(resp *ListRecipientsResponse) []RecipientInfo {
return resp.Recipients
}
iterator := listing.NewIterator(
&request,
getNextPage,
getItems,
nil)
return iterator
}
// List share recipients.
//
// Gets an array of all share recipients within the current metastore where:
//
// * the caller is a metastore admin, or * the caller is the owner. There is no
// guarantee of a specific ordering of the elements in the array.
//
// This method is generated by Databricks SDK Code Generator.
func (a *RecipientsAPI) ListAll(ctx context.Context, request ListRecipientsRequest) ([]RecipientInfo, error) {
iterator := a.List(ctx, request)
return listing.ToSlice[RecipientInfo](ctx, iterator)
}
// RecipientInfoNameToMetastoreIdMap calls [RecipientsAPI.ListAll] and creates a map of results with [RecipientInfo].Name as key and [RecipientInfo].MetastoreId as value.
//
// Returns an error if there's more than one [RecipientInfo] with the same .Name.
//
// Note: All [RecipientInfo] instances are loaded into memory before creating a map.
//
// This method is generated by Databricks SDK Code Generator.
func (a *RecipientsAPI) RecipientInfoNameToMetastoreIdMap(ctx context.Context, request ListRecipientsRequest) (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.Name
_, duplicate := mapping[key]
if duplicate {
return nil, fmt.Errorf("duplicate .Name: %s", key)
}
mapping[key] = v.MetastoreId
}
return mapping, nil
}
// Rotate a token.
//
// Refreshes the specified recipient's delta sharing authentication token with
// the provided token info. The caller must be the owner of the recipient.
func (a *RecipientsAPI) RotateToken(ctx context.Context, request RotateRecipientToken) (*RecipientInfo, error) {
return a.impl.RotateToken(ctx, request)
}
// Get recipient share permissions.
//
// Gets the share permissions for the specified Recipient. The caller must be a
// metastore admin or the owner of the Recipient.
func (a *RecipientsAPI) SharePermissions(ctx context.Context, request SharePermissionsRequest) (*GetRecipientSharePermissionsResponse, error) {
return a.impl.SharePermissions(ctx, request)
}
// Get recipient share permissions.
//
// Gets the share permissions for the specified Recipient. The caller must be a
// metastore admin or the owner of the Recipient.
func (a *RecipientsAPI) SharePermissionsByName(ctx context.Context, name string) (*GetRecipientSharePermissionsResponse, error) {
return a.impl.SharePermissions(ctx, SharePermissionsRequest{
Name: name,
})
}
// Update a share recipient.
//
// Updates an existing recipient in the metastore. The caller must be a
// metastore admin or the owner of the recipient. If the recipient name will be
// updated, the user must be both a metastore admin and the owner of the
// recipient.
func (a *RecipientsAPI) Update(ctx context.Context, request UpdateRecipient) error {
return a.impl.Update(ctx, request)
}
type SharesInterface 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 MockSharesInterface instead.
WithImpl(impl SharesService) SharesInterface
// Impl returns low-level Shares API implementation
// Deprecated: use MockSharesInterface instead.
Impl() SharesService
// Create a share.
//
// Creates a new share for data objects. Data objects can be added after
// creation with **update**. The caller must be a metastore admin or have the
// **CREATE_SHARE** privilege on the metastore.
Create(ctx context.Context, request CreateShare) (*ShareInfo, error)
// Delete a share.
//
// Deletes a data object share from the metastore. The caller must be an owner
// of the share.
Delete(ctx context.Context, request DeleteShareRequest) error
// Delete a share.
//
// Deletes a data object share from the metastore. The caller must be an owner
// of the share.
DeleteByName(ctx context.Context, name string) error
// Get a share.
//
// Gets a data object share from the metastore. The caller must be a metastore
// admin or the owner of the share.
Get(ctx context.Context, request GetShareRequest) (*ShareInfo, error)
// Get a share.
//
// Gets a data object share from the metastore. The caller must be a metastore
// admin or the owner of the share.
GetByName(ctx context.Context, name string) (*ShareInfo, error)
// List shares.
//
// Gets an array of data object shares from the metastore. The caller must be a
// metastore admin or the owner of the share. There is no guarantee of a
// specific ordering of the elements in the array.
//
// This method is generated by Databricks SDK Code Generator.
List(ctx context.Context) listing.Iterator[ShareInfo]
// List shares.
//
// Gets an array of data object shares from the metastore. The caller must be a
// metastore admin or the owner of the share. There is no guarantee of a
// specific ordering of the elements in the array.
//
// This method is generated by Databricks SDK Code Generator.
ListAll(ctx context.Context) ([]ShareInfo, error)
// Get permissions.
//
// Gets the permissions for a data share from the metastore. The caller must be
// a metastore admin or the owner of the share.
SharePermissions(ctx context.Context, request SharePermissionsRequest) (*catalog.PermissionsList, error)