Skip to content

Commit

Permalink
Added command gam print addresses [todrive <ToDriveAttribute>*]
Browse files Browse the repository at this point in the history
  • Loading branch information
taers232c committed Mar 29, 2021
1 parent f2a993a commit 7e4cca3
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/GamUpdate.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
6.00.06

Added command `gam print addresses [todrive <ToDriveAttribute>*]` that produces a
two column CSV file (headers Type, Email) that displays all group and user primary
email addresses and aliases. The types are: Group, GroupAlias, GroupNEAlias,
SuspendedUser, User, UserAlias, UserNEAlias. 'NE' is and abbreviation for NonEditable.

6.00.05

Fixed bug in `gam print vaultcounts ... everyone` which caused the following error:
Expand Down
53 changes: 51 additions & 2 deletions src/gam/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"""

__author__ = 'Ross Scroggs <[email protected]>'
__version__ = '6.00.05'
__version__ = '6.00.06'
__license__ = 'Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)'

import base64
Expand Down Expand Up @@ -13769,6 +13769,54 @@ def doPrintAliases():
csvPF.WriteRow({'NonEditableAlias': alias, 'Target': group['email'], 'TargetType': 'Group'})
csvPF.writeCSVfile('Aliases')

# gam print addresses [todrive <ToDriveAttribute>*]
def doPrintAddresses():
cd = buildGAPIObject(API.DIRECTORY)
csvPF = CSVPrintFile()
titlesList = ['Type', 'Email']
userFields = ['primaryEmail', 'aliases', 'suspended']
groupFields = ['email', 'aliases']
while Cmd.ArgumentsRemaining():
myarg = getArgument()
if myarg == 'todrive':
csvPF.GetTodriveParameters()
else:
unknownArgumentExit()
csvPF.SetTitles(titlesList)
printGettingAllAccountEntities(Ent.USER)
try:
entityList = callGAPIpages(cd.users(), 'list', 'users',
pageMessage=getPageMessage(showFirstLastItems=True), messageAttribute='primaryEmail',
throwReasons=[GAPI.RESOURCE_NOT_FOUND, GAPI.FORBIDDEN, GAPI.BAD_REQUEST],
customer=GC.Values[GC.CUSTOMER_ID], orderBy='email',
fields=f'nextPageToken,users({",".join(userFields)})',
maxResults=GC.Values[GC.USER_MAX_RESULTS])
except (GAPI.resourceNotFound, GAPI.forbidden, GAPI.badRequest):
accessErrorExit(cd)
for user in entityList:
csvPF.WriteRow({'Type': 'User' if not user['suspended'] else 'SuspendedUser', 'Email': user['primaryEmail']})
for alias in user.get('aliases', []):
csvPF.WriteRow({'Type': 'UserAlias', 'Email': alias})
for alias in user.get('nonEditableAliases', []):
csvPF.WriteRow({'Type': 'UserNEAlias', 'Email': alias})
printGettingAllAccountEntities(Ent.GROUP)
try:
entityList = callGAPIpages(cd.groups(), 'list', 'groups',
pageMessage=getPageMessage(showFirstLastItems=True), messageAttribute='email',
throwReasons=GAPI.GROUP_LIST_THROW_REASONS,
customer=GC.Values[GC.CUSTOMER_ID], orderBy='email',
fields=f'nextPageToken,groups({",".join(groupFields)})')
except (GAPI.resourceNotFound, GAPI.domainNotFound, GAPI.forbidden, GAPI.badRequest):
accessErrorExit(cd)
for group in entityList:
csvPF.WriteRow({'Type': 'Group', 'Email': group['email']})
for alias in group.get('aliases', []):
csvPF.WriteRow({'Type': 'GroupAlias', 'Email': alias})
for alias in group.get('nonEditableAliases', []):
csvPF.WriteRow({'Type': 'GroupNEAlias', 'Email': alias})
csvPF.SortRowsTwoTitles('Type', 'Email', False)
csvPF.writeCSVfile('Addresses')

# Contact commands utilities
#
CONTACT_JSON = 'JSON'
Expand Down Expand Up @@ -51428,7 +51476,8 @@ def _printVacation(user, result, showDisabled):
),
'print':
(Act.PRINT,
{Cmd.ARG_ADMINROLE: doPrintShowAdminRoles,
{Cmd.ARG_ADDRESSES: doPrintAddresses,
Cmd.ARG_ADMINROLE: doPrintShowAdminRoles,
Cmd.ARG_ADMIN: doPrintShowAdmins,
Cmd.ARG_ALERT: doPrintShowAlerts,
Cmd.ARG_ALERTFEEDBACK: doPrintShowAlertFeedback,
Expand Down
1 change: 1 addition & 0 deletions src/gam/gamlib/glclargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ class GamCLArgs():
ARG_3LO = '3lo'
ARG_ACL = 'acl'
ARG_ACLS = 'acls'
ARG_ADDRESSES = 'addresses'
ARG_ADMIN = 'admin'
ARG_ADMINS = 'admins'
ARG_ADMINROLE = 'adminrole'
Expand Down

0 comments on commit 7e4cca3

Please sign in to comment.