Created
March 25, 2020 15:31
-
-
Save angstwad/b6ac715a3e569f3a994387ff59281696 to your computer and use it in GitHub Desktop.
Snippets for Blog: Solving a Set Cover Problem in Cloud IAM on GCP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while remaining: | |
for perm in remaining: | |
# get set of roles which contain permission | |
satisfy = perms_to_roles[perm] | |
# sort roles by the number of permissions they contain, select role | |
# with the most | |
sorted_roles = sorted((role, perms_counts[role]) | |
for role in satisfy) | |
selected = sorted_roles[-1][0] | |
# add this role to selected roles and recalculate remaining perms | |
selected_roles.add(selected) | |
remaining = remaining - roles_to_perms[selected] | |
# we're recalculating remaining in-place, so we have to break | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment