Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
6e48d54a
Commit
6e48d54a
authored
May 07, 2014
by
David Baumgold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor to support two-factor authentication
parent
d49c97bd
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
16 deletions
+34
-16
scripts/release.py
+34
-16
No files found.
scripts/release.py
View file @
6e48d54a
...
...
@@ -125,6 +125,31 @@ def get_github_creds():
return
None
def
create_github_creds
():
headers
=
{
"User-Agent"
:
"edx-release"
}
payload
=
{
"note"
:
"edx-release"
}
username
=
raw_input
(
"Github username: "
)
password
=
getpass
.
getpass
(
"Github password: "
)
response
=
requests
.
post
(
"https://api.github.com/authorizations"
,
auth
=
(
username
,
password
),
headers
=
headers
,
data
=
json
.
dumps
(
payload
),
)
# is the user using two-factor authentication?
otp_header
=
response
.
headers
.
get
(
"X-GitHub-OTP"
)
if
not
response
.
ok
and
otp_header
and
otp_header
.
startswith
(
"required;"
):
# get two-factor code, redo the request
headers
[
"X-GitHub-OTP"
]
=
raw_input
(
"Two-factor authentication code: "
)
response
=
requests
.
post
(
"https://api.github.com/authorizations"
,
auth
=
(
username
,
password
),
headers
=
headers
,
data
=
json
.
dumps
(
payload
),
)
if
not
response
.
ok
:
raise
requests
.
exceptions
.
RequestException
(
response
.
json
()[
"message"
])
return
(
username
,
response
.
json
()[
"token"
])
def
ensure_github_creds
(
attempts
=
3
):
"""
Make sure that we have Github OAuth credentials. This will check the user's
...
...
@@ -140,32 +165,25 @@ def ensure_github_creds(attempts=3):
# Looks like we need to create the OAuth creds
# https://developer.github.com/v3/oauth_authorizations/#create-a-new-authorization
print
(
"We need to set up OAuth authentication with Github's API. "
"Your credentials will not be stored."
,
file
=
sys
.
stderr
)
headers
=
{
"User-Agent"
:
"edx-release"
}
payload
=
{
"note"
:
"edx-release"
}
"Your password will not be stored."
,
file
=
sys
.
stderr
)
token
=
None
for
_
in
range
(
attempts
):
username
=
raw_input
(
"Github username: "
)
password
=
getpass
.
getpass
(
"Github password: "
)
response
=
requests
.
post
(
"https://api.github.com/authorizations"
,
auth
=
(
username
,
password
),
headers
=
headers
,
data
=
json
.
dumps
(
payload
),
)
if
not
response
.
ok
:
try
:
username
,
token
=
create_github_creds
()
except
requests
.
exceptions
.
RequestException
as
e
:
print
(
"Invalid authentication: {}"
.
format
(
response
.
json
()[
"message"
]
),
"Invalid authentication: {}"
.
format
(
e
.
message
),
file
=
sys
.
stderr
,
)
continue
else
:
break
if
not
response
.
ok
:
if
token
:
print
(
"Successfully authenticated to Github"
,
file
=
sys
.
stderr
)
if
not
token
:
print
(
"Too many invalid authentication attempts."
,
file
=
sys
.
stderr
)
return
False
# got the token!
token
=
response
.
json
()[
"token"
]
config_file
=
path
(
"~/.config/edx-release"
)
.
expand
()
# make sure parent directory exists
config_file
.
parent
.
makedirs_p
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment