Skip to content

Commit

Permalink
Move to using kcadm-wrapper config file so that script is just a scri…
Browse files Browse the repository at this point in the history
…pt and not a template
  • Loading branch information
treydock committed Nov 17, 2024
1 parent 2cd3e8c commit d56cacd
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 20 deletions.
13 changes: 13 additions & 0 deletions files/kcadm-wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

# shellcheck source=/dev/null
. /etc/sysconfig/kcadm-wrapper

EXPIRES=$(/usr/bin/sed -n -r 's|.*"refreshExpiresAt" : ([0-9]*).*|\1|p' "$CONFIG" || echo "0")
NOW=$(/usr/bin/date +%s%3N)

if [ ! -f "$CONFIG" ] || [ "$EXPIRES" -gt "$NOW" ]; then
${KCADM} config credentials --config "$CONFIG" --server "$SERVER" --realm "$REALM" --user "$ADMIN_USER" --password "$PASSWORD"
fi

${KCADM} "$@" --config "$CONFIG"
22 changes: 17 additions & 5 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,29 @@
}
}

# Template uses:
# - $keycloak::install_base
# - $keycloak::admin_user
# - $keycloak::admin_user_password
$wrapper_conf = {
'KCADM' => "${keycloak::install_base}/bin/kcadm.sh",
'CONFIG' => "${keycloak::conf_dir}/kcadm.config",
'SERVER' => $keycloak::wrapper_server,
'REALM' => 'master',
'ADMIN_USER' => $keycloak::admin_user,
'PASSWORD' => $keycloak::admin_user_password,
}
file { '/etc/sysconfig/kcadm-wrapper':
ensure => 'file',
owner => $keycloak::user,
group => $keycloak::group,
mode => '0640',
content => epp('keycloak/shell_vars.epp', { 'vars' => $wrapper_conf }),
}

file { 'kcadm-wrapper.sh':
ensure => 'file',
path => $keycloak::wrapper_path,
owner => $keycloak::user,
group => $keycloak::group,
mode => '0750',
content => template('keycloak/kcadm-wrapper.sh.erb'),
source => 'puppet:///modules/keycloak/kcadm-wrapper.sh',
show_diff => false,
}

Expand Down
1 change: 0 additions & 1 deletion spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@
owner: 'keycloak',
group: 'keycloak',
mode: '0750',
content: %r{.*},
show_diff: 'false',
)
end
Expand Down
14 changes: 0 additions & 14 deletions templates/kcadm-wrapper.sh.erb

This file was deleted.

8 changes: 8 additions & 0 deletions templates/shell_vars.epp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<%- |
Hash[String, String] $vars
| -%>
# This file is managed by Puppet, DO NOT EDIT

<% $vars.each |$key, $value| { -%>
<%= $key %>='<%= $value %>'
<% } -%>

0 comments on commit d56cacd

Please sign in to comment.