Skip to content

Commit

Permalink
project roles and perms as csv
Browse files Browse the repository at this point in the history
  • Loading branch information
andylytical committed Aug 23, 2024
1 parent 1b559a0 commit 953637c
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 2 deletions.
28 changes: 28 additions & 0 deletions jira_cleanup/go_jira-cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
DEBUG=1
REGISTRY=ghcr.io
OWNER=ncsa
REPO=atlassian-tools


function is_windows {
rv=1
[[ -n "$USERPROFILE" ]] && rv=0
return $rv
}


[[ "$DEBUG" -eq 1 ]] && set -x

tag=latest

action=''
src_home="$HOME"
if is_windows ; then
action=winpty
src_home="$USERPROFILE"
fi

$action docker run -it --pull always \
--mount type=bind,src="${src_home}",dst=/home \
$REGISTRY/$OWNER/$REPO:$tag

64 changes: 62 additions & 2 deletions jira_cleanup/jira_set_basic_settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import configparser
import csv
import json
import logging
import netrc
Expand All @@ -17,7 +18,7 @@

logfmt = '%(levelname)s:%(funcName)s[%(lineno)d] %(message)s'
loglvl = logging.INFO
loglvl = logging.DEBUG
#loglvl = logging.DEBUG
logging.basicConfig( level=loglvl, format=logfmt )

# requests_log = logging.getLogger("urllib3")
Expand Down Expand Up @@ -133,6 +134,16 @@ def err( msg ):
logging.error( msg )


def get_role_id( name ):
key = 'roles'
if key not in resources:
path = f'role'
r = api_get( path )
rawdata = r.json()
resources[key] = { d['name']: d['id'] for d in rawdata }
return resources[key][name]


# https://stackoverflow.com/questions/1622943/timeit-versus-timing-decorator#27737385
def timing( f ):
@wraps( f )
Expand Down Expand Up @@ -280,6 +291,52 @@ def add_application_access_groups():
print( r.text )


def get_project_roles( pid ):
r = api_get( f'project/{pid}/role' )
data = r.json()
role_names = list( data.keys() )
roles = {}
for role in role_names:
rid = get_role_id( role )
role_data = get_project_role_details( pid, rid )
# print( f"Project:{pid} Role:'{role}'" )
# pprint.pprint( role_data )
actors = [ f"{r['name']} ({r['displayName']})" for r in role_data['actors'] ]
roles[role] = actors
return roles


def get_project_role_details( pid, role_id ):
path = f'project/{pid}/role/{role_id}'
r = api_get( path )
data = r.json()
return data


def project_roles_as_csv():
r = api_get( 'project' )
data = r.json()
project_keys = { p['key'] : p['name'] for p in data }
# projects = {}
csv_rows = [ ['Project', 'Role', 'Members'] ]
for pid,p_name in project_keys.items():
roles = get_project_roles( pid )
# projects[pid] = {
# 'name': p_name,
# 'roles': roles,
# }
for role, members in roles.items():
csv_rows.append( [ pid, role] + members )
# pprint.pprint( projects )
output = pathlib.Path( 'perms.csv' )
with output.open(mode='w', newline='') as f:
writer = csv.writer(f)
writer.writerows( csv_rows )
# return projects




def test_auth():
path = 'issue/SVCPLAN-2741'
r = api_get( path )
Expand All @@ -296,7 +353,10 @@ def run():

# set_general_config()

add_application_access_groups()
# add_application_access_groups() #returns error 400

project_roles_as_csv()
# get_project_roles( 'SVCPLAN', 10002 )

# elapsed = time.time() - starttime
# logging.info( f'Finished in {elapsed} seconds!' )
Expand Down

0 comments on commit 953637c

Please sign in to comment.