Skip to content

Commit

Permalink
fix: future read on grants (#1520)
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

* add nil check

* add nil check

* add nil check

* fix future grant read

* fix future grant read

* fix case logic
  • Loading branch information
sfc-gh-swinkler authored Feb 6, 2023
1 parent 87689bb commit db78f64
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions pkg/resources/grant_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,13 @@ func readGenericGrant(
// Now see which roles have our privilege.
for roleName, privileges := range rolePrivileges {
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 {
// CASE A: If multiple grants is not enabled (meaning this is authoritative) then we always care about what roles have privilige.
caseA := !multipleGrantFeatureFlag
// CASE B: If this is not authoritative, then at least continue managing whatever roles we already are managing
caseB := multipleGrantFeatureFlag && existingRoles.Contains(roleName)
// CASE C: If this is not authoritative and we are not managing the role, then we only care about the role if future objects is disabled. Otherwise we will get flooded with diffs.
caseC := multipleGrantFeatureFlag && !futureObjects
if caseA || caseB || caseC {
roles = append(roles, roleName)
}
}
Expand All @@ -293,11 +295,13 @@ func readGenericGrant(
// Now see which shares have our privilege.
for shareName, privileges := range sharePrivileges {
if privileges.hasString(priv) {
// 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.
// CASE A: If multiple grants is not enabled (meaning this is authoritative) then we always care about what shares have privilige.
caseA := !multipleGrantFeatureFlag
// CASE B: If this is not authoritative, then at least continue managing whatever shares we already are managing
caseB := multipleGrantFeatureFlag && existingShares.Contains(shareName)
// CASE C: If this is not authoritative and we are not managing the share, then we only care about the share if future objects is disabled. Otherwise we will get flooded with diffs.
caseC := multipleGrantFeatureFlag && !futureObjects
if caseA || caseB || caseC {
shares = append(shares, shareName)
}
}
Expand Down

0 comments on commit db78f64

Please sign in to comment.