Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
gh_fetch
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nimrod
gh_fetch
Commits
1d497f99
Unverified
Commit
1d497f99
authored
5 years ago
by
Will Thompson
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #6 from endlessm/T29306-api-authorization
Fix API authentication
parents
0162f4e1
130fb3f7
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
update_repos
+19
-6
19 additions, 6 deletions
update_repos
with
19 additions
and
6 deletions
update_repos
+
19
−
6
View file @
1d497f99
#!/usr/bin/python
#!/usr/bin/python
# encoding: utf-8
# encoding: utf-8
import
base64
import
sys
import
sys
import
os
import
os
import
argparse
import
argparse
from
collections
import
namedtuple
from
collections
import
namedtuple
from
subprocess
import
Popen
,
PIPE
from
subprocess
import
Popen
,
PIPE
from
urllib2
import
urlopen
from
urllib
import
urlencode
from
urllib2
import
Request
,
urlopen
import
json
import
json
from
urlparse
import
urlparse
from
urlparse
import
urlparse
...
@@ -15,8 +17,8 @@ WHITELIST=[]
...
@@ -15,8 +17,8 @@ WHITELIST=[]
BLACKLIST
=
[]
BLACKLIST
=
[]
LISTINGS_PER_PAGE
=
100
LISTINGS_PER_PAGE
=
100
ACCESS_TOKEN_PARAM
=
'
?access_token=%s
'
LISTINGS_PER_PAGE_PARAM
=
'
per_page
'
LISTING_PAGE_PARAM
=
'
&per_page=%d&page=%d
'
LISTING_PAGE_PARAM
=
'
page
'
GITHUB_API_HOST
=
'
https://api.github.com
'
GITHUB_API_HOST
=
'
https://api.github.com
'
GIT_CLONE_CMD
=
'
git clone %s %s %s
'
GIT_CLONE_CMD
=
'
git clone %s %s %s
'
...
@@ -73,12 +75,23 @@ class AttributeDict(dict):
...
@@ -73,12 +75,23 @@ class AttributeDict(dict):
self
[
attr
]
=
value
self
[
attr
]
=
value
def
read_api_uri
(
uri
,
config
,
page
=
1
):
def
read_api_uri
(
uri
,
config
,
page
=
1
):
uri
+=
ACCESS_TOKEN_PARAM
%
config
.
token
+
LISTING_PAGE_PARAM
%
(
LISTINGS_PER_PAGE
,
page
)
params
=
{
LISTINGS_PER_PAGE_PARAM
:
LISTINGS_PER_PAGE
,
LISTING_PAGE_PARAM
:
page
,
}
uri
+=
'
?
'
+
urlencode
(
params
)
creds
=
base64
.
b64encode
(
config
.
token
.
encode
(
'
utf-8
'
)).
decode
(
'
ascii
'
)
basic_auth
=
'
Basic {}
'
.
format
(
creds
)
headers
=
{
'
Authorization
'
:
basic_auth
,
}
if
config
.
debug
:
if
config
.
debug
:
print
"
Trying
:
"
,
uri
print
"
Trying
URI {} with headers {}
"
.
format
(
uri
,
headers
)
return
urlopen
(
uri
).
read
()
req
=
Request
(
uri
,
headers
=
headers
)
return
urlopen
(
req
).
read
()
def
get_json
(
uri
,
config
,
obj_type
=
AttributeDict
,
page
=
1
):
def
get_json
(
uri
,
config
,
obj_type
=
AttributeDict
,
page
=
1
):
return
json
.
loads
(
read_api_uri
(
uri
,
config
,
page
),
object_hook
=
obj_type
)
return
json
.
loads
(
read_api_uri
(
uri
,
config
,
page
),
object_hook
=
obj_type
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment