-
Notifications
You must be signed in to change notification settings - Fork 406
/
Copy pathapi.py
78 lines (57 loc) · 2.13 KB
/
api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"""
github3.api
===========
:copyright: (c) 2012-2014 by Ian Cordasco
:license: Modified BSD, see LICENSE for more details
"""
from .github import GitHub
from .github import GitHubEnterprise
gh = GitHub()
def login(username=None, password=None, token=None, two_factor_callback=None):
"""Construct and return an authenticated GitHub session.
.. note::
To allow you to specify either a username and password combination or
a token, none of the parameters are required. If you provide none of
them, you will receive ``None``.
:param str username: login name
:param str password: password for the login
:param str token: OAuth token
:param func two_factor_callback: (optional), function you implement to
provide the Two-factor Authentication code to GitHub when necessary
:returns: :class:`GitHub <github3.github.GitHub>`
"""
g = None
if (username and password) or token:
g = GitHub()
g.login(username, password, token, two_factor_callback)
return g
def enterprise_login(
username=None,
password=None,
token=None,
url=None,
two_factor_callback=None,
):
"""Construct and return an authenticated GitHubEnterprise session.
.. note::
To allow you to specify either a username and password combination or
a token, none of the parameters are required. If you provide none of
them, you will receive ``None``.
:param str username: login name
:param str password: password for the login
:param str token: OAuth token
:param str url: URL of a GitHub Enterprise instance
:param func two_factor_callback: (optional), function you implement to
provide the Two-factor Authentication code to GitHub when necessary
:returns: :class:`GitHubEnterprise <github3.github.GitHubEnterprise>`
"""
if not url:
raise ValueError(
"GitHub Enterprise requires you provide the URL of"
" the instance"
)
g = None
if (username and password) or token:
g = GitHubEnterprise(url)
g.login(username, password, token, two_factor_callback)
return g