Context
After having been able to add a GitLab personal access token using bash with:
add_gitlab_personal_access_token(){
local gitlab_username="$1"
local token_name="$2"
local personal_access_token="$3"
local docker_container_id="$4"
output="$(sudo docker exec -i "$docker_container_id" bash -c "gitlab-rails runner \"token = User.find_by_username('$gitlab_username').personal_access_tokens.create(scopes: [:api], name: '$token_name'); token.set_token('$personal_access_token'); token.save! \"")"
}
Attempts I
Using the docker exec
and bash -c
command as used in setting the token allows one to revoke the token:
revoke_token(){
local docker_container_id="$1"
local token="sometokenpersonalgitlabtoken"
output="$(sudo docker exec -i "$docker_container_id" bash -c "gitlab-rails runner \"PersonalAccessToken.find_by_token('$token').revoke! \"")"
echo "output=$output"
}
Issue
However, after trying to add the token again, it is still in GitLab, and GitLab returns:
DETAIL: Key (token_digest)=(somelongkeysasdfasdfasdfkeyending=) already exists.
so the revoke method does not actually delete the token, it merely revokes it.
Question
I was wondering how: *How can one delete the GitLab personal token in the docker container using bash (based on the $token_name
)?