Added option showitemcountonly to gam [<UserTypeEntity>] print|show shareddrives

This commit is contained in:
Ross Scroggs
2025-05-27 13:21:31 -07:00
parent a1216b6782
commit 12f5c5e670
2 changed files with 24 additions and 2 deletions

View File

@@ -1,3 +1,8 @@
7.07.13
Added option `showitemcountonly` to `gam [<UserTypeEntity>] print|show shareddrives` that causes GAM to display the
number of Shared Drives on stdout; no CSV file is written.
7.07.12 7.07.12
Fixed bug in `gam print|show oushareddrives` that caused a trap. Fixed bug in `gam print|show oushareddrives` that caused a trap.

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.07.12' __version__ = '7.07.13'
__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
@@ -59838,6 +59838,7 @@ def copyDriveFile(users):
# Source at root of Shared Drive? # Source at root of Shared Drive?
sourceMimeType = source['mimeType'] sourceMimeType = source['mimeType']
if sourceMimeType == MIMETYPE_GA_FOLDER and source.get('driveId') and source['name'] == TEAM_DRIVE and not source.get('parents', []): if sourceMimeType == MIMETYPE_GA_FOLDER and source.get('driveId') and source['name'] == TEAM_DRIVE and not source.get('parents', []):
copyMoveOptions['sourceIsMyDriveSharedDrive'] = True
source['name'] = _getSharedDriveNameFromId(drive, source['driveId']) source['name'] = _getSharedDriveNameFromId(drive, source['driveId'])
sourceName = source['name'] sourceName = source['name']
sourceNameId = f"{sourceName}({source['id']})" sourceNameId = f"{sourceName}({source['id']})"
@@ -65416,12 +65417,14 @@ SHAREDDRIVE_ACL_ROLES_MAP = {
# (role|roles <SharedDriveACLRoleList>)* # (role|roles <SharedDriveACLRoleList>)*
# [fields <SharedDriveFieldNameList>] [noorgunits [<Boolean>]] # [fields <SharedDriveFieldNameList>] [noorgunits [<Boolean>]]
# [guiroles [<Boolean>]] [formatjson [quotechar <Character>]] # [guiroles [<Boolean>]] [formatjson [quotechar <Character>]]
# [showitemcountonly]
# gam <UserTypeEntity> show shareddrives # gam <UserTypeEntity> show shareddrives
# [asadmin [shareddriveadminquery|query <QuerySharedDrive>]] # [asadmin [shareddriveadminquery|query <QuerySharedDrive>]]
# [matchname <REMatchPattrn>] [orgunit|org|ou <OrgUnitPath>] # [matchname <REMatchPattrn>] [orgunit|org|ou <OrgUnitPath>]
# (role|roles <SharedDriveACLRoleLIst>)* # (role|roles <SharedDriveACLRoleLIst>)*
# [fields <SharedDriveFieldNameList>] [noorgunits [<Boolean>]] # [fields <SharedDriveFieldNameList>] [noorgunits [<Boolean>]]
# [guiroles [<Boolean>]] [formatjson] # [guiroles [<Boolean>]] [formatjson]
# [showitemcountonly]
def printShowSharedDrives(users, useDomainAdminAccess=False): def printShowSharedDrives(users, useDomainAdminAccess=False):
def stripNonShowFields(shareddrive): def stripNonShowFields(shareddrive):
if orgUnitIdToPathMap: if orgUnitIdToPathMap:
@@ -65445,7 +65448,7 @@ def printShowSharedDrives(users, useDomainAdminAccess=False):
SHAREDDRIVE_FIELDS_CHOICE_MAP.update(SHAREDDRIVE_LIST_FIELDS_CHOICE_MAP) SHAREDDRIVE_FIELDS_CHOICE_MAP.update(SHAREDDRIVE_LIST_FIELDS_CHOICE_MAP)
showOrgUnitPaths = True showOrgUnitPaths = True
orgUnitIdToPathMap = None orgUnitIdToPathMap = None
guiRoles = False guiRoles = showItemCountOnly = False
while Cmd.ArgumentsRemaining(): while Cmd.ArgumentsRemaining():
myarg = getArgument() myarg = getArgument()
if csvPF and myarg == 'todrive': if csvPF and myarg == 'todrive':
@@ -65475,6 +65478,9 @@ def printShowSharedDrives(users, useDomainAdminAccess=False):
showOrgUnitPaths = not getBoolean() showOrgUnitPaths = not getBoolean()
elif myarg == 'guiroles': elif myarg == 'guiroles':
guiRoles = getBoolean() guiRoles = getBoolean()
elif myarg == 'showitemcountonly':
showItemCountOnly = True
showOrgUnitPaths = False
else: else:
FJQC.GetFormatJSONQuoteChar(myarg, True) FJQC.GetFormatJSONQuoteChar(myarg, True)
if query and not useDomainAdminAccess: if query and not useDomainAdminAccess:
@@ -65544,6 +65550,9 @@ def printShowSharedDrives(users, useDomainAdminAccess=False):
jcount = len(matchedFeed) jcount = len(matchedFeed)
if jcount == 0: if jcount == 0:
setSysExitRC(NO_ENTITIES_FOUND_RC) setSysExitRC(NO_ENTITIES_FOUND_RC)
if showItemCountOnly:
writeStdout(f'{jcount}\n')
return
if not csvPF: if not csvPF:
if not FJQC.formatJSON: if not FJQC.formatJSON:
entityPerformActionNumItems([Ent.USER, user], jcount, Ent.SHAREDDRIVE, i, count) entityPerformActionNumItems([Ent.USER, user], jcount, Ent.SHAREDDRIVE, i, count)
@@ -65574,9 +65583,11 @@ def doPrintShowSharedDrives():
# gam print oushareddrives [todrive <ToDriveAttribute>*] # gam print oushareddrives [todrive <ToDriveAttribute>*]
# [ou|org|orgunit <OrgUnitPath>] # [ou|org|orgunit <OrgUnitPath>]
# [formatjson [quotechar <Character>]] # [formatjson [quotechar <Character>]]
# [showitemcountonly]
# gam show oushareddrives # gam show oushareddrives
# [ou|org|orgunit <OrgUnitPath>] # [ou|org|orgunit <OrgUnitPath>]
# [formatjson] # [formatjson]
# [showitemcountonly]
def doPrintShowOrgunitSharedDrives(): def doPrintShowOrgunitSharedDrives():
def _getOrgUnitSharedDriveInfo(shareddrive): def _getOrgUnitSharedDriveInfo(shareddrive):
shareddrive['driveId'] = shareddrive['name'].rsplit(';')[1] shareddrive['driveId'] = shareddrive['name'].rsplit(';')[1]
@@ -65605,12 +65616,15 @@ def doPrintShowOrgunitSharedDrives():
csvPF = CSVPrintFile(['name', 'type', 'member', 'memberUri', 'driveId', 'driveName', 'orgUnitPath']) if Act.csvFormat() else None csvPF = CSVPrintFile(['name', 'type', 'member', 'memberUri', 'driveId', 'driveName', 'orgUnitPath']) if Act.csvFormat() else None
FJQC = FormatJSONQuoteChar(csvPF) FJQC = FormatJSONQuoteChar(csvPF)
orgUnitPath = '/' orgUnitPath = '/'
showItemCountOnly = False
while Cmd.ArgumentsRemaining(): while Cmd.ArgumentsRemaining():
myarg = getArgument() myarg = getArgument()
if csvPF and myarg == 'todrive': if csvPF and myarg == 'todrive':
csvPF.GetTodriveParameters() csvPF.GetTodriveParameters()
elif myarg in {'ou', 'org', 'orgunit'}: elif myarg in {'ou', 'org', 'orgunit'}:
orgUnitPath = getString(Cmd.OB_ORGUNIT_ITEM) orgUnitPath = getString(Cmd.OB_ORGUNIT_ITEM)
elif myarg == 'showitemcountonly':
showItemCountOnly = True
else: else:
FJQC.GetFormatJSONQuoteChar(myarg, True) FJQC.GetFormatJSONQuoteChar(myarg, True)
if csvPF and FJQC.formatJSON: if csvPF and FJQC.formatJSON:
@@ -65625,6 +65639,9 @@ def doPrintShowOrgunitSharedDrives():
jcount = len(sds) jcount = len(sds)
if jcount == 0: if jcount == 0:
setSysExitRC(NO_ENTITIES_FOUND_RC) setSysExitRC(NO_ENTITIES_FOUND_RC)
if showItemCountOnly:
writeStdout(f'{jcount}\n')
return
if not csvPF: if not csvPF:
if not FJQC.formatJSON: if not FJQC.formatJSON:
entityPerformActionNumItems([Ent.ORGANIZATIONAL_UNIT, orgUnitPath], jcount, Ent.SHAREDDRIVE) entityPerformActionNumItems([Ent.ORGANIZATIONAL_UNIT, orgUnitPath], jcount, Ent.SHAREDDRIVE)