diff --git a/helmchart/single-sign-on/templates/cronjob-create-oauth-clients.yaml b/helmchart/single-sign-on/templates/cronjob-create-oauth-clients.yaml index 932808325be1174ed5e06cfaf63f5dd5fbe05e20..39415a277bbd9aec69ce150e76e007020a98bf1b 100644 --- a/helmchart/single-sign-on/templates/cronjob-create-oauth-clients.yaml +++ b/helmchart/single-sign-on/templates/cronjob-create-oauth-clients.yaml @@ -52,30 +52,40 @@ spec: args: - > curl http://{{ $.Release.Name }}-hydra-admin:4445/health/ready \ - --silent \\ - --write-out "\nCheck Hydra health: HTTP %{http_code}" \ - | tail -1 | grep 200 && echo "Hydra is ready to accept requests." && - curl http://{{ $.Release.Name }}-hydra-admin:4445/clients/$CLIENT_NAME \ --silent \ - --write-out "\nRequesting oauth client $CLIENT_NAME: HTTP %{http_code}\n" \ - | tail -1 \ - | grep 404 && - curl --header "Content-Type: application/json" \ - --request POST \ - --data "{\"client_id\": \"$CLIENT_ID\", - \"client_name\": \"$CLIENT_NAME\", - \"client_secret\": \"$CLIENT_SECRET\", - \"client_uri\": \"$CLIENT_URI\", - \"logo_uri\": \"$CLIENT_LOGO_URI\", - \"redirect_uris\": [\"$REDIRECT_URI\"], - \"scope\": \"$SCOPES\", - \"grant_types\": [$GRANT_TYPES\"\"], - \"response_types\": [$RESPONSE_TYPES\"\"], - \"token_endpoint_auth_method\": \"client_secret_post\"}" \ - http://{{ $.Release.Name }}-hydra-admin:4445/clients \ + --write-out "\nCheck Hydra health: HTTP %{http_code}" \ + | tail -1 | grep 200; \ + if [ $? -eq 0 ]; then \ + echo "Hydra is ready to accept requests."; \ + curl http://{{ $.Release.Name }}-hydra-admin:4445/clients/$CLIENT_NAME \ --silent \ - --write-out "\nCreating oauth client $CLIENT_ID: HTTP(%{http_code})\n" \ + --write-out "\nRequesting oauth client $CLIENT_NAME: HTTP %{http_code}\n" \ | tail -1 \ - | grep 201 && - echo "Successfully created $CLIENT_ID" + | grep 404; \ + if [ $? -eq 0 ]; then \ + echo "Client doesn't exist. (Re)creating client..."; \ + curl --header "Content-Type: application/json" \ + --request POST \ + --data "{\"client_id\": \"$CLIENT_ID\", + \"client_name\": \"$CLIENT_NAME\", + \"client_secret\": \"$CLIENT_SECRET\", + \"client_uri\": \"$CLIENT_URI\", + \"logo_uri\": \"$CLIENT_LOGO_URI\", + \"redirect_uris\": [\"$REDIRECT_URI\"], + \"scope\": \"$SCOPES\", + \"grant_types\": [$GRANT_TYPES\"\"], + \"response_types\": [$RESPONSE_TYPES\"\"], + \"token_endpoint_auth_method\": \"client_secret_post\"}" \ + http://{{ $.Release.Name }}-hydra-admin:4445/clients \ + --silent \ + --write-out "\nCreating oauth client $CLIENT_ID: HTTP(%{http_code})\n" \ + | tail -1 \ + | grep 201; \ + if [ $? -eq 0 ]; then echo "Successfully created $CLIENT_ID"; exit 0; \ + else echo "Client creation failed"; exit 1; \ + fi; \ + else echo "Client already exists"; exit 0; \ + fi; \ + else echo "Hydra API not available"; exit 1; \ + fi; {{- end }}