Skip to content

Instantly share code, notes, and snippets.

View angstwad's full-sized avatar

Paul Durivage angstwad

View GitHub Profile
@angstwad
angstwad / set_cover_4.py
Created March 25, 2020 14:44
Snippets for Blog: Solving a Set Cover Problem in Cloud IAM on GCP
roles_sorted_by_perms_asc = sorted(perms_counts.items(),
key=lambda x: x[1])
@angstwad
angstwad / set_cover_5.py
Created March 25, 2020 14:45
Snippets for Blog: Solving a Set Cover Problem in Cloud IAM on GCP
subset_roles = set()
for this_role, _ in roles_sorted_by_perms_asc:
for other_role, other_perms in roles_to_perms.items():
if this_role == other_role:
continue
this_perms = roles_to_perms[this_role]
if this_perms.issubset(other_perms):
subset_roles.add(this_role)
@angstwad
angstwad / set_cover_6.py
Created March 25, 2020 15:21
Snippets for Blog: Solving a Set Cover Problem in Cloud IAM on GCP
role_with_most_perms = roles_sorted_by_perms_asc[-1][0]
@angstwad
angstwad / set_cover_7.py
Created March 25, 2020 15:29
Snippets for Blog: Solving a Set Cover Problem in Cloud IAM on GCP
selected_roles = {role_with_most_perms,}
@angstwad
angstwad / set_cover_8.py
Created March 25, 2020 15:30
Snippets for Blog: Solving a Set Cover Problem in Cloud IAM on GCP
remaining = unique_perms - roles_to_perms['roles/owner']
@angstwad
angstwad / set_cover_9.py
Created March 25, 2020 15:31
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]
@angstwad
angstwad / set_cover_10.txt
Created March 25, 2020 15:35
Snippets for Blog: Solving a Set Cover Problem in Cloud IAM on GCP
roles/axt.admin
roles/billing.admin
roles/billing.creator
roles/compute.xpnAdmin
roles/container.hostServiceAgentUser
roles/datacatalog.categoryFineGrainedReader
roles/datafusion.serviceAgent
roles/iam.serviceAccountTokenCreator
roles/iap.httpsResourceAccessor
roles/orgpolicy.policyAdmin
@angstwad
angstwad / git-lg.sh
Created January 12, 2016 17:31
Better Git Log (git lg)
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
@angstwad
angstwad / app.py
Last active June 2, 2021 23:11
todo flask app
# Import Flask, Jsonify and Requests
from flask import Flask, jsonify, request
# Create the web applicatiion via Flask
app = Flask(__name__)
# Existing To-Do List
# it's easiest to manipulate if this is a dict where key is the id and value is the todo
todos = {
1: "Buy Hitman 3",
@angstwad
angstwad / signals.py
Created October 14, 2020 18:00
A simple script to catch any valid OS signals and simulate an action in response to a signal
import argparse
import functools
import logging
import os
import signal
import sys
import time
_LOG_FORMAT = "%(levelname)s:%(asctime)s:%(name)s:%(message)s"
logging.basicConfig(stream=sys.stdout, format=_LOG_FORMAT)