mirror of
https://github.com/GAM-team/GAM.git
synced 2026-06-28 09:51:36 +00:00
Improve error handling when invalid report is entered (#1094)
* Improve error handling when invalid report is entered * Add chat to report list * Use discovery document * This will work * Fix formatting * These aren't necessary * Yes, these are necessary because the user may enter the version without _ and gam has has to add it back
This commit is contained in:
@@ -880,6 +880,25 @@ gam update resoldsubscription <CustomerID> <SKUID>
|
||||
gam delete resoldsubscription <CustomerID> <SKUID> cancel|downgrade|transfer_to_direct
|
||||
gam info resoldsubscriptions <CustomerID> [customer_auth_token <String>]
|
||||
|
||||
<ActivityApplicationName> ::=
|
||||
access|accesstransparency|
|
||||
admin|
|
||||
calendar|calendars|
|
||||
chat|
|
||||
drive|doc|docs|
|
||||
enterprisegroups|groupsenterprise|
|
||||
gcp|
|
||||
google+|gplus|
|
||||
group|groups|
|
||||
hangoutsmeet|meet|
|
||||
jamboard|
|
||||
login|logins|
|
||||
mobile|
|
||||
oauthtoken|token|tokens|
|
||||
rules|
|
||||
saml|
|
||||
useraccounts
|
||||
|
||||
<ReportsApp> ::=
|
||||
accounts|
|
||||
app_maker|
|
||||
@@ -899,7 +918,7 @@ gam report users|user [todrive] [date <Date>] [fulldatarequired all|<ReportsAppL
|
||||
[(user <UserItem>)|(orgunit|org|ou <OrgUnitPath>)] [filter|filters <String>] [fields|parameters <String>]
|
||||
gam report customers|customer|domain [todrive] [date <Date>] [fulldatarequired all|<ReportsAppList>]
|
||||
[fields|parameters <String>]
|
||||
gam report admin|calendar|calendars|drive|docs|doc|groups|group|logins|login|mobile|tokens|token [todrive]
|
||||
gam report <ActivityApplicationName> [todrive]
|
||||
[start <Time>] [end <Time>] [(user all|<UserItem>)] [event <String>] [filter|filters <String>] [ip <String>]
|
||||
|
||||
gam create admin <UserItem> <RoleItem> customer|(org_unit <OrgUnitItem>)
|
||||
|
||||
39
src/gam.py
39
src/gam.py
@@ -1213,9 +1213,33 @@ def _checkFullDataAvailable(warnings, tryDate, fullDataRequired):
|
||||
return (-1, tryDate)
|
||||
return (1, tryDate)
|
||||
|
||||
REPORT_CHOICE_MAP = {
|
||||
'access': 'access_transparency',
|
||||
'accesstransparency': 'access_transparency',
|
||||
'calendars': 'calendar',
|
||||
'customers': 'customer',
|
||||
'doc': 'drive',
|
||||
'docs': 'drive',
|
||||
'domain': 'customer',
|
||||
'enterprisegroups': 'groups_enterprise',
|
||||
'google+': 'gplus',
|
||||
'group': 'groups',
|
||||
'groupsenterprise': 'groups_enterprise',
|
||||
'hangoutsmeet': 'meet',
|
||||
'logins': 'login',
|
||||
'oauthtoken': 'token',
|
||||
'tokens': 'token',
|
||||
'users': 'user',
|
||||
'useraccounts': 'user_accounts',
|
||||
}
|
||||
|
||||
def showReport():
|
||||
rep = buildGAPIObject('reports')
|
||||
report = sys.argv[2].lower()
|
||||
report = REPORT_CHOICE_MAP.get(report.replace('_', ''), report)
|
||||
valid_apps = _getEnumValuesMinusUnspecified(rep._rootDesc['resources']['activities']['methods']['list']['parameters']['applicationName']['enum'])
|
||||
if report not in valid_apps:
|
||||
controlflow.expected_argument_exit("report", ", ".join(valid_apps), report)
|
||||
customerId = GC_Values[GC_CUSTOMER_ID]
|
||||
if customerId == MY_CUSTOMER:
|
||||
customerId = None
|
||||
@@ -1265,7 +1289,7 @@ def showReport():
|
||||
i += 1
|
||||
else:
|
||||
controlflow.invalid_argument_exit(sys.argv[i], "gam report")
|
||||
if report in ['users', 'user']:
|
||||
if report == 'user':
|
||||
while True:
|
||||
try:
|
||||
if fullDataRequired is not None:
|
||||
@@ -1307,7 +1331,7 @@ def showReport():
|
||||
row[name] = ''
|
||||
csvRows.append(row)
|
||||
writeCSVfile(csvRows, titles, f'User Reports - {tryDate}', to_drive)
|
||||
elif report in ['customer', 'customers', 'domain']:
|
||||
elif report == 'customer':
|
||||
while True:
|
||||
try:
|
||||
if fullDataRequired is not None:
|
||||
@@ -1372,16 +1396,6 @@ def showReport():
|
||||
csvRows.append(app)
|
||||
writeCSVfile(csvRows, titles, f'Customer Report - {tryDate}', todrive=to_drive)
|
||||
else:
|
||||
if report in ['doc', 'docs']:
|
||||
report = 'drive'
|
||||
elif report in ['calendars']:
|
||||
report = 'calendar'
|
||||
elif report == 'logins':
|
||||
report = 'login'
|
||||
elif report == 'tokens':
|
||||
report = 'token'
|
||||
elif report == 'group':
|
||||
report = 'groups'
|
||||
page_message = gapi.got_total_items_msg('Activities', '...\n')
|
||||
activities = gapi.get_all_pages(rep.activities(), 'list', 'items',
|
||||
page_message=page_message,
|
||||
@@ -11553,7 +11567,6 @@ def doCreateAlertFeedback():
|
||||
alertId = sys.argv[3]
|
||||
body = {'type': sys.argv[4].upper()}
|
||||
if body['type'] not in valid_types:
|
||||
###
|
||||
controlflow.system_error_exit(2, f'{body["type"]} is not a valid feedback value, expected one of: {", ".join(valid_types)}')
|
||||
gapi.call(ac.alerts().feedback(), 'create', alertId=alertId, body=body)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user