bmk
bmk

Reputation: 396

Access raw file on GitHub Enterprise without user having to create token

I have a repo with shell script and want to put single command to run it in readme file, like:

bash <(curl -L <path_to_raw_script_file>)

Raw file urls for GitHub Enterprise look like this: https://raw.github.ibm.com/<user>/<repo>/<branch>/<path_to_file>?token=<token>, where <token> is unique to the file and generated when accesing it via Raw button in repository or with ?raw=true suffix in url.

The problem is, tokens get invalidated after few days/when file is updated and I wouldn't like to update mentioned command each time token becomes invalid. Is there a way to deal with it?

I know there is a way for user to create personal token and use it to login to github from machine he's runnning script from, but I wanted to keep it as simple as possible.

I was thinking of something like auto-generating that raw file url (since user reading the readme file on github surely does have access to the script located in the same repo), but I am not sure if that's possible.

Upvotes: 8

Views: 6352

Answers (3)

VonC
VonC

Reputation: 1327264

I know there is a way for user to create personal token and use it to login to GitHub from machine he's runnning script from, but I wanted to keep it as simple as possible.

Actually, using GCM (Git Credential Manager); the PAT will be provided when accessing the raw.xxx URL.

But only with GCM v2.0.692 which supports those URLs. See PR 599.

Fix GitHub Enterprise API URL for raw source code links

This is a simple fix of #598 for GitHub Enterprise instances that use a raw. hostname prefix for raw source code links.

I've verified this fix locally by swapping out the GitHub.dll that is used by Visual Studio.

So it now checks for 'raw.' in the hostname and remove it to get the correct GHE API URL.

Upvotes: 0

Aki
Aki

Reputation: 179

No input, one-liner.

You can get this link by clicking the raw button in the GHE UI, just remove the token query param at the end.

curl -sfSO https://${USER}:${TOKEN}@${GHE_DOMAIN}/raw/${REPO_OWNER}/${REPO_NAME}/${REF}/${FILE}

Upvotes: 2

Alex Mapley
Alex Mapley

Reputation: 922

I believe you'll always need the tokens - however if you'd like to automate the process you can dynamically request tokens associated with a github Oauth app and not associated with any user profile.

https://developer.github.com/enterprise/2.13/apps/building-oauth-apps/authorizing-oauth-apps/

Upvotes: 1

Related Questions