mirror of
https://github.com/GAM-team/GAM.git
synced 2025-07-10 22:53:34 +00:00
Various small cleanups (#1332)
This commit is contained in:
@ -17,7 +17,7 @@ from gam import utils
|
|||||||
def _get_customerid():
|
def _get_customerid():
|
||||||
''' returns customer id without C prefix'''
|
''' returns customer id without C prefix'''
|
||||||
customer_id = GC_Values[GC_CUSTOMER_ID]
|
customer_id = GC_Values[GC_CUSTOMER_ID]
|
||||||
if customer_id != MY_CUSTOMER and customer_id[0] == 'C':
|
if customer_id[0] == 'C':
|
||||||
customer_id = customer_id[1:]
|
customer_id = customer_id[1:]
|
||||||
return customer_id
|
return customer_id
|
||||||
|
|
||||||
|
@ -1,14 +1,11 @@
|
|||||||
"""Chrome Browser Cloud Management API calls"""
|
"""Chrome Browser Cloud Management API calls"""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import os.path
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import gam
|
import gam
|
||||||
from gam.var import *
|
from gam.var import *
|
||||||
from gam import controlflow
|
from gam import controlflow
|
||||||
from gam import display
|
|
||||||
from gam import fileutils
|
|
||||||
from gam import gapi
|
from gam import gapi
|
||||||
from gam.gapi import errors as gapi_errors
|
from gam.gapi import errors as gapi_errors
|
||||||
from gam.gapi.directory import orgunits as gapi_directory_orgunits
|
from gam.gapi.directory import orgunits as gapi_directory_orgunits
|
||||||
@ -56,7 +53,6 @@ def print_policies():
|
|||||||
body = {
|
body = {
|
||||||
'policyTargetKey': {
|
'policyTargetKey': {
|
||||||
'targetResource': orgunit,
|
'targetResource': orgunit,
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw_reasons = [gapi_errors.ErrorReason.FOUR_O_O,]
|
throw_reasons = [gapi_errors.ErrorReason.FOUR_O_O,]
|
||||||
@ -68,7 +64,7 @@ def print_policies():
|
|||||||
throw_reasons=throw_reasons,
|
throw_reasons=throw_reasons,
|
||||||
customer=customer,
|
customer=customer,
|
||||||
body=body)
|
body=body)
|
||||||
except googleapiclient.errors.HttpError as err:
|
except googleapiclient.errors.HttpError:
|
||||||
policies = []
|
policies = []
|
||||||
for policy in policies:
|
for policy in policies:
|
||||||
#print(json.dumps(policy, indent=2))
|
#print(json.dumps(policy, indent=2))
|
||||||
@ -77,7 +73,7 @@ def print_policies():
|
|||||||
print(name)
|
print(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():
|
||||||
if type(value) is str and value.find('_ENUM_') != -1:
|
if isinstance(value, str) and value.find('_ENUM_') != -1:
|
||||||
value = value.split('_ENUM_')[-1]
|
value = value.split('_ENUM_')[-1]
|
||||||
print(f' {setting}: {value}')
|
print(f' {setting}: {value}')
|
||||||
print()
|
print()
|
||||||
@ -156,11 +152,11 @@ def print_schemas():
|
|||||||
elif vtype == 'TYPE_BOOL':
|
elif vtype == 'TYPE_BOOL':
|
||||||
pvs = v.get('descriptions')
|
pvs = v.get('descriptions')
|
||||||
for pv in pvs:
|
for pv in pvs:
|
||||||
if type(pv) is dict:
|
if isinstance(pv, dict):
|
||||||
pvalue = pv.get('value')
|
pvalue = pv.get('value')
|
||||||
pdescription = pv.get('description')
|
pdescription = pv.get('description')
|
||||||
print(f' {pvalue} - {pdescription}')
|
print(f' {pvalue} - {pdescription}')
|
||||||
elif type(pv) is list:
|
elif isinstance(pv, list):
|
||||||
print(f' {pv[0]}')
|
print(f' {pv[0]}')
|
||||||
else:
|
else:
|
||||||
print(f' {v.get("descriptions")[0]}')
|
print(f' {v.get("descriptions")[0]}')
|
||||||
@ -212,7 +208,7 @@ def update_policy():
|
|||||||
field = sys.argv[i].lower()
|
field = sys.argv[i].lower()
|
||||||
if field == 'orgunit' or '.' in field:
|
if field == 'orgunit' or '.' in field:
|
||||||
break # field is actually a new policy name or orgunit
|
break # field is actually a new policy name or orgunit
|
||||||
expected_fields = ', '.join([setting for setting in schemas[myarg].settings])
|
expected_fields = ', '.join(schemas[myarg].settings)
|
||||||
if field not in expected_fields:
|
if field not in expected_fields:
|
||||||
controlflow.system_error_exit(4, f'Expected {myarg} field of {expected_fields}. Got {field}.')
|
controlflow.system_error_exit(4, f'Expected {myarg} field of {expected_fields}. Got {field}.')
|
||||||
value = sys.argv[i+1]
|
value = sys.argv[i+1]
|
||||||
@ -243,4 +239,3 @@ def update_policy():
|
|||||||
for request in body['requests']:
|
for request in body['requests']:
|
||||||
request['policyTargetKey'] = {'targetResource': orgunit}
|
request['policyTargetKey'] = {'targetResource': orgunit}
|
||||||
gapi.call(cp.customers().policies().orgunits(), 'batchModify', customer=customer, body=body)
|
gapi.call(cp.customers().policies().orgunits(), 'batchModify', customer=customer, body=body)
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ def print_():
|
|||||||
titles.append(key)
|
titles.append(key)
|
||||||
row[key] = val
|
row[key] = val
|
||||||
rows.append(row)
|
rows.append(row)
|
||||||
display.write_csv_file(rows, titles, 'Printer', todrive)
|
display.write_csv_file(rows, titles, 'Printers', todrive)
|
||||||
|
|
||||||
|
|
||||||
def print_models():
|
def print_models():
|
||||||
|
Reference in New Issue
Block a user