Skip to content

Instantly share code, notes, and snippets.

@angstwad
Created March 25, 2020 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angstwad/b6ac715a3e569f3a994387ff59281696 to your computer and use it in GitHub Desktop.
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
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