Added option returnidonly to gam create|update printer

This commit is contained in:
Ross Scroggs
2026-03-01 19:52:51 -08:00
parent 7ab959f27c
commit 28383c1391
4 changed files with 26 additions and 10 deletions

View File

@@ -1102,7 +1102,7 @@ jobs:
echo "printer model count:" echo "printer model count:"
run_gam print printermodels | wc -l run_gam print printermodels | wc -l
run_gam print printers run_gam print printers
printerid=$($gam create printer displayname "${newbase}" uri ipp://localhost:631 driverless description "made by ${gam_user}" ou "${newou}" nodetails | awk '{print substr($2, 1, length($2)-1)}') printerid=$($gam create printer displayname "${newbase}" uri ipp://localhost:631 driverless description "made by ${gam_user}" ou "${newou}" returnIdOnly)
run_gam info printer "$printerid" run_gam info printer "$printerid"
run_gam delete printer "$printerid" run_gam delete printer "$printerid"
run_gam delete ou "${newou}" run_gam delete ou "${newou}"

View File

@@ -4568,8 +4568,8 @@ gam check ou|org <OrgUnitItem> [todrive <ToDriveAttribute>*]
usedriverlessconfig| usedriverlessconfig|
<PrinterFieldNameList> ::= "<PrinterFieldName>(,<PrinterFieldName>)*" <PrinterFieldNameList> ::= "<PrinterFieldName>(,<PrinterFieldName>)*"
gam create printer <PrinterAttribute>+ gam create printer <PrinterAttribute>+ [nodetails|returnidonly]
gam update printer <PrinterID> <PrinterAttribute>+ gam update printer <PrinterID> <PrinterAttribute>+ [nodetails|returnidonly]
gam delete printer gam delete printer
<PrinterIDList>| <PrinterIDList>|
<FileSelector>| <FileSelector>|

View File

@@ -1,3 +1,10 @@
7.34.12
Fixed build errors that prevented Windows zip files from being created.
Added option `returnidonly` to `gam create|update printer` that causes GAM to return just the ID
of the printer.
7.34.11 7.34.11
Updated gam-install.sh script for macOS/Linux to properly config GAM when the answer to the following question is No. Updated gam-install.sh script for macOS/Linux to properly config GAM when the answer to the following question is No.

View File

@@ -25,7 +25,7 @@ https://github.com/GAM-team/GAM/wiki
""" """
__author__ = 'GAM Team <google-apps-manager@googlegroups.com>' __author__ = 'GAM Team <google-apps-manager@googlegroups.com>'
__version__ = '7.34.11' __version__ = '7.34.12'
__license__ = 'Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)' __license__ = 'Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)'
# pylint: disable=wrong-import-position # pylint: disable=wrong-import-position
@@ -31656,6 +31656,7 @@ UPDATE_PRINTER_JSON_SKIP_FIELDS = ['id', 'name', 'createTime', 'orgUnitId', 'org
def _getPrinterAttributes(cd, jsonDeleteFields): def _getPrinterAttributes(cd, jsonDeleteFields):
'''get printer attributes for create/update commands''' '''get printer attributes for create/update commands'''
body = {} body = {}
returnIdOnly = False
showDetails = True showDetails = True
while Cmd.ArgumentsRemaining(): while Cmd.ArgumentsRemaining():
myarg = getArgument() myarg = getArgument()
@@ -31674,13 +31675,15 @@ def _getPrinterAttributes(cd, jsonDeleteFields):
body['useDriverlessConfig'] = getBoolean() body['useDriverlessConfig'] = getBoolean()
elif myarg == 'nodetails': elif myarg == 'nodetails':
showDetails = False showDetails = False
elif myarg == 'returnidonly':
returnIdOnly = True
elif myarg == 'json': elif myarg == 'json':
body.update(getJSON(jsonDeleteFields)) body.update(getJSON(jsonDeleteFields))
else: else:
unknownArgumentExit() unknownArgumentExit()
if body.get('makeAndModel'): if body.get('makeAndModel'):
body.pop('useDriverlessConfig', None) body.pop('useDriverlessConfig', None)
return (body, showDetails) return (body, showDetails, returnIdOnly)
PRINTER_FIELDS_CHOICE_MAP = { PRINTER_FIELDS_CHOICE_MAP = {
'auxiliarymessages': 'auxiliaryMessages', 'auxiliarymessages': 'auxiliaryMessages',
@@ -31726,33 +31729,39 @@ def _showPrinter(cd, printer, FJQC, orgUnitId=None, showInherited=False, i=0, co
showJSON(None, printer, timeObjects=PRINTER_TIME_OBJECTS) showJSON(None, printer, timeObjects=PRINTER_TIME_OBJECTS)
Ind.Decrement() Ind.Decrement()
# gam create printer <PrinterAttribute>+ [nodetails] # gam create printer <PrinterAttribute>+ [nodetails|returnidonly]
def doCreatePrinter(): def doCreatePrinter():
cd = buildGAPIObject(API.DIRECTORY) cd = buildGAPIObject(API.DIRECTORY)
parent = _getCustomersCustomerIdWithC() parent = _getCustomersCustomerIdWithC()
body, showDetails = _getPrinterAttributes(cd, CREATE_PRINTER_JSON_SKIP_FIELDS) body, showDetails, returnIdOnly = _getPrinterAttributes(cd, CREATE_PRINTER_JSON_SKIP_FIELDS)
if not body.get('orgUnitId'): if not body.get('orgUnitId'):
missingArgumentExit('orgunit') missingArgumentExit('orgunit')
try: try:
printer = callGAPI(cd.customers().chrome().printers(), 'create', printer = callGAPI(cd.customers().chrome().printers(), 'create',
throwReasons=[GAPI.INVALID_ARGUMENT, GAPI.PERMISSION_DENIED], throwReasons=[GAPI.INVALID_ARGUMENT, GAPI.PERMISSION_DENIED],
parent=parent, body=body) parent=parent, body=body)
if returnIdOnly:
writeStdout(f"{printer['id']}\n")
return
entityActionPerformed([Ent.PRINTER, printer['id']]) entityActionPerformed([Ent.PRINTER, printer['id']])
if showDetails: if showDetails:
_showPrinter(cd, printer, None) _showPrinter(cd, printer, None)
except (GAPI.invalidArgument, GAPI.permissionDenied) as e: except (GAPI.invalidArgument, GAPI.permissionDenied) as e:
entityActionFailedWarning([Ent.PRINTER, None], str(e)) entityActionFailedWarning([Ent.PRINTER, None], str(e))
# gam update printer <PrinterID> <PrinterAttribute>+ [nodetails] # gam update printer <PrinterID> <PrinterAttribute>+ [nodetails|returnidonly]
def doUpdatePrinter(): def doUpdatePrinter():
name, printerId, cd = _getPrinterID() name, printerId, cd = _getPrinterID()
body, showDetails = _getPrinterAttributes(cd, UPDATE_PRINTER_JSON_SKIP_FIELDS) body, showDetails, returnIdOnly = _getPrinterAttributes(cd, UPDATE_PRINTER_JSON_SKIP_FIELDS)
updateMask = ','.join(list(body.keys())) updateMask = ','.join(list(body.keys()))
# note clearMask seems unnecessary. Updating field to '' clears it. # note clearMask seems unnecessary. Updating field to '' clears it.
try: try:
printer = callGAPI(cd.customers().chrome().printers(), 'patch', printer = callGAPI(cd.customers().chrome().printers(), 'patch',
throwReasons=[GAPI.NOT_FOUND, GAPI.INVALID_ARGUMENT, GAPI.PERMISSION_DENIED], throwReasons=[GAPI.NOT_FOUND, GAPI.INVALID_ARGUMENT, GAPI.PERMISSION_DENIED],
name=name, updateMask=updateMask, body=body) name=name, updateMask=updateMask, body=body)
if returnIdOnly:
writeStdout(f"{printer['id']}\n")
return
entityActionPerformed([Ent.PRINTER, printerId]) entityActionPerformed([Ent.PRINTER, printerId])
if showDetails: if showDetails:
_showPrinter(cd, printer, None) _showPrinter(cd, printer, None)
@@ -71340,7 +71349,7 @@ def updatePhoto(users):
bailOnInternalError=True, bailOnInternalError=True,
throwReasons=[GAPI.USER_NOT_FOUND, GAPI.FORBIDDEN, GAPI.PHOTO_NOT_FOUND, GAPI.INTERNAL_ERROR], throwReasons=[GAPI.USER_NOT_FOUND, GAPI.FORBIDDEN, GAPI.PHOTO_NOT_FOUND, GAPI.INTERNAL_ERROR],
userKey=user) userKey=user)
except (GAPI.photoNotFound, GAPI.internalError) as e: except (GAPI.photoNotFound, GAPI.internalError):
pass pass
callGAPI(cd.users().photos(), 'update', callGAPI(cd.users().photos(), 'update',
throwReasons=[GAPI.USER_NOT_FOUND, GAPI.FORBIDDEN, GAPI.INVALID_INPUT, GAPI.CONDITION_NOT_MET], throwReasons=[GAPI.USER_NOT_FOUND, GAPI.FORBIDDEN, GAPI.INVALID_INPUT, GAPI.CONDITION_NOT_MET],