From 20bba75e41c3e39ad8ec6ea95c4d9264c5e4bf5b Mon Sep 17 00:00:00 2001 From: Jay Lee Date: Wed, 30 Dec 2015 16:12:49 -0500 Subject: [PATCH] default scope selections basic logic is: -if 1 scope for API, use it -skip over scopes ending in .readonly, .action or .verify_only UNLESS all scopes are readonly, use all scopes (this is case with reports api) -all other scopes are used by default. --- src/gam.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/gam.py b/src/gam.py index b00f1d73..66dadf4d 100755 --- a/src/gam.py +++ b/src/gam.py @@ -8728,10 +8728,32 @@ def doRequestOAuth(): service = googleapiclient.discovery.build(api, version, http=http, cache_discovery=False) except googleapiclient.errors.UnknownApiNameOrVersion: service = getServiceFromDiscoveryDocument(api, version, http) - all_apis[api] = service._rootDesc + all_apis[u'%s-%s' % (api, version)] = service._rootDesc i = 0 + # Default Scope Selections + for api_name, api in all_apis.items(): + all_apis[api_name][u'use_scopes'] = [] + scopes = api[u'auth'][u'oauth2'][u'scopes'].keys() + if len(scopes) == 1: + all_apis[api_name][u'use_scopes'] += scopes + continue + all_readonly = True + for scope in api[u'auth'][u'oauth2'][u'scopes'].keys(): + if scope.endswith(u'.readonly'): + continue + elif scope.endswith(u'.action'): + all_readonly = False + continue + elif scope.endswith(u'verify_only'): + all_readonly = False + continue + else: + all_apis[api_name][u'use_scopes'].append(scope) + all_readonly = False + if all_readonly: + all_apis[api_name][u'use_scopes'] += scopes for api in all_apis.values(): - print u'[*] %s) %s' % (i, api[u'title']) + print u'[*] %s) %s (%s scopes)' % (i, api[u'title'], len(api[u'use_scopes'])) i += 1 def batch_worker():