@@ -189,58 +189,65 @@ func (g *groupBuilder) Grants(ctx context.Context, resource *v2.Resource, pToken
189189 return nil , "" , nil , fmt .Errorf ("databricks-connector: failed to parse group resource id: %w" , err )
190190 }
191191
192- groupTrait , err := rs .GetGroupTrait (resource )
193- if err != nil {
194- return nil , "" , nil , err
195- }
196-
197192 var workspaceId string
198193 isWorkspaceGroup := parentId .ResourceType == workspaceResourceType .Id
199194 if isWorkspaceGroup {
200195 workspaceId = parentId .Resource
201196 }
202197
203198 // membership grants
204- membersPayload , ok := rs .GetProfileStringValue (groupTrait .Profile , "members" )
205- if ok {
206- members := strings .Split (membersPayload , "," )
207-
208- for _ , m := range members {
209- pp := strings .Split (m , "/" )
210- if len (pp ) != 2 {
211- return nil , "" , nil , fmt .Errorf ("databricks-connector: invalid member format of %s: %w" , m , err )
212- }
199+ // Always fetch the group with members attribute to ensure we get the members
200+ // regardless of authentication type (OAuth vs personal access token)
201+ group , rateLimitData , err := g .client .GetGroup (ctx , workspaceId , groupId .Resource , databricks .NewGroupAttrVars ())
202+ if err != nil {
203+ return nil , "" , nil , fmt .Errorf ("databricks-connector: failed to get group %s: %w" , groupId .Resource , err )
204+ }
213205
214- memberType , memberID := pp [0 ], pp [1 ]
215- var resourceId * v2.ResourceId
216- var anns []protoreflect.ProtoMessage
206+ annos := annotations.Annotations {}
207+ if rateLimitData != nil {
208+ annos .WithRateLimiting (rateLimitData )
209+ }
217210
218- switch memberType {
219- case "Users" :
220- resourceId = & v2.ResourceId {ResourceType : userResourceType .Id , Resource : memberID }
221- case "Groups" :
222- rid , expandAnnotation , err := groupGrantExpansion (ctx , memberID , parentId )
223- if err != nil {
224- return rv , "" , nil , err
225- }
226- resourceId = rid
227- anns = append (anns , expandAnnotation )
228- case "ServicePrincipals" :
229- resourceId = & v2.ResourceId {ResourceType : servicePrincipalResourceType .Id , Resource : memberID }
230- default :
231- return nil , "" , nil , fmt .Errorf ("databricks-connector: invalid member type: %s" , memberType )
232- }
211+ for _ , member := range group .Members {
212+ // member.Ref contains the type and ID separated by "/", e.g., "Users/123" or "Groups/456"
213+ pp := strings .Split (member .Ref , "/" )
214+ if len (pp ) != 2 {
215+ return nil , "" , nil , fmt .Errorf ("databricks-connector: invalid member format of %s" , member .Ref )
216+ }
217+
218+ memberType , memberID := pp [0 ], pp [1 ]
219+ var resourceId * v2.ResourceId
220+ var anns []protoreflect.ProtoMessage
233221
234- rv = append (rv , grant .NewGrant (resource , groupMemberEntitlement , resourceId , grant .WithAnnotation (anns ... )))
222+ switch memberType {
223+ case "Users" :
224+ resourceId = & v2.ResourceId {ResourceType : userResourceType .Id , Resource : memberID }
225+ case "Groups" :
226+ rid , expandAnnotation , err := groupGrantExpansion (ctx , memberID , parentId )
227+ if err != nil {
228+ return rv , "" , nil , err
229+ }
230+ resourceId = rid
231+ anns = append (anns , expandAnnotation )
232+ case "ServicePrincipals" :
233+ resourceId = & v2.ResourceId {ResourceType : servicePrincipalResourceType .Id , Resource : memberID }
234+ default :
235+ return nil , "" , nil , fmt .Errorf ("databricks-connector: invalid member type: %s" , memberType )
235236 }
237+
238+ rv = append (rv , grant .NewGrant (resource , groupMemberEntitlement , resourceId , grant .WithAnnotation (anns ... )))
236239 }
237240
238241 // role permissions grants
239- ruleSets , _ , err := g .client .ListRuleSets (ctx , workspaceId , GroupsType , groupId .Resource )
242+ ruleSets , rateLimitDataRuleSets , err := g .client .ListRuleSets (ctx , workspaceId , GroupsType , groupId .Resource )
240243 if err != nil {
241244 return nil , "" , nil , fmt .Errorf ("databricks-connector: failed to list role rule sets for group %s: %w" , resource .Id .Resource , err )
242245 }
243246
247+ if rateLimitDataRuleSets != nil {
248+ annos .WithRateLimiting (rateLimitDataRuleSets )
249+ }
250+
244251 for _ , ruleSet := range ruleSets {
245252 for _ , p := range ruleSet .Principals {
246253 resourceId , err := prepareResourceId (ctx , g .client , workspaceId , p )
@@ -261,7 +268,7 @@ func (g *groupBuilder) Grants(ctx context.Context, resource *v2.Resource, pToken
261268 }
262269 }
263270
264- return rv , "" , nil , nil
271+ return rv , "" , annos , nil
265272}
266273
267274func (g * groupBuilder ) Grant (ctx context.Context , principal * v2.Resource , entitlement * v2.Entitlement ) (annotations.Annotations , error ) {
@@ -306,7 +313,7 @@ func (g *groupBuilder) Grant(ctx context.Context, principal *v2.Resource, entitl
306313 membershipEntitlementID := ent .NewEntitlementID (entitlement .Resource , groupMemberEntitlement )
307314 managerEntitlementID := ent .NewEntitlementID (entitlement .Resource , groupManagerEntitlement )
308315 if entitlement .Id == membershipEntitlementID {
309- group , _ , err := g .client .GetGroup (ctx , workspaceId , groupId .Resource )
316+ group , _ , err := g .client .GetGroup (ctx , workspaceId , groupId .Resource , databricks . NewGroupAttrVars () )
310317 if err != nil {
311318 return nil , fmt .Errorf ("databricks-connector: failed to get group %s: %w" , groupId .Resource , err )
312319 }
@@ -449,7 +456,7 @@ func (g *groupBuilder) Revoke(ctx context.Context, grant *v2.Grant) (annotations
449456 membershipEntitlementID := ent .NewEntitlementID (entitlement .Resource , groupMemberEntitlement )
450457 managerEntitlementID := ent .NewEntitlementID (entitlement .Resource , groupManagerEntitlement )
451458 if entitlement .Id == membershipEntitlementID {
452- group , _ , err := g .client .GetGroup (ctx , workspaceId , groupId .Resource )
459+ group , _ , err := g .client .GetGroup (ctx , workspaceId , groupId .Resource , databricks . NewGroupAttrVars () )
453460 if err != nil {
454461 return nil , fmt .Errorf ("databricks-connector: failed to get group %s: %w" , groupId .Resource , err )
455462 }
0 commit comments