def _gen_authorization_token(self, counter=0, creds=None):
"""
This function creates the authorization token for AerisCloud.
If an existing token exists for this computer, it adds a #N counter
next to the name.
"""
if creds:
user, pwd = creds['user'], creds['pwd']
else:
(user, pwd) = self._ask_credentials()
note = 'AerisCloud on %s' % (node())
if counter > 0:
note += ' #%d' % counter
try:
auth = authorize(user, pwd, ['repo', 'read:org'], note=note,
two_factor_callback=self._ask_2fa)
return auth.token
except GitHubError as e:
if not e.errors or e.errors[0]['code'] != 'already_exists':
raise
# token exists, increment counter
counter += 1
return self._gen_authorization_token(counter=counter,
creds={'user': user,
'pwd': pwd})
评论列表
文章目录