Skip to content

Commit

Permalink
fix: multiple share grants (#1510)
Browse files Browse the repository at this point in the history
* fix: multiple share grants

* fix: multiple share grants

* fix: multiple share grants

* fix: multiple share grants
  • Loading branch information
sfc-gh-swinkler authored Feb 2, 2023
1 parent f950dac commit d501226
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions pkg/resources/grant_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,26 +267,39 @@ func readGenericGrant(
}
}

existingRoles := d.Get("roles").(*schema.Set)
var existingRoles *schema.Set
if v, ok := d.GetOk("roles"); ok {
existingRoles = v.(*schema.Set)
}
multipleGrantFeatureFlag := d.Get("enable_multiple_grants").(bool)
var roles, shares []string

// Now see which roles have our privilege
// Now see which roles have our privilege.
for roleName, privileges := range rolePrivileges {
// Where priv is not all so it should match exactly
// Match to currently assigned roles or let everything through if no specific role grants
if privileges.hasString(priv) && !multipleGrantFeatureFlag {
roles = append(roles, roleName)
} else if privileges.hasString(priv) && (existingRoles.Contains(roleName) || existingRoles.Len() == 0) && multipleGrantFeatureFlag {
roles = append(roles, roleName)
if privileges.hasString(priv) {
// If multiple grants is not enabled then we care about what roles have privilige.
if !multipleGrantFeatureFlag {
roles = append(roles, roleName)
// otherwise we only care if the role is something we are already managing, or if future object grants are enabled.
} else if existingRoles.Contains(roleName) && !futureObjects {
roles = append(roles, roleName)
}
}
}

// Now see which shares have our privilege
var existingShares *schema.Set
if v, ok := d.GetOk("shares"); ok {
existingShares = v.(*schema.Set)
}
// Now see which shares have our privilege.
for shareName, privileges := range sharePrivileges {
// Where priv is not all so it should match exactly
if privileges.hasString(priv) {
shares = append(shares, shareName)
// If multiple grants is not enabled then we care about what shares have privilige.
if !multipleGrantFeatureFlag {
shares = append(shares, shareName)
} else if existingShares.Contains(shareName) && !futureObjects {
// otherwise we only care if the share is something we are already managing or if future object grants are enabled.
shares = append(shares, shareName)
}
}
}

Expand Down

0 comments on commit d501226

Please sign in to comment.