Skip to content

Commit

Permalink
Reuse session when running kcadm commands
Browse files Browse the repository at this point in the history
Fixes #327
  • Loading branch information
treydock committed Nov 16, 2024
1 parent 8516850 commit 2cd3e8c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion templates/kcadm-wrapper.sh.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
#!/bin/bash

KCADM="<%= scope['keycloak::install_base'] %>/bin/kcadm.sh"
CONFIG="/root/.keycloak/kcadm.config"
EXPIRES=$(/usr/bin/sed -n -r 's|.*"refreshExpiresAt" : ([0-9]*).*|\1|p' ~/.keycloak/kcadm.config)
NOW=$(/usr/bin/date +%s%3N)

${KCADM} "$@" --no-config --server '<%= scope['keycloak::wrapper_server'] %>' --realm master --user '<%= scope['keycloak::admin_user'] %>' --password '<%= scope['keycloak::admin_user_password'] %>'
if [ ! -f "$CONFIG" ]; then
${KCADM} config credentials --server '<%= scope['keycloak::wrapper_server'] %>' --realm master --user '<%= scope['keycloak::admin_user'] %>' --password '<%= scope['keycloak::admin_user_password'] %>'
elif [ "$EXPIRES" -gt "$NOW" ]; then
${KCADM} config credentials --server '<%= scope['keycloak::wrapper_server'] %>' --realm master --user '<%= scope['keycloak::admin_user'] %>' --password '<%= scope['keycloak::admin_user_password'] %>'
fi

${KCADM} "$@" --server '<%= scope['keycloak::wrapper_server'] %>' --realm master --user '<%= scope['keycloak::admin_user'] %>' --password '<%= scope['keycloak::admin_user_password'] %>'

0 comments on commit 2cd3e8c

Please sign in to comment.