@@ -59,6 +59,11 @@ class Recipe(metaclass=RecipeMeta):
59
59
if you want.
60
60
'''
61
61
62
+ _github_access_token = None
63
+ '''Used to access a private git repository. Specify the github-supplied
64
+ access token in order to download the private repository files.
65
+ '''
66
+
62
67
_version = None
63
68
'''A string giving the version of the software the recipe describes,
64
69
e.g. ``2.0.3`` or ``master``.'''
@@ -170,6 +175,11 @@ def versioned_url(self):
170
175
return None
171
176
return self .url .format (version = self .version )
172
177
178
+ @property
179
+ def github_access_token (self ):
180
+ key = "GITHUB_ACCESS_TOKEN_" + self .name
181
+ return environ .get (key , self ._github_access_token )
182
+
173
183
def download_file (self , url , target , cwd = None ):
174
184
"""
175
185
(internal) Download an ``url`` to a ``target``.
@@ -205,6 +215,9 @@ def report_hook(index, blksize, size):
205
215
# jqueryui.com returns a 403 w/ the default user agent
206
216
# Mozilla/5.0 doesnt handle redirection for liblzma
207
217
url_opener .addheaders = [('User-agent' , 'Wget/1.0' )]
218
+ if self .github_access_token :
219
+ url_opener .addheaders += [('Authorization' , f'token { self .github_access_token } ' ),
220
+ ('Accept' , 'application/vnd.github.v3.raw' )]
208
221
urlretrieve (url , target , report_hook )
209
222
except OSError as e :
210
223
attempts += 1
0 commit comments