Skip to content

Commit e11e738

Browse files
Bump Go SDK to v0.26.1 (#2968)
* Bump Go SDK to v0.26.0p * Include SCIM retries * work * work * Fix one test * more work * work * Fix testing fixture * Fixes --------- Co-authored-by: Hector Castejon Diaz <[email protected]>
1 parent 18b0585 commit e11e738

File tree

11 files changed

+231
-170
lines changed

11 files changed

+231
-170
lines changed

exporter/exporter_test.go

Lines changed: 65 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,23 @@ var emptyGlobalSQLConfig = qa.HTTPFixture{
359359
}
360360

361361
func TestImportingUsersGroupsSecretScopes(t *testing.T) {
362+
listSpFixtures := qa.ListServicePrincipalsFixtures([]iam.ServicePrincipal{
363+
{
364+
Id: "345",
365+
ApplicationId: "spn",
366+
},
367+
})
368+
listUserFixtures := qa.ListUsersFixtures([]iam.User{
369+
{
370+
Id: "123",
371+
UserName: "[email protected]",
372+
},
373+
})
374+
listGroupFixtures := qa.ListGroupsFixtures([]iam.Group{
375+
{Id: "a"},
376+
{Id: "b"},
377+
{Id: "c"},
378+
})
362379
qa.HTTPFixturesApply(t,
363380
[]qa.HTTPFixture{
364381
meAdminFixture,
@@ -379,18 +396,8 @@ func TestImportingUsersGroupsSecretScopes(t *testing.T) {
379396
allKnownWorkspaceConfs,
380397
dummyWorkspaceConf,
381398
emptyGlobalSQLConfig,
382-
{
383-
Method: "GET",
384-
Resource: "/api/2.0/preview/scim/v2/ServicePrincipals?attributes=id%2CuserName",
385-
Response: iam.ListServicePrincipalResponse{
386-
Resources: []iam.ServicePrincipal{
387-
{
388-
Id: "345",
389-
ApplicationId: "spn",
390-
},
391-
},
392-
},
393-
},
399+
listSpFixtures[0],
400+
listSpFixtures[1],
394401
{
395402
Method: "GET",
396403
Resource: "/api/2.0/preview/scim/v2/ServicePrincipals/345?attributes=userName,displayName,active,externalId,entitlements",
@@ -409,29 +416,10 @@ func TestImportingUsersGroupsSecretScopes(t *testing.T) {
409416
},
410417
ReuseRequest: true,
411418
},
412-
{
413-
Method: "GET",
414-
Resource: "/api/2.0/preview/scim/v2/Users?attributes=userName%2Cid",
415-
416-
Response: iam.ListUsersResponse{
417-
Resources: []iam.User{
418-
{
419-
Id: "123",
420-
UserName: "[email protected]",
421-
},
422-
},
423-
},
424-
},
425-
{
426-
Method: "GET",
427-
Resource: "/api/2.0/preview/scim/v2/Groups?attributes=id",
428-
Response: scim.GroupList{
429-
Resources: []scim.Group{
430-
{ID: "a"},
431-
{ID: "b"},
432-
{ID: "c"},
433-
}},
434-
},
419+
listUserFixtures[0],
420+
listUserFixtures[1],
421+
listGroupFixtures[0],
422+
listGroupFixtures[1],
435423
{
436424
Method: "GET",
437425
Resource: "/api/2.0/preview/scim/v2/Groups/a",
@@ -488,6 +476,34 @@ func TestImportingUsersGroupsSecretScopes(t *testing.T) {
488476
},
489477
ReuseRequest: true,
490478
},
479+
// Get requests appear to be made with two different sets of parameters. The first set is defined in `util.go`, the second
480+
// in the groups resource definition itself.
481+
{
482+
Method: "GET",
483+
Resource: "/api/2.0/preview/scim/v2/Groups/a?attributes=id,displayName,active,externalId,entitlements,groups,roles,members",
484+
Response: scim.Group{ID: "a", DisplayName: "admins",
485+
Members: []scim.ComplexValue{
486+
{Display: "[email protected]", Value: "123", Ref: "Users/123"},
487+
{Display: "Test group", Value: "f", Ref: "Groups/f"},
488+
{Display: "spn", Value: "spn", Ref: "ServicePrincipals/spn"},
489+
},
490+
},
491+
ReuseRequest: true,
492+
},
493+
{
494+
Method: "GET",
495+
Resource: "/api/2.0/preview/scim/v2/Groups/b?attributes=id,displayName,active,externalId,entitlements,groups,roles,members",
496+
Response: scim.Group{ID: "b", DisplayName: "users"},
497+
},
498+
{
499+
Method: "GET",
500+
Resource: "/api/2.0/preview/scim/v2/Groups/c?attributes=id,displayName,active,externalId,entitlements,groups,roles,members",
501+
Response: scim.Group{ID: "c", DisplayName: "test",
502+
Groups: []scim.ComplexValue{
503+
{Display: "admins", Value: "a", Ref: "Groups/a", Type: "direct"},
504+
},
505+
},
506+
},
491507
{
492508
Method: "GET",
493509
Resource: "/api/2.0/preview/scim/v2/Groups/a?attributes=displayName,externalId,entitlements",
@@ -624,11 +640,7 @@ func TestImportingNoResourcesError(t *testing.T) {
624640
emptyInstancePools,
625641
emptyClusterPolicies,
626642
dummyWorkspaceConf,
627-
{
628-
Method: "GET",
629-
Resource: "/api/2.0/preview/scim/v2/Groups?attributes=id",
630-
Response: scim.GroupList{Resources: []scim.Group{}},
631-
},
643+
qa.ListGroupsFixtures([]iam.Group{})[0],
632644
emptyGitCredentials,
633645
emptyIpAccessLIst,
634646
emptyWorkspace,
@@ -1466,25 +1478,16 @@ func TestImportingGlobalInitScripts(t *testing.T) {
14661478
}
14671479

14681480
func TestImportingUser(t *testing.T) {
1481+
userFixture := qa.ListUsersFixtures([]iam.User{
1482+
{
1483+
Id: "123",
1484+
UserName: "me",
1485+
},
1486+
})
14691487
qa.HTTPFixturesApply(t,
14701488
[]qa.HTTPFixture{
1471-
{
1472-
Method: "GET",
1473-
Resource: "/api/2.0/preview/scim/v2/Users?attributes=userName%2Cid",
1474-
Response: iam.ListUsersResponse{
1475-
Resources: []iam.User{
1476-
{
1477-
Id: "123",
1478-
UserName: "me",
1479-
},
1480-
},
1481-
},
1482-
},
1483-
{
1484-
Method: "GET",
1485-
Resource: "/api/2.0/preview/scim/v2/Users?attributes=userName%2Cid&startIndex=1",
1486-
Response: iam.ListUsersResponse{},
1487-
},
1489+
userFixture[0],
1490+
userFixture[1],
14881491
{
14891492
Method: "GET",
14901493
ReuseRequest: true,
@@ -1779,6 +1782,9 @@ func TestImportingSqlObjects(t *testing.T) {
17791782
}
17801783

17811784
func TestImportingDLTPipelines(t *testing.T) {
1785+
userFixture := qa.ListUsersFixtures([]iam.User{
1786+
{Id: "123", UserName: "[email protected]"},
1787+
})
17821788
qa.HTTPFixturesApply(t,
17831789
[]qa.HTTPFixture{
17841790
meAdminFixture,
@@ -1830,20 +1836,8 @@ func TestImportingDLTPipelines(t *testing.T) {
18301836
},
18311837
ReuseRequest: true,
18321838
},
1833-
{
1834-
Method: "GET",
1835-
Resource: "/api/2.0/preview/scim/v2/Users?attributes=userName%2Cid",
1836-
Response: iam.ListUsersResponse{
1837-
Resources: []iam.User{
1838-
{Id: "123", UserName: "[email protected]"},
1839-
},
1840-
},
1841-
},
1842-
{
1843-
Method: "GET",
1844-
Resource: "/api/2.0/preview/scim/v2/Users?attributes=userName%2Cid&startIndex=1",
1845-
Response: iam.ListUsersResponse{},
1846-
},
1839+
userFixture[0],
1840+
userFixture[1],
18471841
{
18481842
Method: "GET",
18491843
Resource: "/api/2.0/preview/scim/v2/Users/123?attributes=userName,displayName,active,externalId,entitlements",

exporter/importables_test.go

Lines changed: 17 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ func TestGroupCacheError(t *testing.T) {
423423
{
424424
ReuseRequest: true,
425425
Method: "GET",
426-
Resource: "/api/2.0/preview/scim/v2/Groups?attributes=id",
426+
Resource: "/api/2.0/preview/scim/v2/Groups?attributes=id&count=100&startIndex=1",
427427
Status: 404,
428428
Response: apierr.NotFound("nope"),
429429
},
@@ -476,13 +476,9 @@ func TestGroupSearchNoMatch(t *testing.T) {
476476
}
477477

478478
func TestUserSearchFails(t *testing.T) {
479+
userFixture := qa.ListUsersFixtures([]iam.User{})
479480
qa.HTTPFixturesApply(t, []qa.HTTPFixture{
480-
{
481-
Method: "GET",
482-
Resource: "/api/2.0/preview/scim/v2/Users?attributes=userName%2Cid",
483-
484-
Response: map[string]any{},
485-
},
481+
userFixture[0],
486482
}, func(ctx context.Context, client *common.DatabricksClient) {
487483
ic := importContextForTestWithClient(ctx, client)
488484
d := scim.ResourceUser().TestResourceData()
@@ -502,12 +498,7 @@ func TestUserSearchFails(t *testing.T) {
502498

503499
func TestSpnSearchFails(t *testing.T) {
504500
qa.HTTPFixturesApply(t, []qa.HTTPFixture{
505-
{
506-
Method: "GET",
507-
Resource: "/api/2.0/preview/scim/v2/ServicePrincipals?attributes=id%2CuserName",
508-
509-
Response: map[string]any{},
510-
},
501+
qa.ListServicePrincipalsFixtures([]iam.ServicePrincipal{})[0],
511502
}, func(ctx context.Context, client *common.DatabricksClient) {
512503
ic := importContextForTestWithClient(ctx, client)
513504
d := scim.ResourceServicePrincipal().TestResourceData()
@@ -526,25 +517,15 @@ func TestSpnSearchFails(t *testing.T) {
526517
}
527518

528519
func TestSpnSearchSuccess(t *testing.T) {
529-
qa.HTTPFixturesApply(t, []qa.HTTPFixture{
520+
spFixture := qa.ListServicePrincipalsFixtures([]iam.ServicePrincipal{
530521
{
531-
Method: "GET",
532-
Resource: "/api/2.0/preview/scim/v2/ServicePrincipals?attributes=id%2CuserName",
533-
Response: iam.ListServicePrincipalResponse{
534-
Resources: []iam.ServicePrincipal{
535-
{
536-
Id: "321", DisplayName: "spn", ApplicationId: "dbc",
537-
},
538-
},
539-
},
522+
Id: "321", DisplayName: "spn", ApplicationId: "dbc",
540523
},
524+
})
525+
qa.HTTPFixturesApply(t, []qa.HTTPFixture{
526+
spFixture[0],
527+
spFixture[1],
541528
{
542-
Method: "GET",
543-
Resource: "/api/2.0/preview/scim/v2/ServicePrincipals?attributes=id%2CuserName&startIndex=1",
544-
Response: iam.ListServicePrincipalResponse{
545-
Resources: []iam.ServicePrincipal{},
546-
},
547-
}, {
548529
ReuseRequest: true,
549530
Method: "GET",
550531
Resource: "/api/2.0/preview/scim/v2/ServicePrincipals/321?attributes=userName,displayName,active,externalId,entitlements,groups,roles",
@@ -619,24 +600,15 @@ func TestShouldOmitFoRepos(t *testing.T) {
619600
}
620601

621602
func TestUserImportSkipNonDirectGroups(t *testing.T) {
622-
qa.HTTPFixturesApply(t, []qa.HTTPFixture{
623-
{
624-
Method: "GET",
625-
Resource: "/api/2.0/preview/scim/v2/Users?attributes=userName%2Cid",
626-
Response: iam.ListUsersResponse{
627-
Resources: []iam.User{
628-
{
629-
UserName: "dbc",
630-
Id: "321",
631-
},
632-
},
633-
},
634-
},
603+
userFixture := qa.ListUsersFixtures([]iam.User{
635604
{
636-
Method: "GET",
637-
Resource: "/api/2.0/preview/scim/v2/Users?attributes=userName%2Cid&startIndex=1",
638-
Response: iam.ListUsersResponse{},
605+
UserName: "dbc",
606+
Id: "321",
639607
},
608+
})
609+
qa.HTTPFixturesApply(t, []qa.HTTPFixture{
610+
userFixture[0],
611+
userFixture[1],
640612
{
641613
ReuseRequest: true,
642614
Method: "GET",

exporter/util.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,11 @@ func (ic *importContext) getUsersMapping() {
330330
var err error
331331
if ic.accountLevel {
332332
users, err = ic.accountClient.Users.ListAll(ic.Context, iam.ListAccountUsersRequest{
333-
Attributes: "userName,id",
333+
Attributes: "id,userName",
334334
})
335335
} else {
336336
users, err = ic.workspaceClient.Users.ListAll(ic.Context, iam.ListUsersRequest{
337-
Attributes: "userName,id",
337+
Attributes: "id,userName",
338338
})
339339
}
340340
if err != nil {

go.mod

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/databricks/terraform-provider-databricks
33
go 1.20
44

55
require (
6-
github.com/databricks/databricks-sdk-go v0.25.1-0.20231123150617-fe6b76828faa
6+
github.com/databricks/databricks-sdk-go v0.26.1
77
github.com/golang-jwt/jwt/v4 v4.5.0
88
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
99
github.com/hashicorp/hcl v1.0.0
@@ -60,15 +60,15 @@ require (
6060
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
6161
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
6262
go.opencensus.io v0.24.0 // indirect
63-
golang.org/x/crypto v0.15.0 // indirect
64-
golang.org/x/net v0.18.0 // indirect
65-
golang.org/x/oauth2 v0.14.0 // indirect
66-
golang.org/x/sys v0.14.0 // indirect
63+
golang.org/x/crypto v0.16.0 // indirect
64+
golang.org/x/net v0.19.0 // indirect
65+
golang.org/x/oauth2 v0.15.0 // indirect
66+
golang.org/x/sys v0.15.0 // indirect
6767
golang.org/x/text v0.14.0 // indirect
68-
golang.org/x/time v0.4.0 // indirect
69-
google.golang.org/api v0.151.0 // indirect
68+
golang.org/x/time v0.5.0 // indirect
69+
google.golang.org/api v0.152.0 // indirect
7070
google.golang.org/appengine v1.6.8 // indirect
71-
google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 // indirect
71+
google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f // indirect
7272
google.golang.org/grpc v1.59.0 // indirect
7373
google.golang.org/protobuf v1.31.0 // indirect
7474
gopkg.in/ini.v1 v1.67.0 // indirect

0 commit comments

Comments
 (0)