Skip to content

Commit f2c4d29

Browse files
authored
Merge pull request #82 from marcofranssen/resolve-gh-api-rate-limits
fix: resolve gh api rate limits
2 parents d9fa643 + 17da140 commit f2c4d29

File tree

2 files changed

+40
-17
lines changed

2 files changed

+40
-17
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
FROM public.ecr.aws/docker/library/alpine:3.12
22

33
RUN apk --no-cache --update add bash git \
4+
jq curl \
45
&& rm -rf /var/cache/apk/*
56

67
COPY entrypoint.sh /entrypoint.sh

entrypoint.sh

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,52 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
set -xe
44

5+
if [ -z "${INPUT_GITHUB_TOKEN}" ] ; then
6+
echo "Consider setting a GITHUB_TOKEN to prevent GitHub api rate limits." >&2
7+
fi
8+
59
TFSEC_VERSION=""
6-
if [ "$INPUT_TFSEC_VERSION" != "latest" ]; then
10+
if [ "$INPUT_TFSEC_VERSION" != "latest" ] && [ -n "$INPUT_TFSEC_VERSION" ]; then
711
TFSEC_VERSION="/tags/${INPUT_TFSEC_VERSION}"
12+
else
13+
TFSEC_VERSION="/latest"
814
fi
915

10-
wget -O - -q "$(wget -q https://api.github.com/repos/aquasecurity/tfsec/releases${TFSEC_VERSION} -O - | grep -m 1 -o -E "https://.+?tfsec-linux-amd64" | head -n1)" > tfsec-linux-amd64
11-
wget -O - -q "$(wget -q https://api.github.com/repos/aquasecurity/tfsec/releases${TFSEC_VERSION} -O - | grep -m 1 -o -E "https://.+?tfsec_checksums.txt" | head -n1)" > tfsec.checksums
12-
13-
grep tfsec-linux-amd64 tfsec.checksums > tfsec-linux-amd64.checksum
14-
sha256sum -c tfsec-linux-amd64.checksum
15-
install tfsec-linux-amd64 /usr/local/bin/tfsec
16-
1716
COMMENTER_VERSION="latest"
18-
if [ "$INPUT_COMMENTER_VERSION" != "latest" ]; then
19-
COMMENTER_VERSION="tags/${INPUT_COMMENTER_VERSION}"
17+
if [ "$INPUT_COMMENTER_VERSION" != "latest" ] && [ -n "$INPUT_COMMENTER_VERSION" ]; then
18+
COMMENTER_VERSION="/tags/${INPUT_COMMENTER_VERSION}"
19+
else
20+
COMMENTER_VERSION="/latest"
2021
fi
2122

22-
wget -O - -q "$(wget -q https://api.github.com/repos/aquasecurity/tfsec-pr-commenter-action/releases/${COMMENTER_VERSION} -O - | grep -o -E "https://.+?commenter-linux-amd64")" > commenter-linux-amd64
23-
wget -O - -q "$(wget -q https://api.github.com/repos/aquasecurity/tfsec-pr-commenter-action/releases/${COMMENTER_VERSION} -O - | grep -o -E "https://.+?checksums.txt")" > commenter.checksums
23+
function get_release_assets {
24+
repo="$1"
25+
version="$2"
26+
args=(
27+
-sSL
28+
--header "Accept: application/vnd.github+json"
29+
)
30+
[ -n "${INPUT_GITHUB_TOKEN}" ] && args+=(--header "Authorization: Bearer ${INPUT_GITHUB_TOKEN}")
31+
curl "${args[@]}" "https://api.github.com/repos/$repo/releases${version}" | jq '.assets[] | { name: .name, download_url: .browser_download_url }'
32+
}
33+
34+
function install_release {
35+
repo="$1"
36+
version="$2"
37+
binary="$3-linux-amd64"
38+
checksum="$4"
39+
release_assets="$(get_release_assets "${repo}" "${version}")"
40+
41+
curl -sLo "${binary}" "$(echo "${release_assets}" | jq -r ". | select(.name == \"${binary}\") | .download_url")"
42+
curl -sLo "$3-checksums.txt" "$(echo "${release_assets}" | jq -r ". | select(.name | contains(\"$checksum\")) | .download_url")"
43+
44+
grep "${binary}" "$3-checksums.txt" | sha256sum -c -
45+
install "${binary}" "/usr/local/bin/${3}"
46+
}
2447

25-
grep commenter-linux-amd64 commenter.checksums > commenter-linux-amd64.checksum
26-
sha256sum -c commenter-linux-amd64.checksum
27-
install commenter-linux-amd64 /usr/local/bin/commenter
48+
install_release aquasecurity/tfsec "${TFSEC_VERSION}" tfsec tfsec_checksums.txt
49+
install_release aquasecurity/tfsec-pr-commenter-action "${COMMENTER_VERSION}" commenter checksums.txt
2850

2951
if [ -n "${GITHUB_WORKSPACE}" ]; then
3052
cd "${GITHUB_WORKSPACE}" || exit
@@ -41,5 +63,5 @@ if [ -n "${INPUT_TFSEC_FORMATS}" ]; then
4163
TFSEC_OUT_OPTION="${TFSEC_OUT_OPTION%.*}"
4264
fi
4365

44-
tfsec --out=${TFSEC_OUT_OPTION} --format=${TFSEC_FORMAT_OPTION} --soft-fail ${TFSEC_ARGS_OPTION} "${INPUT_WORKING_DIRECTORY}"
66+
tfsec --out=${TFSEC_OUT_OPTION} --format="${TFSEC_FORMAT_OPTION}" --soft-fail "${TFSEC_ARGS_OPTION}" "${INPUT_WORKING_DIRECTORY}"
4567
commenter

0 commit comments

Comments
 (0)