From 239fcba631ac0f45ff800ee52d1abc9524b5b641 Mon Sep 17 00:00:00 2001 From: Ross Scroggs Date: Fri, 7 Feb 2020 09:13:48 -0800 Subject: [PATCH] Tow updates/fixes (#1084) * Allow : in row filter field names export GAM_CSV_ROW_FILTER="'\"accounts:used_quota_in_mb\":count>=15000'" * Updated code to handle Directory API issue that prevents looking up the orgUnitId of OU / This affected `gam report` if you used the `orgunit /` option. This affected `gam create admin org_unit /`. --- src/gam.py | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/gam.py b/src/gam.py index ecc96a24..e1e8b6c9 100755 --- a/src/gam.py +++ b/src/gam.py @@ -506,7 +506,9 @@ def SetGlobalVariables(): if not filterVal: continue try: - column, filterStr = filterVal.split(':', 1) + filterTokens = shlexSplitList(filterVal, ':') + column = filterTokens[0] + filterStr = ':'.join(filterTokens[1:]) except ValueError: controlflow.system_error_exit(3, 'Item: {0}, Value: "{1}", Expected column:filter'.format(itemName, filterVal)) filterDict[column] = filterStr @@ -10674,16 +10676,6 @@ def getOrgUnitItem(orgUnit, pathOnly=False, absolutePath=True): return makeOrgUnitPathAbsolute(orgUnit) return makeOrgUnitPathRelative(orgUnit) -def getOrgUnitId(orgUnit, cd=None): - if cd is None: - cd = buildGAPIObject('directory') - orgUnit = getOrgUnitItem(orgUnit) - if orgUnit[:3] == 'id:': - return (orgUnit, orgUnit) - result = gapi.call(cd.orgunits(), 'get', - customerId=GC_Values[GC_CUSTOMER_ID], orgUnitPath=encodeOrgUnitPath(makeOrgUnitPathRelative(orgUnit)), fields='orgUnitId') - return (orgUnit, result['orgUnitId']) - def getTopLevelOrgId(cd, orgUnitPath): try: # create a temp org so we can learn what the top level org ID is (sigh) @@ -10696,6 +10688,26 @@ def getTopLevelOrgId(cd, orgUnitPath): pass return None +def getOrgUnitId(orgUnit, cd=None): + if cd is None: + cd = buildGAPIObject('directory') + orgUnit = getOrgUnitItem(orgUnit) + if orgUnit[:3] == 'id:': + return (orgUnit, orgUnit) + if orgUnit == '/': + result = gapi.call(cd.orgunits(), 'list', + customerId=GC_Values[GC_CUSTOMER_ID], orgUnitPath='/', type='children', + fields='organizationUnits(parentOrgUnitId)') + if result.get('organizationUnits', []): + return (orgUnit, result['organizationUnits'][0]['parentOrgUnitId']) + topLevelOrgId = getTopLevelOrgId(cd, '/') + if topLevelOrgId: + return (orgUnit, topLevelOrgId) + return (orgUnit, '/') #Bogus but should never happen + result = gapi.call(cd.orgunits(), 'get', + customerId=GC_Values[GC_CUSTOMER_ID], orgUnitPath=encodeOrgUnitPath(makeOrgUnitPathRelative(orgUnit)), fields='orgUnitId') + return (orgUnit, result['orgUnitId']) + def doGetOrgInfo(name=None, return_attrib=None): cd = buildGAPIObject('directory') checkSuspended = None