Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: save empty IAM policy bindings #155

Merged
merged 2 commits into from Mar 23, 2021
Merged

fix: save empty IAM policy bindings #155

merged 2 commits into from Mar 23, 2021

Conversation

busunkim96
Copy link
Contributor

@busunkim96 busunkim96 commented Mar 22, 2021

Fixes #154

__getitem__ currently returns an empty set() for items not in the bindings. If someone adds to the set returned by __getitem__ the changes will not be reflected on the actual policy object.

@busunkim96 busunkim96 requested a review from a team as a code owner March 22, 2021 21:52
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Mar 22, 2021
Comment on lines +35 to +36
assert len(policy) == 0
assert dict(policy) == {}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accessing policy.owners, policy.editors results in __getitem__ being called, which adds empty entries to the dictionary. I moved these empty dict asserts up as a result.

An alternative is to keep them in their previous location and check that the three roles with empty bindings were added

@busunkim96 busunkim96 merged commit 536c2ca into master Mar 23, 2021
@busunkim96 busunkim96 deleted the fix-154 branch March 23, 2021 19:16
gcf-merge-on-green bot pushed a commit that referenced this pull request Mar 25, 2021
Exclude empty policy bindings (bindings with no members) in
`Policy.__iter__()` and `Policy.__len__()`

Follow up to #155
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

google.api_core.iam.Policy.__getitem__ does not correctly save empty bindings
2 participants