mirror of
https://github.com/GAM-team/GAM.git
synced 2025-07-09 14:13:35 +00:00
More clean up of doRequestOAuth
This commit is contained in:
55
src/gam.py
55
src/gam.py
@ -8803,12 +8803,16 @@ def select_default_scopes(apis):
|
|||||||
apis[api_name][u'use_scopes'] += scopes
|
apis[api_name][u'use_scopes'] += scopes
|
||||||
return apis
|
return apis
|
||||||
|
|
||||||
def getSelection():
|
def getSelection(limit):
|
||||||
while True:
|
while True:
|
||||||
selection = raw_input(u'Your selection: ')
|
selection = raw_input(u'Your selection: ')
|
||||||
if selection:
|
if selection:
|
||||||
if selection.isdigit():
|
if selection.isdigit():
|
||||||
return int(selection)
|
selection = int(selection)
|
||||||
|
if (selection >= 0) and (selection <= limit):
|
||||||
|
return selection
|
||||||
|
print u'ERROR: enter number in range 0-{0}'.format(limit)
|
||||||
|
else:
|
||||||
print u'ERROR: please enter numbers only'
|
print u'ERROR: please enter numbers only'
|
||||||
|
|
||||||
def doRequestOAuth():
|
def doRequestOAuth():
|
||||||
@ -8844,19 +8848,20 @@ def doRequestOAuth():
|
|||||||
select_value = u'*'
|
select_value = u'*'
|
||||||
else:
|
else:
|
||||||
select_value = u' '
|
select_value = u' '
|
||||||
print u'[%s] %s) %s (%s/%s scopes)' % (select_value, api[u'index'], api[u'title'], num_scopes_selected, num_scopes_total)
|
print u'[%s] %2d) %s (%d/%d scopes)' % (select_value, api[u'index'], api[u'title'], num_scopes_selected, num_scopes_total)
|
||||||
print
|
print
|
||||||
print u' %s) Select defaults for all APIs (allow all GAM commands)' % (i+1)
|
print u' %2d) Select defaults for all APIs (allow all GAM commands)' % (i)
|
||||||
print u' %s) Unselect all APIs' % (i+2)
|
print u' %2d) Unselect all APIs' % (i+1)
|
||||||
print u' %s) Continue' % (i+3)
|
print u' %2d) Continue' % (i+2)
|
||||||
|
print u' %2d) Cancel' % (i+3)
|
||||||
print
|
print
|
||||||
selection = getSelection()
|
selection = getSelection(i+3)
|
||||||
if selection == i+1: # defaults
|
if selection == i: # defaults
|
||||||
all_apis = select_default_scopes(all_apis)
|
all_apis = select_default_scopes(all_apis)
|
||||||
elif selection == i+2: # unselect all
|
elif selection == i+1: # unselect all
|
||||||
for api in all_apis.keys():
|
for api in all_apis.keys():
|
||||||
all_apis[api][u'use_scopes'] = []
|
all_apis[api][u'use_scopes'] = []
|
||||||
elif selection == i+3:
|
elif selection == i+2: # continue
|
||||||
GM_Globals[GM_GAMSCOPES_BY_API] = {}
|
GM_Globals[GM_GAMSCOPES_BY_API] = {}
|
||||||
GM_Globals[GM_GAMSCOPES_LIST] = []
|
GM_Globals[GM_GAMSCOPES_LIST] = []
|
||||||
for api in all_apis.keys():
|
for api in all_apis.keys():
|
||||||
@ -8869,7 +8874,9 @@ def doRequestOAuth():
|
|||||||
writeFile(GC_Values[GC_GAMSCOPES_JSON], json.dumps(GM_Globals[GM_GAMSCOPES_BY_API]))
|
writeFile(GC_Values[GC_GAMSCOPES_JSON], json.dumps(GM_Globals[GM_GAMSCOPES_BY_API]))
|
||||||
print u'Scopes file: {0}, Created'.format(GC_Values[GC_GAMSCOPES_JSON])
|
print u'Scopes file: {0}, Created'.format(GC_Values[GC_GAMSCOPES_JSON])
|
||||||
break
|
break
|
||||||
elif selection >= 0 and selection < len(all_apis.keys()):
|
elif selection == i+3: # cancel
|
||||||
|
return
|
||||||
|
else: # select
|
||||||
api = all_apis.keys()[selection]
|
api = all_apis.keys()[selection]
|
||||||
if len(all_apis[api][u'auth'][u'oauth2'][u'scopes']) == 1:
|
if len(all_apis[api][u'auth'][u'oauth2'][u'scopes']) == 1:
|
||||||
if len(all_apis[api][u'use_scopes']) == 1:
|
if len(all_apis[api][u'use_scopes']) == 1:
|
||||||
@ -8886,33 +8893,35 @@ def doRequestOAuth():
|
|||||||
select_value = u'*'
|
select_value = u'*'
|
||||||
else:
|
else:
|
||||||
select_value = u' '
|
select_value = u' '
|
||||||
print u'[%s] %s) %s\n %s\n' % (select_value, x, all_apis[api][u'auth'][u'oauth2'][u'scopes'][scope][u'description'], scope)
|
print u'[%s] %2d) %s\n %s\n' % (select_value, x, all_apis[api][u'auth'][u'oauth2'][u'scopes'][scope][u'description'], scope)
|
||||||
x += 1
|
x += 1
|
||||||
print u' %s) Select defaults for this API (allow all GAM commands)' % (x)
|
print u' %2d) Select defaults for this API (allow all GAM commands)' % (x)
|
||||||
print u' %s) Select read-only scopes' % (x+1)
|
print u' %2d) Select read-only scopes' % (x+1)
|
||||||
print u' %s) Unselect all scopes' % (x+2)
|
print u' %2d) Unselect all scopes' % (x+2)
|
||||||
print u' %s) Back to all APIs' % (x+3)
|
print u' %2d) Back to all APIs' % (x+3)
|
||||||
|
print u' %2d) Cancel' % (x+4)
|
||||||
print
|
print
|
||||||
selection = getSelection()
|
selection = getSelection(x+4)
|
||||||
num_scopes = len(all_apis[api][u'auth'][u'oauth2'][u'scopes'].keys())
|
if selection < x: # select
|
||||||
if selection >= 0 and selection < num_scopes:
|
|
||||||
if all_apis[api][u'auth'][u'oauth2'][u'scopes'].keys()[selection] in all_apis[api][u'use_scopes']:
|
if all_apis[api][u'auth'][u'oauth2'][u'scopes'].keys()[selection] in all_apis[api][u'use_scopes']:
|
||||||
all_apis[api][u'use_scopes'].remove(all_apis[api][u'auth'][u'oauth2'][u'scopes'].keys()[selection])
|
all_apis[api][u'use_scopes'].remove(all_apis[api][u'auth'][u'oauth2'][u'scopes'].keys()[selection])
|
||||||
else:
|
else:
|
||||||
all_apis[api][u'use_scopes'].append(all_apis[api][u'auth'][u'oauth2'][u'scopes'].keys()[selection])
|
all_apis[api][u'use_scopes'].append(all_apis[api][u'auth'][u'oauth2'][u'scopes'].keys()[selection])
|
||||||
elif selection == x:
|
elif selection == x: # defaults
|
||||||
just_this_api = {api: all_apis[api]}
|
just_this_api = {api: all_apis[api]}
|
||||||
just_this_api = select_default_scopes(just_this_api)
|
just_this_api = select_default_scopes(just_this_api)
|
||||||
all_apis[api][u'use_scopes'] = just_this_api[api][u'use_scopes']
|
all_apis[api][u'use_scopes'] = just_this_api[api][u'use_scopes']
|
||||||
elif selection == x+1:
|
elif selection == x+1: # read-only
|
||||||
all_apis[api][u'use_scopes'] = []
|
all_apis[api][u'use_scopes'] = []
|
||||||
for scope in all_apis[api][u'auth'][u'oauth2'][u'scopes'].keys():
|
for scope in all_apis[api][u'auth'][u'oauth2'][u'scopes'].keys():
|
||||||
if scope.endswith(u'.readonly'):
|
if scope.endswith(u'.readonly'):
|
||||||
all_apis[api][u'use_scopes'].append(scope)
|
all_apis[api][u'use_scopes'].append(scope)
|
||||||
elif selection == x+2:
|
elif selection == x+2: # unselect all
|
||||||
all_apis[api][u'use_scopes'] = []
|
all_apis[api][u'use_scopes'] = []
|
||||||
elif selection == x+3:
|
elif selection == x+3: # back
|
||||||
break
|
break
|
||||||
|
else: # cancel
|
||||||
|
return
|
||||||
print MESSAGE_PLEASE_AUTHORIZE_SERVIE_ACCOUNT.format(len(GM_Globals[GM_GAMSCOPES_LIST]))
|
print MESSAGE_PLEASE_AUTHORIZE_SERVIE_ACCOUNT.format(len(GM_Globals[GM_GAMSCOPES_LIST]))
|
||||||
print
|
print
|
||||||
print u','.join(GM_Globals[GM_GAMSCOPES_LIST])
|
print u','.join(GM_Globals[GM_GAMSCOPES_LIST])
|
||||||
|
Reference in New Issue
Block a user