Skip to content

Instantly share code, notes, and snippets.

@saedalavinia
Last active February 13, 2019 15:26
Show Gist options
  • Save saedalavinia/5103f12d3651f6431d183416237fe617 to your computer and use it in GitHub Desktop.
Save saedalavinia/5103f12d3651f6431d183416237fe617 to your computer and use it in GitHub Desktop.
Automate Concourse LDAP Login using fly
## Variables required
CONCOURSE_URL="https://my.ci.com"
CONCOURSE_USER="a_user"
CONCOURSE_PASSWORD="a_password"
CONCOURSE_TEAM="some_team"
CONCOURSE_TARGET=mytarget
## Create a file named token that will be used to read and write tokens
touch token
## extract the LDAP authentication url and write to token file
LDAP_AUTH_URL=$CONCOURSE_URL$(curl -b token -c token -L "$CONCOURSE_URL/sky/login" -s | grep "/sky/issuer/auth/ldap?" | awk -F'"' '{print $2}')
# login using username and password while writing to the token file
curl -s -o /dev/null -b token -c token -L --data-urlencode "login=$CONCOURSE_USER" --data-urlencode "password=$CONCOURSE_PASSWORD" "$LDAP_AUTH_URL"
# Extract Bearer Token
ATC_BEARER_TOKEN=$(cat token | grep -o -P '(?<=Bearer\ ).*(?=\")')
# Build your .flyrc
cat <<ENDOFSCRIPT >> ~/.flyrc
targets:
$CONCOURSE_TARGET:
api: $CONCOURSE_URL
team: $CONCOURSE_TEAM
token:
type: Bearer
value: $ATC_BEARER_TOKEN
ENDOFSCRIPT
fly -t $CONCOURSE_TARGET <your_command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment