From 8d6a65aa279eb6f450288e65e971c92b69efeae0 Mon Sep 17 00:00:00 2001 From: cknowles-moz Date: Tue, 21 May 2024 06:58:51 -0400 Subject: [PATCH] org_repo_perms.py - added a flag to only collect admin level permissions (#137) --- README.md | 10 ++++++++-- org_repo_perms.py | 15 ++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c941415..f7d824b 100644 --- a/README.md +++ b/README.md @@ -285,7 +285,9 @@ optional arguments: ## `org_repo_perms` ``` -usage: org_repo_perms.py [-h] [--pat-key PATKEY] [--token TOKEN] [--repo REPO] [--url URL] org +usage: org_repo_perms.py [-h] [--pat-key PATKEY] [--token TOKEN] [--repo REPO] + [--all] [--admin] [--url URL] + org Report all permissions given to repos to individuals (not by a team) @@ -296,7 +298,11 @@ options: -h, --help show this help message and exit --pat-key PATKEY key in .gh_pat.toml of the PAT to use --token TOKEN use this PAT to access resources - --repo REPO Specify a single repo to work on in the specified org if desired + --repo REPO Specify a single repo to work on in the specified org if + desired + --all Dump ALL (Well, not owners) permissions, not just non-team + singletons + --admin Only output admins of the repo --url URL the graphql URL ``` diff --git a/org_repo_perms.py b/org_repo_perms.py index 5ee4e78..b31d404 100755 --- a/org_repo_perms.py +++ b/org_repo_perms.py @@ -6,6 +6,8 @@ But sometimes we just need a dump of everything - so add a flag to look for more than singles """ +# TODO: Output only perms of ADMIN + import sys import alive_progress @@ -36,6 +38,7 @@ def parse_arguments(): help="Dump ALL (Well, not owners) permissions, not just non-team singletons", action="store_true", ) + parser.add_argument("--admin", help="Only output admins of the repo", action="store_true") parser.add_argument( "--url", type=str, @@ -182,9 +185,15 @@ def main(): outputlist = [] for repo in resultdict.keys(): line = f"{repo}," # noqa: E231 - for perms in resultdict[repo].keys(): - line = line + f"{perms}:{':'.join(resultdict[repo][perms])}," # noqa: E231 - outputlist.append(line) + if args.admin: + # print(f"keys = {resultdict[repo].keys()}, {'ADMIN' in resultdict[repo].keys()}") + if "ADMIN" in resultdict[repo].keys(): + line = line + f"{'ADMIN'}:{':'.join(resultdict[repo]['ADMIN'])}," # noqa: E231 + outputlist.append(line) + else: + for perms in resultdict[repo].keys(): + line = line + f"{perms}:{':'.join(resultdict[repo][perms])}," # noqa: E231 + outputlist.append(line) print("RepoName, PermissionsColumns") print("\n".join(outputlist))