Skip to content

Commit

Permalink
Try authenticated curl API calls for Cloudsmith
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuru committed Feb 6, 2025
1 parent a176219 commit b79a1d0
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
26 changes: 26 additions & 0 deletions bin/curl-auth
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 "$@"
7 changes: 7 additions & 0 deletions deb/Dockerfile.stable-slim
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ RUN echo downloading go${GO_INSTALL_VERSION} && \

WORKDIR /packages

# Add a wrapper script to authenticate curl requests when directed to GitHub API
COPY bin/curl-auth /usr/local/bin/curl-auth
RUN real_curl="$(which curl)" && \
mv "${real_curl}" "${real_curl}".real && \
mv /usr/local/bin/curl-auth "${real_curl}" && \
chmod +x "${real_curl}"

# Our base image is Python, with entrypoint into a Python shell, so we need to override the entrypoint
ENTRYPOINT []
CMD ["/bin/bash"]
7 changes: 7 additions & 0 deletions rpm/Dockerfile.ubi
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,10 @@ RUN gem install --no-document fpm --ignore-dependencies -N


WORKDIR /packages

COPY bin/curl-auth /usr/local/bin/curl-auth
RUN real_curl="$(which curl)" && \
mv "${real_curl}" "${real_curl}".real && \
mv /usr/local/bin/curl-auth "${real_curl}" && \
chmod +x "${real_curl}"

0 comments on commit b79a1d0

Please sign in to comment.