Added option shownopolicy to `gam print chromepolicies

This commit is contained in:
Ross Scroggs
2026-02-05 11:27:19 -08:00
parent ea0886229e
commit 97358d15ef
3 changed files with 71 additions and 23 deletions

View File

@@ -2789,21 +2789,23 @@ gam create chromepolicyimage <ChromePolicyImageSchemaName> <FileName>
gam update chromepolicy [convertcrnl]
(<SchemaName> ((<Field> <Value>)+ | <JSONData>))+
((ou|orgunit <OrgUnitItem>)|(cigroup <GroupItem>))
((ou|orgunit <OrgUnitItem>)|(group <GroupItem>))
[(printerid <PrinterID>)|(appid <AppID>)]
gam delete chromepolicy
(<SchemaName> [<JSONData>])+
((ou|orgunit <OrgUnitItem>)|(cigroup <GroupItem>))
((ou|orgunit <OrgUnitItem>)|(group <GroupItem>))
[(printerid <PrinterID>)|(appid <AppID>)]
gam show chromepolicies
((ou|orgunit <OrgUnitItem> [show all|direct|inherited])|(cigroup <GroupItem>))
((ou|orgunit <OrgUnitItem> [show all|direct|inherited])|(group <GroupItem>))
[(printerid <PrinterID>)|(appid <AppID>)]
(filter <StringList>)* (namespace <NamespaceList>)*
[show all|direct|inherited]
[formatjson]
gam print chromepolicies [todrive <ToDriveAttribute>*]
((ou|orgunit <OrgUnitItem> [show all|direct|inherited])|(cigroup <GroupItem>))
((ou|orgunit <OrgUnitItem> [show all|direct|inherited])|(group <GroupItem>))
[(printerid <PrinterID>)|(appid <AppID>)]
(filter <StringList>)* (namespace <NamespaceList>)*
[show all|direct|inherited] [shownopolicy]
[[formatjson [quotechar <Character>]]
<ChromePolicySchemaFieldName> ::=

View File

@@ -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.

View File

@@ -25,7 +25,7 @@ https://github.com/GAM-team/GAM/wiki
"""
__author__ = 'GAM Team <google-apps-manager@googlegroups.com>'
__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 <OrgUnitItem>)|(group <GroupItem>))
# [(printerid <PrinterID>)|(appid <AppID>)]
# (filter <StringList>)* (namespace <NamespaceList>)*
# [show all|direct|inherited]
# [show all|direct|inherited] [shownopolicy]
# [[formatjson [quotechar <Character>]]
def doPrintShowChromePolicies():
def normalizedPolicy(policy):
@@ -30160,9 +30160,7 @@ def doPrintShowChromePolicies():
showJSON(None, policy, sortDictKeys=False)
Ind.Decrement()
def _printPolicy(policy):
policy = normalizedPolicy(policy)
if (entityType == Ent.GROUP) or showPolicies in (CHROME_POLICY_SHOW_ALL, policy['direct']):
def _printPolicyRow(policy):
row = flattenJSON(policy)
if not FJQC.formatJSON:
csvPF.WriteRowTitles(row)
@@ -30180,6 +30178,37 @@ def doPrintShowChromePolicies():
'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']):
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)
customer = _getCustomersCustomerIdWithC()
@@ -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 = {