Skip to content

Commit

Permalink
fix(grant): use grant at headIndex as sample grant
Browse files Browse the repository at this point in the history
  • Loading branch information
rahmatrhd committed Feb 2, 2023
1 parent 61f396b commit 2503d24
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions core/grant/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,11 @@ func (s *Service) ImportFromProvider(ctx context.Context, criteria ImportFromPro
// group grants for the same account (accountGrants) by provider role
rc := resourceConfigs[resource.Type]
grants = reduceGrantsByProviderRole(rc, grants)
for _, g := range grants {
for i, g := range grants {
key := g.PermissionsKey()
if existingGrant, ok := activeGrantsMap[rURN][accountSignature][key]; ok {
// replace imported grant values with existing grant
*g = *existingGrant
*grants[i] = *existingGrant

// remove updated grant from active grants map
delete(activeGrantsMap[rURN][accountSignature], key)
Expand Down Expand Up @@ -434,7 +434,7 @@ func reduceGrantsByProviderRole(rc *domain.ResourceConfig, grants []*domain.Gran

for roleID, permissionsByRole := range rolePermissionsMap {
if containing, headIndex := utils.SubsliceExists(allGrantPermissions, permissionsByRole); containing {
sampleGrant := grantsGroupedByPermission[allGrantPermissions[0]]
sampleGrant := grantsGroupedByPermission[allGrantPermissions[headIndex]]
sampleGrant.Role = roleID
sampleGrant.Permissions = permissionsByRole
reducedGrants = append(reducedGrants, sampleGrant)
Expand Down

0 comments on commit 2503d24

Please sign in to comment.