diff --git a/src/GamCommands.txt b/src/GamCommands.txt index 5a5a30f0..74365c63 100644 --- a/src/GamCommands.txt +++ b/src/GamCommands.txt @@ -209,6 +209,7 @@ If an item contains spaces, it should be surrounded by ". ::= ::= ::= id:||anyone|anyonewithlink + ::= ::= ::= ::= See: https://support.google.com/chrome/a/answer/9681204#retrieve_all_chrome_devices_for_an_account @@ -220,7 +221,6 @@ If an item contains spaces, it should be surrounded by ". ::= See: https://support.google.com/mail/answer/7190 ::= See: https://developers.google.com/admin-sdk/directory/v1/guides/search-groups ::= See: https://support.google.com/a/answer/7549103 - ::= See: https://developers.google.com/cloud-print/docs/appInterfaces#parameters_3 ::= See: https://developers.google.com/admin-sdk/directory/v1/guides/search-users ::= See: https://developers.google.com/vault/reference/rest/v1/matters.holds#CorpusQuery ::= @@ -489,9 +489,6 @@ If an item contains spaces, it should be surrounded by ". description|id|inherit|name|orgunitpath|parent|parentid|inherit ::= "(,)*" - ::= - create_time|status|title - ::= buildingid| capacity| @@ -592,8 +589,8 @@ Items, separated by spaces, with spaces, commas or single quotes in the items th ::= "(,)*" ::= "(,)*" ::= "(,)*" + ::= ")(,)*" ::= "(|SKUID>)(,|SKUID>)*" - ::= "(,)*" ::= "(,)*" ::= "(,)*" ::= "(,)*" @@ -1275,6 +1272,22 @@ gam info mobile gam print mobile [todrive] [(query )|(queries )] [basic|full] [orderby [ascending|descending]] fields ] [delimiter ] [appslimit ] [listlimit ] + ::= + (description )| + (displayname )| + (makeandmodel )| + (ou|org|orgunit|orgunitid )| + (ownerid )| + (uri )| + (driverless|usedriverlessconfig) + +gam create printer + +gam update printer + +gam delete printer |(file )|(csvfile :) + +gam print printers [todrive] [filter ] +gam print printermodels [todrive] [filter ] + gam create cigroup * [makeowner] [alias|aliases ] [dynamic ] gam update cigroup [email ] * [security] @@ -1317,6 +1330,13 @@ gam print group-members|groups-members [todrive] [roles ] [membernames] [fields ] [includederivedmembership] +gam create userinvitation +gam cancel userinvitation +gam check userinvitation +gam info userinvitation +gam print userinvitations [todrive] [filter ] +gam check isinvitable [todrive] + gam print licenses [todrive] [(products|product )|(skus|sku )|allskus|gsuite] [countsonly] gam show license|licenses|licence|licences [(products|product )|(skus|sku )|allskus|gsuite] diff --git a/src/gam/__init__.py b/src/gam/__init__.py index 181e7f0d..02d40c7a 100755 --- a/src/gam/__init__.py +++ b/src/gam/__init__.py @@ -7863,7 +7863,7 @@ def doCreateOrRotateServiceAccountKeys(iam=None, # Ask Google to generate private key, store locally result = gapi.call(iam.projects().serviceAccounts().keys(), 'create', - name=name, + name=sa_name, body=body) new_data_str = base64.b64decode( result['privateKeyData']).decode(UTF8) @@ -11990,8 +11990,6 @@ def ProcessGAMCommand(args): gapi_directory_users.turn_off_2sv(users) elif command == 'waitformailbox': gapi_directory_users.wait_for_mailbox(users) - elif command == 'deleteprinters': - gapi_directory_printers.batch_delete(users) else: controlflow.invalid_argument_exit(command, 'gam') except IndexError: diff --git a/src/gam/gapi/directory/printers.py b/src/gam/gapi/directory/printers.py index ae887c9c..ee2fe109 100644 --- a/src/gam/gapi/directory/printers.py +++ b/src/gam/gapi/directory/printers.py @@ -1,9 +1,12 @@ '''Commands to manage directory printers.''' # pylint: disable=unused-wildcard-import wildcard-import +import sys + from gam import controlflow from gam import display from gam import gapi +from gam import getUsersToModify from gam.var import * from gam.gapi import directory as gapi_directory from gam.gapi.directory import orgunits as gapi_directory_orgunits @@ -30,39 +33,19 @@ def _get_printer_attributes(i, cdapi=None): elif myarg == 'makeandmodel': body['makeAndModel'] = sys.argv[i+1] i += 2 - elif myarg in ['ou', 'orgunit']: + elif myarg in ['ou', 'org', 'orgunit', 'orgunitid']: _, body['orgUnitId'] = gapi_directory_orgunits.getOrgUnitId(sys.argv[i+1], cdapi) body['orgUnitId'] = body['orgUnitId'][3:] i += 2 elif myarg == 'uri': body['uri'] = sys.argv[i+1] i += 2 - elif myarg == 'driverless': + elif myarg in {'driverless', 'usedriverlessconfig'}: body['useDriverlessConfig'] = True i += 1 return body -def batch_delete(printer_ids): - '''gam croscsvfile file:column deleteprinters''' - cdapi = gapi_directory.build() - parent = _get_customerid() - # max 50 per API call - batch_size = 50 - for chunk in range(0, len(printer_ids), batch_size): - body = { - 'printerIds': printer_ids[chunk:chunk + batch_size] - } - result = gapi.call(cdapi.customers().chrome().printers(), - 'batchDeletePrinters', - parent=parent, - body=body) - for printer_id in result.get('printerIds', []): - print(f'Deleted printer {printer_id}') - for printer_id in result.get('failedPrinters', []): - print(f'ERROR: failed to delete {printer_id.get("printerIds")}') - - def create(): '''gam create printer''' cdapi = gapi_directory.build() @@ -76,15 +59,28 @@ def create(): def delete(): - '''gam delete printer''' + '''gam delete printer |(file )|(csvfile :)''' cdapi = gapi_directory.build() customer_id = _get_customerid() printer_id = sys.argv[3] - name = f'{customer_id}/chrome/printers/{printer_id}' - gapi.call(cdapi.customers().chrome().printers(), - 'delete', - name=name) - print(f'Deleted printer {printer_id}') + if printer_id.lower() not in {'file', 'csvfile'}: + printer_ids = printer_id.replace(',', ' ').split() + else: + printer_ids = getUsersToModify(f'cros{printer_id.lower()}', sys.argv[4]) + # max 50 per API call + batch_size = 50 + for chunk in range(0, len(printer_ids), batch_size): + body = { + 'printerIds': printer_ids[chunk:chunk + batch_size] + } + result = gapi.call(cdapi.customers().chrome().printers(), + 'batchDeletePrinters', + parent=customer_id, + body=body) + for printer_id in result.get('printerIds', []): + print(f'Deleted printer {printer_id}') + for printer_id in result.get('failedPrinters', []): + print(f'ERROR: failed to delete {printer_id.get("printerIds")}') def print_(): '''gam print printers'''