Skip to content

Commit

Permalink
Fixed regression in databricks_group data not to require workspace …
Browse files Browse the repository at this point in the history
…admin privileges (#2210)
  • Loading branch information
shreyas-goenka authored Apr 12, 2023
1 parent e30b8e0 commit c81812c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 57 deletions.
2 changes: 1 addition & 1 deletion exporter/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (ic *importContext) cacheGroups() error {
if len(ic.allGroups) == 0 {
log.Printf("[INFO] Caching groups in memory ...")
groupsAPI := scim.NewGroupsAPI(ic.Context, ic.Client)
g, err := groupsAPI.Filter("", true)
g, err := groupsAPI.Filter("")
if err != nil {
return err
}
Expand Down
44 changes: 6 additions & 38 deletions scim/data_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestDataSourceGroup(t *testing.T) {
Fixtures: []qa.HTTPFixture{
{
Method: "GET",
Resource: "/api/2.0/preview/scim/v2/Groups?excludedAttributes=roles&filter=displayName%20eq%20%27ds%27",
Resource: "/api/2.0/preview/scim/v2/Groups?filter=displayName%20eq%20%27ds%27",
Response: GroupList{
Resources: []Group{
{
Expand Down Expand Up @@ -48,43 +48,11 @@ func TestDataSourceGroup(t *testing.T) {
Value: "abc",
},
},
},
},
},
},
{
Method: "GET",
Resource: "/api/2.0/preview/scim/v2/Groups/eerste?attributes=members,roles,entitlements,externalId",
Response: Group{
DisplayName: "ds",
ID: "eerste",
Entitlements: []ComplexValue{
{
Value: "allow-cluster-create",
},
},
Roles: []ComplexValue{
{
Value: "a",
},
},
Members: []ComplexValue{
{
Ref: "Users/1112",
Value: "1112",
},
{
Ref: "ServicePrincipals/1113",
Value: "1113",
},
{
Ref: "Groups/1114",
Value: "1114",
},
},
Groups: []ComplexValue{
{
Value: "abc",
Roles: []ComplexValue{
{
Value: "a",
},
},
},
},
},
Expand Down
13 changes: 4 additions & 9 deletions scim/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,32 +40,27 @@ func (a GroupsAPI) Read(groupID, attributes string) (group Group, err error) {
}

// Filter returns groups matching the filter
func (a GroupsAPI) Filter(filter string, includeRoles bool) (GroupList, error) {
func (a GroupsAPI) Filter(filter string) (GroupList, error) {
var groups GroupList
req := map[string]string{}
if filter != "" {
req["filter"] = filter
}
if !includeRoles {
// We exclude roles to reduce load on the scim service
req["excludedAttributes"] = "roles"
}
err := a.client.Scim(a.context, http.MethodGet, "/preview/scim/v2/Groups", req, &groups)
return groups, err
}

func (a GroupsAPI) ReadByDisplayName(displayName, attributes string) (group Group, err error) {
groupList, err := a.Filter(fmt.Sprintf("displayName eq '%s'", displayName), false)
groupList, err := a.Filter(fmt.Sprintf("displayName eq '%s'", displayName))
if err != nil {
return
}
if len(groupList.Resources) == 0 {
err = fmt.Errorf("cannot find group: %s", displayName)
return
}
// We GET the group again to fetch any fields that were excluded the first
// time around
return a.Read(groupList.Resources[0].ID, attributes)
group = groupList.Resources[0]
return
}

func (a GroupsAPI) Patch(groupID string, r patchRequest) error {
Expand Down
11 changes: 2 additions & 9 deletions scim/resource_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func TestCreateForceOverwriteCannotListGroups(t *testing.T) {
qa.HTTPFixturesApply(t, []qa.HTTPFixture{
{
Method: "GET",
Resource: "/api/2.0/preview/scim/v2/Groups?excludedAttributes=roles&filter=displayName%20eq%20%27abc%27",
Resource: "/api/2.0/preview/scim/v2/Groups?filter=displayName%20eq%20%27abc%27",
Status: 417,
Response: apierr.APIError{
Message: "cannot find group",
Expand All @@ -376,7 +376,7 @@ func TestCreateForceOverwriteFindsAndSetsGroupID(t *testing.T) {
qa.HTTPFixturesApply(t, []qa.HTTPFixture{
{
Method: "GET",
Resource: "/api/2.0/preview/scim/v2/Groups?excludedAttributes=roles&filter=displayName%20eq%20%27abc%27",
Resource: "/api/2.0/preview/scim/v2/Groups?filter=displayName%20eq%20%27abc%27",
Response: GroupList{
Resources: []Group{
{
Expand All @@ -392,13 +392,6 @@ func TestCreateForceOverwriteFindsAndSetsGroupID(t *testing.T) {
ID: "123",
},
},
{
Method: "GET",
Resource: "/api/2.0/preview/scim/v2/Groups/123?attributes=",
Response: Group{
ID: "123",
},
},
{
Method: "PUT",
Resource: "/api/2.0/preview/scim/v2/Groups/123",
Expand Down

0 comments on commit c81812c

Please sign in to comment.