blob: b5eb0a635bb376f1334e05c37c705b33a7b20db3 [file] [log] [blame]
Denis Egorenko96e8b062019-04-03 18:05:50 +04001#!/bin/bash
2
3realm_name='drivetrain-realm'
4realm_user='operations-api'
5realm_usermail='drivetrain-eng@mirantis.com'
6echo "[ Getting Keycloak endpoint ]"
7keycloak_port=$(salt-call pillar.get --out=txt _param:haproxy_keycloak_exposed_port | awk '{print $2}')
Vladimir Khlyunev029b9322021-11-16 16:18:24 +04008internal_address=$(salt-call pillar.get --out=txt _param:docker_default_gateway | awk '{print $2}')
Denis Egorenko96e8b062019-04-03 18:05:50 +04009keycloak_url="http://${internal_address}:${keycloak_port}"
10keycloak_admin_password=$(salt-call pillar.get --out=txt _param:keycloak_admin_password | awk '{print $2}')
11keycloak_user_password=$(salt-call pillar.get --out=txt _param:keycloak_user_password | awk '{print $2}')
12echo "[ Waiting for Keycloak server ]"
13until $(curl --output /dev/null --silent --head --fail ${keycloak_url}); do
14 sleep 2
15done
16
17KCADM="/opt/jboss/keycloak/bin/kcadm.sh"
18keycloak_container=$(docker ps --format '{{.Names}}' --filter 'name=keycloak-server')
19script="""
20$KCADM config credentials --server ${keycloak_url}/auth --realm master --user admin --password ${keycloak_admin_password} ;
21$KCADM create users -r ${realm_name} -s username=${realm_user} -s enabled=true -s emailVerified=true -s firstName=Operations-Service-User -s email=${realm_usermail} ;
22ID=\$($KCADM get users -r ${realm_name} --fields id -q username=${realm_user} -q email=${realm_usermail} | grep id | cut -f 2 -d \":\" | tr -d \"\\\"\" | tr -d \" \") ;
23$KCADM update users/\$ID/reset-password -r ${realm_name} -s type=password -s value=${keycloak_user_password} -s temporary=false -n ;
24"""
25
26docker exec -t ${keycloak_container} /bin/bash -c "${script}"