mirror of
https://github.com/GAM-team/GAM.git
synced 2026-07-04 04:41:35 +00:00
Clean up printer commands/documentation (#1330)
* Clean up printer commands/documentation driverless has to take value so it can be changed from true to false Drop separate deleteprinters command, merge into delete printers * Printer delete update Allow a list of printer IDs Drop cros from crosfile and croscsvfile to avoid confusion; add cros back when calling getUsersToModify
This commit is contained in:
@@ -209,6 +209,7 @@ If an item contains spaces, it should be surrounded by ".
|
|||||||
<ParameterValue> ::= <String>
|
<ParameterValue> ::= <String>
|
||||||
<Password> ::= <String>
|
<Password> ::= <String>
|
||||||
<PermissionID> ::= id:<String>|<EmailAddress>|anyone|anyonewithlink
|
<PermissionID> ::= id:<String>|<EmailAddress>|anyone|anyonewithlink
|
||||||
|
<PrinterID> ::= <String>
|
||||||
<PropertyKey> ::= <String>
|
<PropertyKey> ::= <String>
|
||||||
<PropertyValue> ::= <String>
|
<PropertyValue> ::= <String>
|
||||||
<QueryBrowser> ::= <String> See: https://support.google.com/chrome/a/answer/9681204#retrieve_all_chrome_devices_for_an_account
|
<QueryBrowser> ::= <String> 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 ".
|
|||||||
<QueryGmail> ::= <String> See: https://support.google.com/mail/answer/7190
|
<QueryGmail> ::= <String> See: https://support.google.com/mail/answer/7190
|
||||||
<QueryGroup> ::= <String> See: https://developers.google.com/admin-sdk/directory/v1/guides/search-groups
|
<QueryGroup> ::= <String> See: https://developers.google.com/admin-sdk/directory/v1/guides/search-groups
|
||||||
<QueryMobile> ::= <String> See: https://support.google.com/a/answer/7549103
|
<QueryMobile> ::= <String> See: https://support.google.com/a/answer/7549103
|
||||||
<QueryPrintJob> ::= <String> See: https://developers.google.com/cloud-print/docs/appInterfaces#parameters_3
|
|
||||||
<QueryUser> ::= <String> See: https://developers.google.com/admin-sdk/directory/v1/guides/search-users
|
<QueryUser> ::= <String> See: https://developers.google.com/admin-sdk/directory/v1/guides/search-users
|
||||||
<QueryVaultCorpus> ::= <String> See: https://developers.google.com/vault/reference/rest/v1/matters.holds#CorpusQuery
|
<QueryVaultCorpus> ::= <String> See: https://developers.google.com/vault/reference/rest/v1/matters.holds#CorpusQuery
|
||||||
<RequestID> ::= <String>
|
<RequestID> ::= <String>
|
||||||
@@ -489,9 +489,6 @@ If an item contains spaces, it should be surrounded by ".
|
|||||||
description|id|inherit|name|orgunitpath|parent|parentid|inherit
|
description|id|inherit|name|orgunitpath|parent|parentid|inherit
|
||||||
<OrgUnitFieldNameList> ::= "<OrgUnitFieldName>(,<OrgUnitFieldName>)*"
|
<OrgUnitFieldNameList> ::= "<OrgUnitFieldName>(,<OrgUnitFieldName>)*"
|
||||||
|
|
||||||
<PrintJobOrderByFieldName> ::=
|
|
||||||
create_time|status|title
|
|
||||||
|
|
||||||
<ResourceFieldName> ::=
|
<ResourceFieldName> ::=
|
||||||
buildingid|
|
buildingid|
|
||||||
capacity|
|
capacity|
|
||||||
@@ -592,8 +589,8 @@ Items, separated by spaces, with spaces, commas or single quotes in the items th
|
|||||||
<MembersFieldNameList> ::= "<MembersFieldName>(,<MembersFieldName>)*"
|
<MembersFieldNameList> ::= "<MembersFieldName>(,<MembersFieldName>)*"
|
||||||
<MobileList> ::= "<MobileId>(,<MobileId>)*"
|
<MobileList> ::= "<MobileId>(,<MobileId>)*"
|
||||||
<OrgUnitList> ::= "<OrgUnitPath>(,<OrgUnitPath>)*"
|
<OrgUnitList> ::= "<OrgUnitPath>(,<OrgUnitPath>)*"
|
||||||
|
<PrinterIDList> ::= "<PrinterID>)(,<PrinterID>)*"
|
||||||
<ProductIDList> ::= "(<ProductID>|SKUID>)(,<ProductID>|SKUID>)*"
|
<ProductIDList> ::= "(<ProductID>|SKUID>)(,<ProductID>|SKUID>)*"
|
||||||
<PrintJobIDList> ::= "<PrintJobID>(,<PrintJobID>)*"
|
|
||||||
<QueryCrOSList> ::= "<QueryCrOS>(,<QueryCrOS>)*"
|
<QueryCrOSList> ::= "<QueryCrOS>(,<QueryCrOS>)*"
|
||||||
<QueryMobileList> ::= "<QueryMobile>(,<QueryMobile>)*"
|
<QueryMobileList> ::= "<QueryMobile>(,<QueryMobile>)*"
|
||||||
<QueryUserList> ::= "<QueryUser>(,<QueryUser>)*"
|
<QueryUserList> ::= "<QueryUser>(,<QueryUser>)*"
|
||||||
@@ -1275,6 +1272,22 @@ gam info mobile <MobileID>
|
|||||||
gam print mobile [todrive] [(query <QueryMobile>)|(queries <QueryMobileList>)] [basic|full] [orderby <MobileOrderByFieldName> [ascending|descending]]
|
gam print mobile [todrive] [(query <QueryMobile>)|(queries <QueryMobileList>)] [basic|full] [orderby <MobileOrderByFieldName> [ascending|descending]]
|
||||||
fields <MobileFieldNameList>] [delimiter <Character>] [appslimit <Number>] [listlimit <Number>]
|
fields <MobileFieldNameList>] [delimiter <Character>] [appslimit <Number>] [listlimit <Number>]
|
||||||
|
|
||||||
|
<PrinterAttribute> ::=
|
||||||
|
(description <String>)|
|
||||||
|
(displayname <String>)|
|
||||||
|
(makeandmodel <String>)|
|
||||||
|
(ou|org|orgunit|orgunitid <OrgUnitItem>)|
|
||||||
|
(ownerid <EmailAddress>)|
|
||||||
|
(uri <String>)|
|
||||||
|
(driverless|usedriverlessconfig)
|
||||||
|
|
||||||
|
gam create printer <PrinterAttribute>+
|
||||||
|
gam update printer <PrinterID> <PrinterAttribute>+
|
||||||
|
gam delete printer <PrinterIDList>|(file <FileName>)|(csvfile <FileName>:<FieldName>)
|
||||||
|
|
||||||
|
gam print printers [todrive] [filter <String>]
|
||||||
|
gam print printermodels [todrive] [filter <String>]
|
||||||
|
|
||||||
gam create cigroup <EmailAddress> <CIGroupAttribute>*
|
gam create cigroup <EmailAddress> <CIGroupAttribute>*
|
||||||
[makeowner] [alias|aliases <AliasList>] [dynamic <QueryDynamicGroup>]
|
[makeowner] [alias|aliases <AliasList>] [dynamic <QueryDynamicGroup>]
|
||||||
gam update cigroup <GroupItem> [email <EmailAddress>] <CIGroupAttribute>* [security]
|
gam update cigroup <GroupItem> [email <EmailAddress>] <CIGroupAttribute>* [security]
|
||||||
@@ -1317,6 +1330,13 @@ gam print group-members|groups-members [todrive]
|
|||||||
[roles <GroupRoleList>] [membernames] [fields <MembersFieldNameList>]
|
[roles <GroupRoleList>] [membernames] [fields <MembersFieldNameList>]
|
||||||
[includederivedmembership]
|
[includederivedmembership]
|
||||||
|
|
||||||
|
gam create userinvitation <EmailAddress>
|
||||||
|
gam cancel userinvitation <EmailAddress>
|
||||||
|
gam check userinvitation <EmailAddress>
|
||||||
|
gam info userinvitation <EmailAddress>
|
||||||
|
gam print userinvitations [todrive] [filter <String>]
|
||||||
|
gam <UserTypeEntity> check isinvitable [todrive]
|
||||||
|
|
||||||
gam print licenses [todrive] [(products|product <ProductIDList>)|(skus|sku <SKUIDList>)|allskus|gsuite] [countsonly]
|
gam print licenses [todrive] [(products|product <ProductIDList>)|(skus|sku <SKUIDList>)|allskus|gsuite] [countsonly]
|
||||||
gam show license|licenses|licence|licences [(products|product <ProductIDList>)|(skus|sku <SKUIDList>)|allskus|gsuite]
|
gam show license|licenses|licence|licences [(products|product <ProductIDList>)|(skus|sku <SKUIDList>)|allskus|gsuite]
|
||||||
|
|
||||||
|
|||||||
@@ -7863,7 +7863,7 @@ def doCreateOrRotateServiceAccountKeys(iam=None,
|
|||||||
# Ask Google to generate private key, store locally
|
# Ask Google to generate private key, store locally
|
||||||
result = gapi.call(iam.projects().serviceAccounts().keys(),
|
result = gapi.call(iam.projects().serviceAccounts().keys(),
|
||||||
'create',
|
'create',
|
||||||
name=name,
|
name=sa_name,
|
||||||
body=body)
|
body=body)
|
||||||
new_data_str = base64.b64decode(
|
new_data_str = base64.b64decode(
|
||||||
result['privateKeyData']).decode(UTF8)
|
result['privateKeyData']).decode(UTF8)
|
||||||
@@ -11990,8 +11990,6 @@ def ProcessGAMCommand(args):
|
|||||||
gapi_directory_users.turn_off_2sv(users)
|
gapi_directory_users.turn_off_2sv(users)
|
||||||
elif command == 'waitformailbox':
|
elif command == 'waitformailbox':
|
||||||
gapi_directory_users.wait_for_mailbox(users)
|
gapi_directory_users.wait_for_mailbox(users)
|
||||||
elif command == 'deleteprinters':
|
|
||||||
gapi_directory_printers.batch_delete(users)
|
|
||||||
else:
|
else:
|
||||||
controlflow.invalid_argument_exit(command, 'gam')
|
controlflow.invalid_argument_exit(command, 'gam')
|
||||||
except IndexError:
|
except IndexError:
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
'''Commands to manage directory printers.'''
|
'''Commands to manage directory printers.'''
|
||||||
# pylint: disable=unused-wildcard-import wildcard-import
|
# pylint: disable=unused-wildcard-import wildcard-import
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
from gam import controlflow
|
from gam import controlflow
|
||||||
from gam import display
|
from gam import display
|
||||||
from gam import gapi
|
from gam import gapi
|
||||||
|
from gam import getUsersToModify
|
||||||
from gam.var import *
|
from gam.var import *
|
||||||
from gam.gapi import directory as gapi_directory
|
from gam.gapi import directory as gapi_directory
|
||||||
from gam.gapi.directory import orgunits as gapi_directory_orgunits
|
from gam.gapi.directory import orgunits as gapi_directory_orgunits
|
||||||
@@ -30,39 +33,19 @@ def _get_printer_attributes(i, cdapi=None):
|
|||||||
elif myarg == 'makeandmodel':
|
elif myarg == 'makeandmodel':
|
||||||
body['makeAndModel'] = sys.argv[i+1]
|
body['makeAndModel'] = sys.argv[i+1]
|
||||||
i += 2
|
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'] = gapi_directory_orgunits.getOrgUnitId(sys.argv[i+1], cdapi)
|
||||||
body['orgUnitId'] = body['orgUnitId'][3:]
|
body['orgUnitId'] = body['orgUnitId'][3:]
|
||||||
i += 2
|
i += 2
|
||||||
elif myarg == 'uri':
|
elif myarg == 'uri':
|
||||||
body['uri'] = sys.argv[i+1]
|
body['uri'] = sys.argv[i+1]
|
||||||
i += 2
|
i += 2
|
||||||
elif myarg == 'driverless':
|
elif myarg in {'driverless', 'usedriverlessconfig'}:
|
||||||
body['useDriverlessConfig'] = True
|
body['useDriverlessConfig'] = True
|
||||||
i += 1
|
i += 1
|
||||||
return body
|
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():
|
def create():
|
||||||
'''gam create printer'''
|
'''gam create printer'''
|
||||||
cdapi = gapi_directory.build()
|
cdapi = gapi_directory.build()
|
||||||
@@ -76,15 +59,28 @@ def create():
|
|||||||
|
|
||||||
|
|
||||||
def delete():
|
def delete():
|
||||||
'''gam delete printer'''
|
'''gam delete printer <PrinterIDList>|(file <FileName>)|(csvfile <FileName>:<FieldName>)'''
|
||||||
cdapi = gapi_directory.build()
|
cdapi = gapi_directory.build()
|
||||||
customer_id = _get_customerid()
|
customer_id = _get_customerid()
|
||||||
printer_id = sys.argv[3]
|
printer_id = sys.argv[3]
|
||||||
name = f'{customer_id}/chrome/printers/{printer_id}'
|
if printer_id.lower() not in {'file', 'csvfile'}:
|
||||||
gapi.call(cdapi.customers().chrome().printers(),
|
printer_ids = printer_id.replace(',', ' ').split()
|
||||||
'delete',
|
else:
|
||||||
name=name)
|
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}')
|
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_():
|
def print_():
|
||||||
'''gam print printers'''
|
'''gam print printers'''
|
||||||
|
|||||||
Reference in New Issue
Block a user