Code fixes, cleanup (#315)

* Code fixes, cleanup

Fix doCheckServiceAccount to pass correct api to buildGAPIServiceObject
pylint cleanup
Simplify passing login_hint to doRequestOAuth in main
Give error if invalid argument after gam <users> check

* Fix error

* Use try accept
This commit is contained in:
Ross Scroggs
2016-11-04 11:13:39 -07:00
committed by Jay Lee
parent 2958bd9f86
commit 7d849e0cc0

View File

@ -1214,17 +1214,17 @@ def doCheckServiceAccount(users):
for scope in scopes:
if scope in all_scopes:
continue # don't check same scope twice
all_scopes.append(scope)
all_scopes.append((api, scope))
all_scopes = sorted(all_scopes)
for scope in all_scopes:
try:
service = buildGAPIServiceObject(api, act_as=user, use_scopes=scope)
service = buildGAPIServiceObject(scope[0], act_as=user, use_scopes=scope[1])
service._http.request.credentials.refresh(httplib2.Http(disable_ssl_certificate_validation=GC_Values[GC_NO_VERIFY_SSL]))
result = u'PASS'
except oauth2client.client.HttpAccessTokenRefreshError:
result = u'FAIL'
all_scopes_pass = False
print u' Scope: {0:60} {1}'.format(scope, result)
print u' Scope: {0:60} {1}'.format(scope[1], result)
service_account = service._http.request.credentials.serialization_data[u'client_id']
if all_scopes_pass:
print u'\nAll scopes passed!\nService account %s is fully authorized.' % service_account
@ -1241,7 +1241,7 @@ and grant Client name:
Access to scopes:
%s\n''' % (user_domain, service_account, ',\n'.join(all_scopes))
%s\n''' % (user_domain, service_account, ',\n'.join([scope[1] for scope in all_scopes]))
sys.exit(int(not all_scopes_pass))
def showReport():
@ -10767,6 +10767,9 @@ def ProcessGAMCommand(args):
checkWhat = sys.argv[4].replace(u'_', '').lower()
if checkWhat == u'serviceaccount':
doCheckServiceAccount(users)
else:
print u'ERROR: %s is not a valid argument for "gam <users> check"' % checkWhat
sys.exit(2)
elif command == u'profile':
doProfile(users)
elif command == u'imap':