From 901abd15d010e804aa6dd270f1470651aeff74bd Mon Sep 17 00:00:00 2001 From: RouxAntoine Date: Sun, 25 Aug 2024 20:37:19 +0200 Subject: [PATCH] feature: protect ca addition from duplicate --- action.yml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index ff0f630..e3fcff4 100644 --- a/action.yml +++ b/action.yml @@ -8,7 +8,7 @@ inputs: description: 'root certificate to add to the truststore' required: true alias-name: - description: "alias name of the new added certificate" + description: "alias name of the new added certificate, if not provided a random name is generate, beware with random name generated certificate is always inserted even if it already exist" required: false default: "" store-path: @@ -49,5 +49,14 @@ runs: - name: Add certificate ${{ steps.generate-alias-name.outputs.alias-name }} to truststore shell: bash + env: + does_not_exist_message: "does not exist" run: | - echo "${{ inputs.ca-cert }}" | keytool -import -noprompt -trustcacerts -alias ${{ steps.generate-alias-name.outputs.alias-name }} -keystore ${{ inputs.store-path }} -storepass ${{ inputs.store-password }} \ No newline at end of file + already_exists=$(keytool -list -alias ${{ steps.generate-alias-name.outputs.alias-name }} -keystore ${{ inputs.store-path }} -storepass ${{ inputs.store-password }} 2>/dev/null | grep "${{ env.does_not_exist_message }}" || true) + + if [ ! -z "$already_exists" ]; + then + echo "${{ inputs.ca-cert }}" | keytool -import -noprompt -trustcacerts -alias ${{ steps.generate-alias-name.outputs.alias-name }} -keystore ${{ inputs.store-path }} -storepass ${{ inputs.store-password }}; + else + echo "Certificate ${{ steps.generate-alias-name.outputs.alias-name }} already contained in the truststore"; + fi \ No newline at end of file