Use user's ~/.netrc for accessing mixin repositories - #50
Conversation
Recent changes to GitHub raw content availability have made it more desirable to support authenticated requests to externally hosted content. Rather than adding specific logic for GitHub's authorization mechanisms, we can leverage the widely used .netrc format for adding an authorization header to our web requests.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #50 +/- ##
======================================
Coverage 0.00% 0.00%
======================================
Files 11 11
Lines 540 557 +17
======================================
- Misses 540 557 +17 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Looks good to me.
I'm having a hard time testing that the ~/.netrc raw.githubusercontent.com token on my machine actually does something, though. I used a dummy password, which does seem to be used and unexpectedly works fine, so I'm not sure if a real token would actually do anything:
machine raw.githubusercontent.com
password 123
If I change Basic to token and only include the password without the login (from here), I get a 404 unless I use a real token:
- credentials = f'{entry[0]}:{entry[2]}'
- auth = 'Basic ' + b64encode(credentials.encode()).decode()
+ credentials = f'{entry[2]}'
+ auth = 'token ' + credentials|
I observed similar behavior. The only way I was able to verify that it was in fact using the token was to set up a mixin repository that was in a private repository. I'm not sure why we don't get an error when the credentials are wrong. I don't think we can use |
|
Do you think other hosts would also need |
|
Let's verify whether this existing approach works first, then we can discuss GitHub-specific alternatives and workarounds if necessary. (by that I mean verify that it can be used to get around the anonymous rate limiting) |
Recent changes to GitHub raw content availability have made it more desirable to support authenticated requests to externally hosted content. Rather than adding specific logic for GitHub's authorization mechanisms, we can leverage the widely used .netrc format for adding an authorization header to our web requests.
As an example, a GitHub classic PAT with sufficient scopes can be configured and automatically used with a
~/.netrclike this:Note that this scheme works for
raw.githubusercontent.com, but may not work forgithub.comURLs (even when they redirect toraw.githubusercontent.com). Also worth noting is that .netrc files are implicitly used by the widely-usedrequestsPython package, so there is precedent for their use in this context.This change doesn't introduce any new dependencies, but does change default behavior.