Skip to content

Commit 78b1498

Browse files
authored
feat: authenticate github API calls (#12)
1 parent aae1964 commit 78b1498

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ inputs:
1414
description: 'Optional nancy command. Defaults to "sleuth"'
1515
required: false
1616
default: 'sleuth'
17+
githubToken:
18+
description: 'Optional GitHub token. If not provided, no GitHub token will be used.'
19+
required: false
20+
default: ''
1721
runs:
1822
using: 'docker'
1923
image: 'Dockerfile'

install-nancy.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,23 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17+
acurl() {
18+
curl "$@"
19+
}
20+
if [ -n "${INPUT_GITHUBTOKEN}" ]; then
21+
acurl() {
22+
echo "using authenticated curl"
23+
curl -H "Authorization: Bearer ${INPUT_GITHUBTOKEN}" "$@"
24+
}
25+
fi
26+
1727
desiredVersion="$1"
1828
echo "desired nancy version: ${desiredVersion}"
1929
if [ -z "$desiredVersion" ]; then
2030
>&2 echo "must specify a desiredVersion, like: latest or v1.0.15"
2131
exit 1
2232
elif [[ ${desiredVersion} == "latest" ]]; then
23-
latest_version_is=$(curl --fail -s https://api.github.com/repos/sonatype-nexus-community/nancy/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")')
33+
latest_version_is=$(acurl --fail -s https://api.github.com/repos/sonatype-nexus-community/nancy/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")')
2434
desiredVersion=${latest_version_is}
2535
elif [[ ${desiredVersion:0:1} != "v" ]]; then
2636
>&2 echo "specific nancy version (${desiredVersion}) must start with v, like: v1.0.15"
@@ -29,5 +39,5 @@ fi
2939
# installer filename excludes v from version
3040
sourceUrl="https://github.com/sonatype-nexus-community/nancy/releases/download/${desiredVersion}/nancy_${desiredVersion:1}_linux_amd64.apk"
3141
echo "installing nancy via ${sourceUrl}"
32-
curl --fail -L -o nancy.apk ${sourceUrl}
42+
acurl --fail -L -o nancy.apk "${sourceUrl}"
3343
apk add --no-progress --quiet --no-cache --allow-untrusted nancy.apk

0 commit comments

Comments
 (0)