-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Try authenticated curl API calls for Cloudsmith
- Loading branch information
Showing
3 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/bash | ||
|
||
# Authenticate with GitHub using a token when calling the API via curl | ||
# Needed to get past rate limits with Cloudsmith GitHub action | ||
|
||
curl_wrapper() { | ||
local args=("$@") | ||
local url="" | ||
|
||
# Find the URL argument | ||
for arg in "${args[@]}"; do | ||
if [[ "$arg" =~ ^https?:// ]]; then | ||
url="$arg" | ||
break | ||
fi | ||
done | ||
|
||
# Check if URL is for api.github.com and GITHUB_TOKEN is set | ||
if [[ -n "$GITHUB_TOKEN" && -n "$url" && "$url" =~ ^https?://api\.github\.com ]]; then | ||
exec curl.real -H "Authorization: Bearer $GITHUB_TOKEN" "${args[@]}" | ||
else | ||
exec curl.real "${args[@]}" | ||
fi | ||
} | ||
|
||
curl_wrapper "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters