From e9c18d0c01d6586ec134650eff028e0bf27862b9 Mon Sep 17 00:00:00 2001 From: Ross Scroggs Date: Mon, 7 Dec 2020 06:38:05 -0800 Subject: [PATCH] Add info deviceuserstate (#1290) * Fix typos in update deviceuserstate documentation * Add info deviceuserstate * Update info/update deviceusertstate documentation * Update devices.py --- src/GamCommands.txt | 25 +++++++------- src/gam/__init__.py | 2 ++ src/gam/gapi/cloudidentity/devices.py | 50 ++++++++++++++++++++------- 3 files changed, 53 insertions(+), 24 deletions(-) diff --git a/src/GamCommands.txt b/src/GamCommands.txt index fbe72f8c..b65b630c 100644 --- a/src/GamCommands.txt +++ b/src/GamCommands.txt @@ -1154,18 +1154,6 @@ gam info device [id] gam delete device [id] gam cancelwipe device [id] gam wipe device [id] - -gam approve deviceuser [id] -gam block deviceuser [id] -gam delete deviceuser [id] -gam cancelwipe deviceuser [id] -gam wipe deviceuser [id] -gam update deviceuserstate [id] - [clientid ] [customid ] [assettags clear|] - [compliantstate|compliancestate compliant|noncompliant] [managedstate clear|managed|unmanaged] - [healthscore verypoor|poor|neutral|good|verygood] [scorereason clear|] - (customvalue (bool )|(number )|(string ))* - gam print devices [todrive] [filter|query ] [orderby [ascending|descending]] [company|personal|nocompanydevices|nopersonaldevices] @@ -1178,6 +1166,19 @@ gam sync devices [filter|query ] [unassigned_missing_action delete|wipe|donothing] [assigned_missing_action delete|wipe|donothing] +gam approve deviceuser [id] +gam block deviceuser [id] +gam delete deviceuser [id] +gam cancelwipe deviceuser [id] +gam wipe deviceuser [id] + +gam info deviceuserstate [id] [clientid ] +gam update deviceuserstate [id] [clientid ] + [customid ] [assettags clear|] + [compliantstate|compliancestate compliant|noncompliant] [managedstate clear|managed|unmanaged] + [healthscore very_poor|poor|neutral|good|very_good] [scorereason clear|] + (customvalue (bool )|(number )|(string ))* + gam update mobile |query: action [doit] [if_users|match_users ] gam delete mobile gam info mobile diff --git a/src/gam/__init__.py b/src/gam/__init__.py index fb9e6034..1ece8a89 100755 --- a/src/gam/__init__.py +++ b/src/gam/__init__.py @@ -11225,6 +11225,8 @@ def ProcessGAMCommand(args): gapi_directory_resource.getBuildingInfo() elif argument in ['device']: gapi_cloudidentity_devices.info() + elif argument == 'deviceuserstate': + gapi_cloudidentity_devices.info_state() elif argument in ['browser', 'browsers']: gapi_cbcm.info() else: diff --git a/src/gam/gapi/cloudidentity/devices.py b/src/gam/gapi/cloudidentity/devices.py index 3af096b0..63985233 100644 --- a/src/gam/gapi/cloudidentity/devices.py +++ b/src/gam/gapi/cloudidentity/devices.py @@ -128,22 +128,48 @@ def wipe_user(): _generic_action('wipe', True) -def update_state(): +def _get_deviceuser_name(): + i = 3 + name = sys.argv[i] + if name == 'id': + i += 1 + name = sys.argv[i] + if not name.startswith('devices/'): + name = f'devices/{name}' + return (i+1, name) + +def info_state(): ci = gapi_cloudidentity.build_dwd() gapi_directory_customer.setTrueCustomerId() - customer = _get_device_customerid()[10:] - client_id = f'{customer}-gam' - body = {} - i = 3 - deviceuser = sys.argv[i] - if deviceuser == 'id': - i += 1 - deviceuser = sys.argv[i] - i += 1 + customer = _get_device_customerid() + customer_id = customer[10:] + client_id = f'{customer_id}-gam' + i, deviceuser = _get_deviceuser_name() while i < len(sys.argv): myarg = sys.argv[i].lower().replace('_', '') if myarg == 'clientid': - client_id = f'{customer}-{sys.argv[i+1]}' + client_id = f'{customer_id}-{sys.argv[i+1]}' + i += 2 + else: + controlflow.invalid_argument_exit(sys.argv[i], 'gam info deviceuserstate') + name = f'{deviceuser}/clientStates/{client_id}' + result = gapi.call(ci.devices().deviceUsers().clientStates(), 'get', + name=name, customer=customer) + display.print_json(result) + + +def update_state(): + ci = gapi_cloudidentity.build_dwd() + gapi_directory_customer.setTrueCustomerId() + customer = _get_device_customerid() + customer_id = customer[10:] + client_id = f'{customer_id}-gam' + body = {} + i, deviceuser = _get_deviceuser_name() + while i < len(sys.argv): + myarg = sys.argv[i].lower().replace('_', '') + if myarg == 'clientid': + client_id = f'{customer_id}-{sys.argv[i+1]}' i += 2 elif myarg in ['assettag', 'assettags']: body['assetTags'] = gam.shlexSplitList(sys.argv[i+1]) @@ -212,7 +238,7 @@ def update_state(): name = f'{deviceuser}/clientStates/{client_id}' updateMask = ','.join(body.keys()) result = gapi.call(ci.devices().deviceUsers().clientStates(), 'patch', - name=name, customer=f'customers/{customer}', updateMask=updateMask, body=body) + name=name, customer=customer, updateMask=updateMask, body=body) display.print_json(result)