When displaying printers, add orgUnitPath (#1338)

This commit is contained in:
Ross Scroggs
2021-03-19 11:19:40 -07:00
committed by GitHub
parent 6f2ebf8d2d
commit 90160da042
4 changed files with 23 additions and 21 deletions

View File

@ -1739,7 +1739,7 @@ def doPrintAdmins():
value = f'id:{value}' value = f'id:{value}'
admin_attrib[ admin_attrib[
'orgUnit'] = gapi_directory_orgunits.orgunit_from_orgunitid( 'orgUnit'] = gapi_directory_orgunits.orgunit_from_orgunitid(
value) value, cd)
admin_attrib[key] = value admin_attrib[key] = value
csvRows.append(admin_attrib) csvRows.append(admin_attrib)
display.write_csv_file(csvRows, titles, 'Admins', todrive) display.write_csv_file(csvRows, titles, 'Admins', todrive)

View File

@ -402,20 +402,16 @@ def getOrgUnitId(orgUnit, cd=None):
return (orgUnit, result['orgUnitId']) return (orgUnit, result['orgUnitId'])
def buildOrgUnitIdToNameMap(): def orgunit_from_orgunitid(orgunitid, cd):
cd = gapi_directory.build() orgunitpath = GM_Globals[GM_MAP_ORGUNIT_ID_TO_NAME].get(orgunitid)
result = gapi.call(cd.orgunits(), if not orgunitpath:
'list', try:
orgunitpath = gapi.call(cd.orgunits(),
'get',
customerId=GC_Values[GC_CUSTOMER_ID], customerId=GC_Values[GC_CUSTOMER_ID],
fields='organizationUnits(orgUnitPath,orgUnitId)', orgUnitPath=f'id:{orgunitid}' if not orgunitid.startswith('id:') else orgunitid,
type='all') fields='orgUnitPath')['orgUnitPath']
GM_Globals[GM_MAP_ORGUNIT_ID_TO_NAME] = {} except:
for orgUnit in result['organizationUnits']: orgunitpath = orgunitid
GM_Globals[GM_MAP_ORGUNIT_ID_TO_NAME][ GM_Globals[GM_MAP_ORGUNIT_ID_TO_NAME][orgunitid] = orgunitpath
orgUnit['orgUnitId']] = orgUnit['orgUnitPath'] return orgunitpath
def orgunit_from_orgunitid(orgunitid):
if not GM_Globals[GM_MAP_ORGUNIT_ID_TO_NAME]:
buildOrgUnitIdToNameMap()
return GM_Globals[GM_MAP_ORGUNIT_ID_TO_NAME].get(orgunitid, orgunitid)

View File

@ -89,10 +89,13 @@ def info():
customer = _get_customerid() customer = _get_customerid()
printer_id = sys.argv[3] printer_id = sys.argv[3]
name = f'{customer}/chrome/printers/{printer_id}' name = f'{customer}/chrome/printers/{printer_id}'
result = gapi.call(cdapi.customers().chrome().printers(), printer = gapi.call(cdapi.customers().chrome().printers(),
'get', 'get',
name=name) name=name)
display.print_json(result) if 'orgUnitId' in printer:
printer['orgUnitPath'] = gapi_directory_orgunits.orgunit_from_orgunitid(
printer['orgUnitId'], cdapi)
display.print_json(printer)
def print_(): def print_():
@ -120,6 +123,9 @@ def print_():
parent=parent, parent=parent,
filter=filter_) filter=filter_)
for printer in printers: for printer in printers:
if 'orgUnitId' in printer:
printer['orgUnitPath'] = gapi_directory_orgunits.orgunit_from_orgunitid(
printer['orgUnitId'], cdapi)
row = {} row = {}
for key, val in printer.items(): for key, val in printer.items():
if key not in titles: if key not in titles:

View File

@ -1180,7 +1180,7 @@ GM_Globals = {
GM_OAUTH2SERVICE_ACCOUNT_CLIENT_ID: None, GM_OAUTH2SERVICE_ACCOUNT_CLIENT_ID: None,
GM_ENABLEDASA_TXT: '', GM_ENABLEDASA_TXT: '',
GM_LAST_UPDATE_CHECK_TXT: '', GM_LAST_UPDATE_CHECK_TXT: '',
GM_MAP_ORGUNIT_ID_TO_NAME: None, GM_MAP_ORGUNIT_ID_TO_NAME: {},
GM_MAP_ROLE_ID_TO_NAME: None, GM_MAP_ROLE_ID_TO_NAME: None,
GM_MAP_ROLE_NAME_TO_ID: None, GM_MAP_ROLE_NAME_TO_ID: None,
GM_MAP_USER_ID_TO_NAME: None, GM_MAP_USER_ID_TO_NAME: None,