github.py 文件源码

python
阅读 36 收藏 0 点赞 0 评论 0

项目:AerisCloud 作者: AerisCloud 项目源码 文件源码
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})
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号