本文整理汇总了Python中github3.authorize方法的典型用法代码示例。如果您正苦于以下问题:Python github3.authorize方法的具体用法?Python github3.authorize怎么用?Python github3.authorize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github3
的用法示例。
在下文中一共展示了github3.authorize方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_github
# 需要导入模块: import github3 [as 别名]
# 或者: from github3 import authorize [as 别名]
def get_github():
config_path = os.path.expanduser('~/.lbry-release-tool.json')
if os.path.exists(config_path):
with open(config_path, 'r') as config_file:
config = json.load(config_file)
return github3.login(token=config['token'])
token = os.environ.get("GH_TOKEN")
if not token:
print('GitHub Credentials')
username = input('username: ')
password = getpass('password: ')
gh = github3.authorize(
username, password, ['repo'], 'lbry release tool',
two_factor_callback=lambda: input('Enter 2FA: ')
)
with open(config_path, 'w') as config_file:
json.dump({'token': gh.token}, config_file)
token = gh.token
return github3.login(token=token)
示例2: get_session
# 需要导入模块: import github3 [as 别名]
# 或者: from github3 import authorize [as 别名]
def get_session():
"""Fetch and/or load API authorization token for GITHUB."""
ensure_config_dir()
credential_file = os.path.join(CONFIG_DIR, 'github_auth')
if os.path.isfile(credential_file):
with open(credential_file) as fd:
token = fd.readline().strip()
gh = GitHub(token=token)
try: # Test connection before starting
gh.is_starred('github', 'gitignore')
return gh
except GitHubError as exc:
raise_unexpected(exc.code)
sys.stderr.write('Invalid saved credential file.\n')
from getpass import getpass
from github3 import authorize
user = prompt('GITHUB Username')
try:
auth = authorize(
user, getpass('Password for {0}: '.format(user)), 'repo',
'Farcy Code Reviewer',
two_factor_callback=lambda: prompt('Two factor token'))
except GitHubError as exc:
raise_unexpected(exc.code)
raise FarcyException(exc.message)
with open(credential_file, 'w') as fd:
fd.write('{0}\n{1}\n'.format(auth.token, auth.id))
return GitHub(token=auth.token)
示例3: github_auth
# 需要导入模块: import github3 [as 别名]
# 或者: from github3 import authorize [as 别名]
def github_auth():
if os.path.exists(CREDENTIALS_FILE):
with open(CREDENTIALS_FILE) as f:
token = f.read().strip()
return token
from github3 import authorize
from getpass import getpass
user = ''
while not user:
user = input("Username: ")
password = ''
while not password:
password = getpass('Password for {0}: '.format(user))
note = 'cavejohnson, teaching Xcode 6 CI new tricks'
note_url = 'http://sealedabstract.com'
scopes = ['repo:status', 'repo']
auth = authorize(user, password, scopes, note, note_url)
with open(CREDENTIALS_FILE, "w") as f:
f.write(auth.token)
return auth.token
# rdar://17923022
示例4: auth
# 需要导入模块: import github3 [as 别名]
# 或者: from github3 import authorize [as 别名]
def auth():
username = click.prompt('Username')
password = click.prompt('Password', hide_input=True)
def twofacallback(*args):
return click.prompt('2fa Code')
hostid = ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(8))
note = 'gitconsensus - %s' % (hostid,)
note_url = 'https://github.com/tedivm/GitConsensus'
scopes = ['repo']
auth = github3.authorize(username, password, scopes, note, note_url, two_factor_callback=twofacallback)
with open("%s/%s" % (os.getcwd(), '/.gitcredentials'), 'w') as fd:
fd.write(str(auth.id) + '\n')
fd.write(auth.token + '\n')
示例5: authorize_token
# 需要导入模块: import github3 [as 别名]
# 或者: from github3 import authorize [as 别名]
def authorize_token(user):
config = read_config()
if config.get('GitHub', 'token'):
print("The token already exists.")
sys.exit()
password = getpass('Password for {0}: '.format(user))
note = 'OCA (odoo community association) Maintainers Tools'
note_url = 'https://github.com/OCA/maintainers-tools'
scopes = ['repo', 'read:org', 'write:org', 'admin:org']
try:
# Python 2
prompt = raw_input
except NameError:
# Python 3
prompt = input
def two_factor_prompt():
code = ''
while not code:
# The user could accidentally press Enter before being ready,
# let's protect them from doing that.
code = prompt('Enter 2FA code: ')
return code
try:
auth = github3.authorize(user, password, scopes, note, note_url,
two_factor_callback=two_factor_prompt)
except github3.GitHubError as err:
if err.code == 422:
for error in err.errors:
if error['code'] == 'already_exists':
msg = ("The 'OCA (odoo community association) Maintainers "
"Tools' token already exists. You will find it at "
"https://github.com/settings/tokens and can "
"revoke it or set the token manually in the "
"configuration file.")
sys.exit(msg)
raise
config.set("GitHub", "token", auth.token)
write_config(config)
print("Token stored in configuration file")
示例6: login
# 需要导入模块: import github3 [as 别名]
# 或者: from github3 import authorize [as 别名]
def login(self, username="", password=""):
"""
Performs a login and sets the Github object via given credentials. If
credentials are empty or incorrect then prompts user for credentials.
Stores the authentication token in a CREDENTIALS_FILE used for future
logins. Handles Two Factor Authentication.
"""
try:
token = ""
id = ""
if not os.path.isfile("CREDENTIALS_FILE"):
if username == "" or password == "":
username = raw_input("Username: ")
password = getpass.getpass("Password: ")
note = "GitHub Organization Stats App"
note_url = "http://software.llnl.gov/"
scopes = ["user", "repo"]
auth = github3.authorize(
username,
password,
scopes,
note,
note_url,
two_factor_callback=self.prompt_2fa,
)
token = auth.token
id = auth.id
with open("CREDENTIALS_FILE", "w+") as fd:
fd.write(token + "\n")
fd.write(str(id))
fd.close()
else:
with open("CREDENTIALS_FILE", "r") as fd:
token = fd.readline().strip()
id = fd.readline().strip()
fd.close()
print("Logging in.")
self.logged_in_gh = github3.login(
token=token, two_factor_callback=self.prompt_2fa
)
self.logged_in_gh.user().to_json()
except (ValueError, AttributeError, github3.models.GitHubError):
print("Bad credentials. Try again.")
self.login()
示例7: login
# 需要导入模块: import github3 [as 别名]
# 或者: from github3 import authorize [as 别名]
def login(self, username="", password=""):
"""
Performs a login and sets the Github object via given credentials. If
credentials are empty or incorrect then prompts user for credentials.
Stores the authentication token in a CREDENTIALS_FILE used for future
logins. Handles Two Factor Authentication.
"""
try:
self.token = ""
id = ""
if not os.path.isfile("CREDENTIALS_FILE_ADMIN"):
if username == "" or password == "":
username = raw_input("Username: ")
password = getpass.getpass("Password: ")
note = "GitHub Organization Stats App"
note_url = "http://software.llnl.gov/"
scopes = ["user", "repo"]
auth = github3.authorize(
username,
password,
scopes,
note,
note_url,
two_factor_callback=self.prompt_2fa,
)
self.token = auth.token
id = auth.id
with open("CREDENTIALS_FILE_ADMIN", "w+") as fd:
fd.write(self.token + "\n")
fd.write(str(id))
fd.close()
else:
with open("CREDENTIALS_FILE_ADMIN", "r") as fd:
self.token = fd.readline().strip()
id = fd.readline().strip()
fd.close()
print("Logging in.")
self.logged_in_gh = github3.login(
token=self.token, two_factor_callback=self.prompt_2fa
)
self.logged_in_gh.user().to_json()
except (ValueError, AttributeError, github3.models.GitHubError):
print("Bad credentials. Try again.")
self.login()
示例8: login
# 需要导入模块: import github3 [as 别名]
# 或者: from github3 import authorize [as 别名]
def login(self, username="", password=""):
"""
Performs a login and sets the Github object via given credentials. If
credentials are empty or incorrect then prompts user for credentials.
Stores the authentication token in a CREDENTIALS_FILE used for future
logins. Handles Two Factor Authentication.
"""
try:
self.token = ""
id = ""
if not os.path.isfile("CREDENTIALS_FILE"):
if username == "" or password == "":
username = raw_input("Username: ")
password = getpass.getpass("Password: ")
note = "GitHub Organization Stats App"
note_url = "http://software.llnl.gov/"
scopes = ["user", "repo"]
auth = github3.authorize(
username,
password,
scopes,
note,
note_url,
two_factor_callback=self.prompt_2fa,
)
self.token = auth.token
id = auth.id
with open("CREDENTIALS_FILE", "w+") as fd:
fd.write(self.token + "\n")
fd.write(str(id))
fd.close()
else:
with open("CREDENTIALS_FILE", "r") as fd:
self.token = fd.readline().strip()
id = fd.readline().strip()
fd.close()
print("Logging in.")
self.logged_in_gh = github3.login(
token=self.token, two_factor_callback=self.prompt_2fa
)
self.logged_in_gh.user().to_json()
except (ValueError, AttributeError, github3.models.GitHubError):
print("Bad credentials. Try again.")
self.login()