bilak
bilak

Reputation: 4942

Jboss cli conditional list-add

with following script I'm able to add provider to my keycloak instance.

embed-server --server-config=standalone.xml
/subsystem=keycloak-server:list-add(name=providers, value=module:com.example.InviteUserRequiredAction)
stop-embedded-server

However when the application is restarted it's added twice (or that many times the server is restarted). I'd like to add the provider only conditionally, but I can't find the way how to query existence of provider that I'm adding.

so finally it could look like:

if (outcome != success) of /subsystem=keycloak-server:here-should-be-the-query
   ...
end-if

Can somebody please tell me how to query the providers with name module:com.example.InviteUserRequiredAction?

Thanks

Upvotes: 0

Views: 717

Answers (1)

bilak
bilak

Reputation: 4942

In the end I've finished with custom script as I wasn't able to find the way with cli only.

#!/bin/bash
REQUIREDACTION=module:com.example.InviteUserRequiredAction
ADDREQUIREDACTION=$(cat <<EOF
embed-server --server-config=standalone.xml
/subsystem=keycloak-server:list-add(name=providers, value=$REQUIREDACTION)
stop-embedded-server
EOF
);

cat <<EOF > script.cli
embed-server --server-config=standalone.xml
/subsystem=keycloak-server:read-attribute(name=providers)
stop-embedded-server
EOF

OUTPUT=`/opt/jboss/keycloak/bin/jboss-cli.sh --file=script.cli`
echo $OUTPUT | grep -q "$REQUIREDACTION"
if [ $? -ne 0 ] ; then
  echo going to add provider $REQUIREDACTION
  echo "$ADDREQUIREDACTION" > script.cli
  /opt/jboss/keycloak/bin/jboss-cli.sh --file=script.cli
else
  echo provider $REQUIREDACTION already exists
fi

Upvotes: 1

Related Questions