mirror of
https://github.com/GAM-team/GAM.git
synced 2025-07-09 22:23:35 +00:00
Update gam print|show|update chromepolicy
to handle the following special case policies: (#1399)
``` chrome.users.AutoUpdateCheckPeriodNew autoupdatecheckperiodminutesnew chrome.users.BrowserSwitcherDelayDuration browserswitcherdelayduration chrome.users.FetchKeepaliveDurationSecondsOnShutdown fetchkeepalivedurationsecondsonshutdown chrome.users.MaxInvalidationFetchDelay maxinvalidationfetchdelay chrome.users.PrintingMaxSheetsAllowed printingmaxsheetsallowednullable chrome.users.PrintJobHistoryExpirationPeriodNew printjobhistoryexpirationperioddaysnew chrome.users.SecurityTokenSessionSettings securitytokensessionnotificationseconds chrome.users.SessionLength sessiondurationlimit chrome.users.UpdatesSuppressed updatessuppresseddurationmin chrome.users.UpdatesSuppressed updatessuppressedstarttime ```
This commit is contained in:
@ -104,7 +104,6 @@ def printshow_policies():
|
|||||||
for policy in policies:
|
for policy in policies:
|
||||||
print()
|
print()
|
||||||
name = policy.get('value', {}).get('policySchema', '')
|
name = policy.get('value', {}).get('policySchema', '')
|
||||||
schema = CHROME_SCHEMA_TYPE_MESSAGE.get(name)
|
|
||||||
for key, val in policy['targetKey'].get('additionalTargetKeys', {}).items():
|
for key, val in policy['targetKey'].get('additionalTargetKeys', {}).items():
|
||||||
additional_id = f'{key} - {val}'
|
additional_id = f'{key} - {val}'
|
||||||
if additional_id not in printed_ids:
|
if additional_id not in printed_ids:
|
||||||
@ -114,13 +113,22 @@ def printshow_policies():
|
|||||||
print(f'{spacing}{name}')
|
print(f'{spacing}{name}')
|
||||||
values = policy.get('value', {}).get('value', {})
|
values = policy.get('value', {}).get('value', {})
|
||||||
for setting, value in values.items():
|
for setting, value in values.items():
|
||||||
# Handle TYPE_MESSAGE fields with durations or counts as a special case
|
# Handle TYPE_MESSAGE fields with durations, values, counts and timeOfDay as special cases
|
||||||
|
schema = CHROME_SCHEMA_TYPE_MESSAGE.get(name, {}).get(setting.lower())
|
||||||
if schema and setting == schema['casedField']:
|
if schema and setting == schema['casedField']:
|
||||||
value = value.get(schema['type'], '')
|
vtype = schema['type']
|
||||||
|
if vtype in {'duration', 'value'}:
|
||||||
|
value = value.get(vtype, '')
|
||||||
if value:
|
if value:
|
||||||
if value.endswith('s'):
|
if value.endswith('s'):
|
||||||
value = value[:-1]
|
value = value[:-1]
|
||||||
value = int(value) // schema['scale']
|
value = int(value) // schema['scale']
|
||||||
|
elif vtype == 'count':
|
||||||
|
pass
|
||||||
|
else: ##timeOfDay
|
||||||
|
hours = value.get(vtype, {}).get('hours', 0)
|
||||||
|
minutes = value.get(vtype, {}).get('minutes', 0)
|
||||||
|
value = f'{hours:02}:{minutes:02}'
|
||||||
elif isinstance(value, str) and value.find('_ENUM_') != -1:
|
elif isinstance(value, str) and value.find('_ENUM_') != -1:
|
||||||
value = value.split('_ENUM_')[-1]
|
value = value.split('_ENUM_')[-1]
|
||||||
print(f'{spacing}{setting}: {value}')
|
print(f'{spacing}{setting}: {value}')
|
||||||
@ -266,21 +274,45 @@ def delete_policy():
|
|||||||
|
|
||||||
|
|
||||||
CHROME_SCHEMA_TYPE_MESSAGE = {
|
CHROME_SCHEMA_TYPE_MESSAGE = {
|
||||||
'chrome.users.SessionLength':
|
'chrome.users.AutoUpdateCheckPeriodNew': {
|
||||||
{'field': 'sessiondurationlimit', 'casedField': 'sessionDurationLimit',
|
'autoupdatecheckperiodminutesnew':
|
||||||
'type': 'duration', 'minVal': 1, 'maxVal': 1440, 'scale': 60},
|
{'casedField': 'autoUpdateCheckPeriodMinutesNew',
|
||||||
|
'type': 'duration', 'minVal': 1, 'maxVal': 720, 'scale': 60}},
|
||||||
'chrome.users.BrowserSwitcherDelayDuration':
|
'chrome.users.BrowserSwitcherDelayDuration':
|
||||||
{'field': 'browserswitcherdelayduration', 'casedField': 'browserSwitcherDelayDuration',
|
{'browserswitcherdelayduration':
|
||||||
'type': 'duration', 'minVal': 0, 'maxVal': 30, 'scale': 1},
|
{'casedField': 'browserSwitcherDelayDuration',
|
||||||
|
'type': 'duration', 'minVal': 0, 'maxVal': 30, 'scale': 1}},
|
||||||
|
'chrome.users.FetchKeepaliveDurationSecondsOnShutdown':
|
||||||
|
{'fetchkeepalivedurationsecondsonshutdown':
|
||||||
|
{'casedField': 'fetchKeepaliveDurationSecondsOnShutdown',
|
||||||
|
'type': 'duration', 'minVal': 0, 'maxVal': 5, 'scale': 1}},
|
||||||
'chrome.users.MaxInvalidationFetchDelay':
|
'chrome.users.MaxInvalidationFetchDelay':
|
||||||
{'field': 'maxinvalidationfetchdelay', 'casedField': 'maxInvalidationFetchDelay',
|
{'maxinvalidationfetchdelay':
|
||||||
'type': 'duration', 'minVal': 1, 'maxVal': 30, 'scale': 1},
|
{'casedField': 'maxInvalidationFetchDelay',
|
||||||
'chrome.users.SecurityTokenSessionSettings':
|
'type': 'duration', 'minVal': 1, 'maxVal': 30, 'scale': 1, 'default': 10}},
|
||||||
{'field': 'securitytokensessionnotificationseconds', 'casedField': 'securityTokenSessionNotificationSeconds',
|
|
||||||
'type': 'duration', 'minVal': 0, 'maxVal': 9999, 'scale': 1},
|
|
||||||
'chrome.users.PrintingMaxSheetsAllowed':
|
'chrome.users.PrintingMaxSheetsAllowed':
|
||||||
{'field': 'printingmaxsheetsallowednullable', 'casedField': 'printingMaxSheetsAllowedNullable',
|
{'printingmaxsheetsallowednullable':
|
||||||
'type': 'value', 'minVal': 1, 'maxVal': None, 'scale': 1},
|
{'casedField': 'printingMaxSheetsAllowedNullable',
|
||||||
|
'type': 'value', 'minVal': 1, 'maxVal': None, 'scale': 1}},
|
||||||
|
'chrome.users.PrintJobHistoryExpirationPeriodNew':
|
||||||
|
{'printjobhistoryexpirationperioddaysnew':
|
||||||
|
{'casedField': 'printJobHistoryExpirationPeriodDaysNew',
|
||||||
|
'type': 'duration', 'minVal': -1, 'maxVal': None, 'scale': 86400}},
|
||||||
|
'chrome.users.SecurityTokenSessionSettings':
|
||||||
|
{'securitytokensessionnotificationseconds':
|
||||||
|
{'casedField': 'securityTokenSessionNotificationSeconds',
|
||||||
|
'type': 'duration', 'minVal': 0, 'maxVal': 9999, 'scale': 1}},
|
||||||
|
'chrome.users.SessionLength':
|
||||||
|
{'sessiondurationlimit':
|
||||||
|
{'casedField': 'sessionDurationLimit',
|
||||||
|
'type': 'duration', 'minVal': 1, 'maxVal': 1440, 'scale': 60}},
|
||||||
|
'chrome.users.UpdatesSuppressed':
|
||||||
|
{'updatessuppresseddurationmin':
|
||||||
|
{'casedField': 'updatesSuppressedDurationMin',
|
||||||
|
'type': 'count', 'minVal': 1, 'maxVal': 1440, 'scale': 1},
|
||||||
|
'updatessuppressedstarttime':
|
||||||
|
{'casedField': 'updatesSuppressedStartTime',
|
||||||
|
'type': 'timeOfDay'}},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -314,18 +346,38 @@ def update_policy():
|
|||||||
field = sys.argv[i].lower()
|
field = sys.argv[i].lower()
|
||||||
if field in ['ou', 'org', 'orgunit', 'printerid', 'appid'] or '.' in field:
|
if field in ['ou', 'org', 'orgunit', 'printerid', 'appid'] or '.' in field:
|
||||||
break # field is actually a new policy, orgunit or app/printer id
|
break # field is actually a new policy, orgunit or app/printer id
|
||||||
# Handle TYPE_MESSAGE fields with durations or counts as a special case
|
# Handle TYPE_MESSAGE fields with durations, values, counts and timeOfDay as special cases
|
||||||
schema = CHROME_SCHEMA_TYPE_MESSAGE.get(schemaName)
|
schema = CHROME_SCHEMA_TYPE_MESSAGE.get(schemaName, {}).get(field)
|
||||||
if schema and field == schema['field']:
|
if schema:
|
||||||
|
i += 1
|
||||||
casedField = schema['casedField']
|
casedField = schema['casedField']
|
||||||
value = gam.getInteger(sys.argv[i+1], casedField,
|
vtype = schema['type']
|
||||||
|
if vtype != 'timeOfDay':
|
||||||
|
if 'default' not in schema:
|
||||||
|
value = gam.getInteger(sys.argv[i], casedField,
|
||||||
minVal=schema['minVal'], maxVal=schema['maxVal'])*schema['scale']
|
minVal=schema['minVal'], maxVal=schema['maxVal'])*schema['scale']
|
||||||
if schema['type'] == 'duration':
|
i += 1
|
||||||
body['requests'][-1]['policyValue']['value'][casedField] = {schema['type']: f'{value}s'}
|
elif i < len(sys.argv) and sys.argv[i].isdigit():
|
||||||
|
value = gam.getInteger(sys.argv[i], casedField,
|
||||||
|
minVal=schema['minVal'], maxVal=schema['maxVal'])*schema['scale']
|
||||||
|
i += 1
|
||||||
|
else: # Handle empty value for fields with default
|
||||||
|
value = schema['default']*schema['scale']
|
||||||
|
if i < len(sys.argv) and not sys.argv[i]:
|
||||||
|
i += 1
|
||||||
else:
|
else:
|
||||||
body['requests'][-1]['policyValue']['value'][casedField] = {schema['type']: value}
|
value = utils.get_hhmm(sys.argv[i])
|
||||||
|
i += 1
|
||||||
|
if vtype == 'duration':
|
||||||
|
body['requests'][-1]['policyValue']['value'][casedField] = {vtype: f'{value}s'}
|
||||||
|
elif vtype == 'value':
|
||||||
|
body['requests'][-1]['policyValue']['value'][casedField] = {vtype: value}
|
||||||
|
elif vtype == 'count':
|
||||||
|
body['requests'][-1]['policyValue']['value'][casedField] = value
|
||||||
|
else: ##timeOfDay
|
||||||
|
hours, minutes = value.split(':')
|
||||||
|
body['requests'][-1]['policyValue']['value'][casedField] = {vtype: {'hours': hours, 'minutes': minutes}}
|
||||||
body['requests'][-1]['updateMask'] += f'{casedField},'
|
body['requests'][-1]['updateMask'] += f'{casedField},'
|
||||||
i += 2
|
|
||||||
continue
|
continue
|
||||||
expected_fields = ', '.join(schemas[myarg]['settings'])
|
expected_fields = ', '.join(schemas[myarg]['settings'])
|
||||||
if field not in expected_fields:
|
if field not in expected_fields:
|
||||||
|
@ -254,6 +254,18 @@ def get_delta_time(argstr):
|
|||||||
return deltaTime
|
return deltaTime
|
||||||
|
|
||||||
|
|
||||||
|
def get_hhmm(argstr):
|
||||||
|
argstr = argstr.strip()
|
||||||
|
if argstr:
|
||||||
|
try:
|
||||||
|
dateTime = datetime.datetime.strptime(argstr, HHMM_FORMAT)
|
||||||
|
return argstr
|
||||||
|
except ValueError:
|
||||||
|
controlflow.system_error_exit(
|
||||||
|
2, f'expected a <{HHMM_FORMAT_REQUIRED}>; got {argstr}')
|
||||||
|
controlflow.system_error_exit(2, f'expected a <{HHMM_FORMAT_REQUIRED}>')
|
||||||
|
|
||||||
|
|
||||||
def get_yyyymmdd(argstr, minLen=1, returnTimeStamp=False, returnDateTime=False):
|
def get_yyyymmdd(argstr, minLen=1, returnTimeStamp=False, returnDateTime=False):
|
||||||
argstr = argstr.strip()
|
argstr = argstr.strip()
|
||||||
if argstr:
|
if argstr:
|
||||||
|
@ -1933,6 +1933,9 @@ DELTA_DATE_FORMAT_REQUIRED = '(+|-)<Number>(d|w|y)'
|
|||||||
DELTA_TIME_PATTERN = re.compile(r'^([+-])(\d+)([mhdwy])$')
|
DELTA_TIME_PATTERN = re.compile(r'^([+-])(\d+)([mhdwy])$')
|
||||||
DELTA_TIME_FORMAT_REQUIRED = '(+|-)<Number>(m|h|d|w|y)'
|
DELTA_TIME_FORMAT_REQUIRED = '(+|-)<Number>(m|h|d|w|y)'
|
||||||
|
|
||||||
|
HHMM_FORMAT = '%H:%M'
|
||||||
|
HHMM_FORMAT_REQUIRED = 'hh:mm'
|
||||||
|
|
||||||
YYYYMMDD_FORMAT = '%Y-%m-%d'
|
YYYYMMDD_FORMAT = '%Y-%m-%d'
|
||||||
YYYYMMDD_FORMAT_REQUIRED = 'yyyy-mm-dd'
|
YYYYMMDD_FORMAT_REQUIRED = 'yyyy-mm-dd'
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user