From 97358d15efc4ddc3e6cb957c37256eaaa46e4ac3 Mon Sep 17 00:00:00 2001 From: Ross Scroggs Date: Thu, 5 Feb 2026 11:27:19 -0800 Subject: [PATCH] Added option `shownopolicy` to `gam print chromepolicies --- src/GamCommands.txt | 10 ++++--- src/GamUpdate.txt | 12 ++++++++ src/gam/__init__.py | 72 +++++++++++++++++++++++++++++++++------------ 3 files changed, 71 insertions(+), 23 deletions(-) diff --git a/src/GamCommands.txt b/src/GamCommands.txt index 3942bd1f..4dfb7d03 100644 --- a/src/GamCommands.txt +++ b/src/GamCommands.txt @@ -2789,21 +2789,23 @@ gam create chromepolicyimage gam update chromepolicy [convertcrnl] ( (( )+ | ))+ - ((ou|orgunit )|(cigroup )) + ((ou|orgunit )|(group )) [(printerid )|(appid )] gam delete chromepolicy ( [])+ - ((ou|orgunit )|(cigroup )) + ((ou|orgunit )|(group )) [(printerid )|(appid )] gam show chromepolicies - ((ou|orgunit [show all|direct|inherited])|(cigroup )) + ((ou|orgunit [show all|direct|inherited])|(group )) [(printerid )|(appid )] (filter )* (namespace )* + [show all|direct|inherited] [formatjson] gam print chromepolicies [todrive *] - ((ou|orgunit [show all|direct|inherited])|(cigroup )) + ((ou|orgunit [show all|direct|inherited])|(group )) [(printerid )|(appid )] (filter )* (namespace )* + [show all|direct|inherited] [shownopolicy] [[formatjson [quotechar ]] ::= diff --git a/src/GamUpdate.txt b/src/GamUpdate.txt index dfbd5867..26163a08 100644 --- a/src/GamUpdate.txt +++ b/src/GamUpdate.txt @@ -1,3 +1,15 @@ +7.33.01 + +Added option `shownopolicy` to `gam print chromepolicies` that will display output like the following +if no policies apply to the selected OU or group. +``` +gam print chromepolicies ou /Test appid chrome:emidddocikgklceeeifefomdnbkldhng namespace chrome.users.apps shownopolicy +Getting all Chrome Policies that match query (chrome.users.apps.*) for /Test +Got 0 Chrome Policies that matched query (chrome.users.apps.*) for /Test... +name,orgUnitPath,parentOrgUnitPath,direct,appId +noPolicy,/Test,/,False,chrome:emidddocikgklceeeifefomdnbkldhng +``` + 7.33.00 Added variable `developer_preview_apis` to `gam.cfg` that is a comma separated list of APIs requiring a Developer Preview key. diff --git a/src/gam/__init__.py b/src/gam/__init__.py index 44c43dd3..38b7c30e 100755 --- a/src/gam/__init__.py +++ b/src/gam/__init__.py @@ -25,7 +25,7 @@ https://github.com/GAM-team/GAM/wiki """ __author__ = 'GAM Team ' -__version__ = '7.33.00' +__version__ = '7.33.01' __license__ = 'Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)' # pylint: disable=wrong-import-position @@ -30089,7 +30089,7 @@ CHROME_POLICY_SHOW_CHOICE_MAP = { # ((ou|orgunit )|(group )) # [(printerid )|(appid )] # (filter )* (namespace )* -# [show all|direct|inherited] +# [show all|direct|inherited] [shownopolicy] # [[formatjson [quotechar ]] def doPrintShowChromePolicies(): def normalizedPolicy(policy): @@ -30160,25 +30160,54 @@ def doPrintShowChromePolicies(): showJSON(None, policy, sortDictKeys=False) Ind.Decrement() + def _printPolicyRow(policy): + row = flattenJSON(policy) + if not FJQC.formatJSON: + csvPF.WriteRowTitles(row) + elif (not csvPF.rowFilter and not csvPF.rowDropFilter) or csvPF.CheckRowTitles(row): + if entityType == Ent.ORGANIZATIONAL_UNIT: + csvPF.WriteRowNoFilter({'name': policy['name'], + 'orgUnitPath': policy['orgUnitPath'], + 'parentOrgUnitPath': policy['parentOrgUnitPath'], + 'direct': policy['direct'], + 'JSON': json.dumps(cleanJSON(policy), + ensure_ascii=False, sort_keys=True)}) + else: + csvPF.WriteRowNoFilter({'name': policy['name'], + 'group': policy['group'], + 'JSON': json.dumps(cleanJSON(policy), + ensure_ascii=False, sort_keys=True)}) + + def _printPolicy(policy): + nonlocal policiesShown policy = normalizedPolicy(policy) if (entityType == Ent.GROUP) or showPolicies in (CHROME_POLICY_SHOW_ALL, policy['direct']): - row = flattenJSON(policy) - if not FJQC.formatJSON: - csvPF.WriteRowTitles(row) - elif (not csvPF.rowFilter and not csvPF.rowDropFilter) or csvPF.CheckRowTitles(row): - if entityType == Ent.ORGANIZATIONAL_UNIT: - csvPF.WriteRowNoFilter({'name': policy['name'], - 'orgUnitPath': policy['orgUnitPath'], - 'parentOrgUnitPath': policy['parentOrgUnitPath'], - 'direct': policy['direct'], - 'JSON': json.dumps(cleanJSON(policy), - ensure_ascii=False, sort_keys=True)}) - else: - csvPF.WriteRowNoFilter({'name': policy['name'], - 'group': policy['group'], - 'JSON': json.dumps(cleanJSON(policy), - ensure_ascii=False, sort_keys=True)}) + policiesShown += 1 + _printPolicyRow(policy) + + def _printNoPolicy(): + nonlocal targetName + policy = {'name': 'noPolicy'} + if app_id: + policy['appId'] = app_id + elif printer_id: + policy['printerId'] = printer_id + if entityType == Ent.ORGANIZATIONAL_UNIT: + policy['orgUnitPath'] = targetName + if targetName == '/': + policy['parentOrgUnitPath'] = '/' + else: + targetName = makeOrgUnitPathRelative(targetName) + policy['parentOrgUnitPath'] = callGAPI(cd.orgunits(), 'get', + throwReasons=GAPI.ORGUNIT_GET_THROW_REASONS, + customerId=GC.Values[GC.CUSTOMER_ID], + orgUnitPath=encodeOrgUnitPath(targetName), + fields='parentOrgUnitPath')['parentOrgUnitPath'] + policy['direct'] = False + else: + policy['group'] = targetName + _printPolicyRow(policy) cp = buildGAPIObject(API.CHROMEPOLICY) cd = buildGAPIObject(API.DIRECTORY) @@ -30190,6 +30219,8 @@ def doPrintShowChromePolicies(): app_id = groupEmail = orgUnit = printer_id = targetResource = None showPolicies = CHROME_POLICY_SHOW_ALL psFilters = [] + showNoPolicy = False + policiesShown = 0 while Cmd.ArgumentsRemaining(): myarg = getArgument() if csvPF and myarg == 'todrive': @@ -30213,6 +30244,8 @@ def doPrintShowChromePolicies(): psFilters.append(f'{psFilter}.*') elif myarg == 'show': showPolicies = getChoice(CHROME_POLICY_SHOW_CHOICE_MAP, mapChoice=True) + elif csvPF and myarg == 'shownopolicy': + showNoPolicy = True else: FJQC.GetFormatJSONQuoteChar(myarg, False) checkPolicyArgs(targetResource, printer_id, app_id) @@ -30302,7 +30335,8 @@ def doPrintShowChromePolicies(): else: for policy in policies: _printPolicy(policy) - if csvPF: + if showNoPolicy and policiesShown == 0: + _printNoPolicy() csvPF.writeCSVfile(f'Chrome Policies - {targetName}') CHROME_IMAGE_SCHEMAS_MAP = {