Skip to content

Commit

Permalink
feat: Request new Runner token if invalid (#425)
Browse files Browse the repository at this point in the history
* Request new Runner token if invalid

* Escape the "%{" sequence

* Fix template error accessing variables
  • Loading branch information
kayman-mk authored Jan 18, 2022
1 parent 36633fa commit 2706c09
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion template/gitlab-runner.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,17 @@ if ! [ -x "$(command -v jq)" ]; then
yum install jq -y
fi

# fetch Runner token from SSM and validate it
token=$(aws ssm get-parameters --names "${secure_parameter_store_runner_token_key}" --with-decryption --region "${secure_parameter_store_region}" | jq -r ".Parameters | .[0] | .Value")
if [[ `echo ${runners_token}` == "__REPLACED_BY_USER_DATA__" && `echo $token` == "null" ]]

valid_token=true
if [[ `echo $token` != "null" ]]
then
valid_token_response=$(curl -s -o /dev/null -w "%%{response_code}" --request POST -L "${runners_gitlab_url}/api/v4/runners/verify" --form "token=$token" )
[[ `echo $valid_token_response` != "200" ]] && valid_token=false
fi

if [[ `echo ${runners_token}` == "__REPLACED_BY_USER_DATA__" && `echo $token` == "null" ]] || [[ `echo $valid_token` == "false" ]]
then
token=$(curl --request POST -L "${runners_gitlab_url}/api/v4/runners" \
--form "token=${gitlab_runner_registration_token}" \
Expand Down

0 comments on commit 2706c09

Please sign in to comment.