Do print|show for caalevels and oushareddrives (#1506)

This commit is contained in:
Ross Scroggs
2022-04-08 09:28:11 -07:00
committed by GitHub
parent 6de424b185
commit 5eb1277691
3 changed files with 54 additions and 10 deletions

View File

@@ -52,9 +52,22 @@ def get_access_policy(caa=None):
controlflow.system_error_exit(2, ' Could not find a org level access policy. That is odd.')
def print_access_levels():
def printshow_access_levels(csvFormat):
caa = build()
ap_name = get_access_policy(caa)
if csvFormat:
todrive = False
csvRows = []
titles = ['name', 'title']
i = 3
while i < len(sys.argv):
myarg = sys.argv[i].lower()
if csvFormat and myarg == 'todrive':
todrive = True
i += 1
else:
controlflow.invalid_argument_exit(sys.argv[i],
f"gam {['show', 'print'][csvFormat]} caalevels")
try:
levels = gapi.get_all_pages(caa.accessPolicies().accessLevels(),
'list',
@@ -64,9 +77,16 @@ def print_access_levels():
accessLevelFormat='CEL', fields='*')
except googleapiclient.errors.HttpError:
_gen_role_error(caa)
for level in levels:
display.print_json(level)
print()
if not csvFormat:
for level in levels:
display.print_json(level)
print()
else:
for level in levels:
display.add_row_titles_to_csv_file(
utils.flatten_json(level),
csvRows, titles)
display.write_csv_file(csvRows, titles, 'CAA Levels', todrive)
def build_os_constraints(constraints):

View File

@@ -32,11 +32,24 @@ def move_shared_drive(driveId, orgUnit):
name=name,
body=body)
def print_orgunit_shared_drives():
def printshow_orgunit_shared_drives(csvFormat):
try:
orgunit = sys.argv[3]
except IndexError:
orgunit = '/'
if csvFormat:
todrive = False
csvRows = []
titles = ['name']
i = 4
while i < len(sys.argv):
myarg = sys.argv[i].lower()
if csvFormat and myarg == 'todrive':
todrive = True
i += 1
else:
controlflow.invalid_argument_exit(sys.argv[i],
f"gam {['show', 'print'][csvFormat]} oushareddrives")
ci = gapi_cloudidentity.build('cloudidentity_beta')
_, orgUnitId = gapi_directory_orgunits.getOrgUnitId(orgunit)
parent = f'orgUnits/{orgUnitId[3:]}'
@@ -47,6 +60,13 @@ def print_orgunit_shared_drives():
parent=parent,
customer=_get_orgunit_customerid(),
filter=filter_)
for sd in sds:
display.print_json(sd)
print()
if not csvFormat:
for sd in sds:
display.print_json(sd)
print()
else:
for sd in sds:
display.add_row_titles_to_csv_file(
utils.flatten_json(sd),
csvRows, titles)
display.write_csv_file(csvRows, titles, f'OrgUnit {orgunit} Shared Drives', todrive)