Skip to content

Commit 47da0d2

Browse files
authored
fix(create-github-app-token): use temporary file w/ trap for token response (#1474)
fix: use temporary file w/ trap for token response
1 parent 60fadd1 commit 47da0d2

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

actions/create-github-app-token/create_token.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,26 @@ setRandomApp() {
88
echo "Randomly selected GitHub App: ${GITHUB_APP}"
99
}
1010

11+
TEMP_FILE=$(mktemp)
12+
echo "Using temporary file: ${TEMP_FILE}"
13+
trap 'rm -f "${TEMP_FILE}"' EXIT
14+
1115
for attempt in $(seq 1 "${MAX_ATTEMPTS}"); do
1216
echo "Attempt ${attempt} to get GitHub token..."
1317
setRandomApp
14-
RESPONSE=$(curl -sS -w "%{http_code}" -o response.json \
18+
RESPONSE=$(curl -sS -w "%{http_code}" -o "${TEMP_FILE}" \
1519
"${VAULT_URL}/v1/github-app-${GITHUB_APP}/token/${REPOSITORY_NAME}-${REF_SHA}-${PERMISSION_SET}" \
1620
-H "X-Vault-Token: ${VAULT_TOKEN}" \
1721
-H "Proxy-Authorization-Token: Bearer ${GITHUB_JWT_PROXY}" || true)
1822

1923
if [[ "${RESPONSE}" -eq 200 ]]; then
20-
TOKEN=$(jq -r '.data.token' response.json)
24+
TOKEN=$(jq -r '.data.token' "${TEMP_FILE}")
2125
echo "github_token=${TOKEN}" >> "${GITHUB_OUTPUT}"
2226
echo "Create GitHub Token done!"
2327
exit 0
2428
else
2529
echo "Vault request failed (HTTP ${RESPONSE})"
26-
cat response.json || true
30+
cat "${TEMP_FILE}" || true
2731
sleep $((attempt * 5))
2832
fi
2933
done

0 commit comments

Comments
 (0)