Skip to content

Commit 4ec1d75

Browse files
authored
ci: troubleshooting token validation error (#1699)
This verbose logging will clarify the root cause of this 403 error: "curl: (22) The requested URL returned error: 403" Also, the entire script returned success because the "exit 1" was called within the piped while loop. For it to work, we need `-o pipefail`.
1 parent 4dada48 commit 4ec1d75

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

infra/test/token-access-test.yaml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ steps:
2222
waitFor: ['-']
2323
script: |
2424
#!/usr/bin/env bash
25+
26+
# "-o pipefail" stops execution of the piped command fails, especially
27+
# the body of the while loop in this case.
28+
set -eo pipefail
2529
echo "Your project ID is $PROJECT_ID"
2630
echo "gcloud config get-value core/account:"
2731
gcloud config get-value core/account
@@ -36,11 +40,16 @@ steps:
3640
exit 1
3741
fi
3842
cat infra/prod/repositories.yaml | grep '^\s*-\s*name:' |awk '{print $NF}' |tr -d '"' | while read -r repo_name; do
39-
echo "Validating credentials for repository: $repo_name"
43+
echo "Validating credentials for repository: ${repo_name}"
4044
GITHUB_TOKEN=$(gcloud secrets versions access latest --secret="${repo_name}-github-token")
41-
curl --fail -H "Authorization: token ${GITHUB_TOKEN}" "https://api.github.com/repos/googleapis/${repo_name}/collaborators/${ROBOT_ACCOUNT}/permission"
45+
if [[ -z "${GITHUB_TOKEN}" ]]; then
46+
echo "GitHub token for repository ${repo_name} is not set."
47+
exit 1
48+
fi
49+
permission_url="https://api.github.com/repos/googleapis/${repo_name}/collaborators/${ROBOT_ACCOUNT}/permission"
50+
curl --fail -H "Authorization: token ${GITHUB_TOKEN}" "${permission_url}"
4251
if [[ $? -ne 0 ]]; then
43-
echo "Failed to validate credentials for repository: $repo_name"
52+
echo "Failed to validate credentials for repository: ${repo_name} via ${permission_url}"
4453
exit 1
4554
fi
4655
done

0 commit comments

Comments
 (0)