From 33393474a1d569a3680c47ae454032c3c4fe2fd4 Mon Sep 17 00:00:00 2001 From: Javi <8519394+rtomyj@users.noreply.github.com> Date: Sun, 17 Mar 2024 16:50:22 -0500 Subject: [PATCH] de-coupling logic --- aws-cert-update.sh | 11 ----------- aws-secrets-sync.sh | 11 +++++++++++ 2 files changed, 11 insertions(+), 11 deletions(-) create mode 100644 aws-secrets-sync.sh diff --git a/aws-cert-update.sh b/aws-cert-update.sh index df17adf..09d60c8 100644 --- a/aws-cert-update.sh +++ b/aws-cert-update.sh @@ -1,16 +1,5 @@ -SECRET_MANAGER_ID="/project-next/podcast-api/ssl" HOST_NAME="next-podcast-api.com" -# AWS will remove new line characters, which are needed in below files - converting to base64 at the time of saving will resolve this issue -SSL_PRIVATE_KEY=$(base64 certs/private.key) -SSL_CA_BUNDLE_CRT=$(base64 certs/ca_bundle.crt) -SSL_CERTIFICATE_CRT=$(base64 certs/certificate.crt) - -# take current secrets and update the values associated with SSL files - then increment the secret version using today's date -CERT_FILE_VALUES="{\"SSL_PRIVATE_KEY\": \"$SSL_PRIVATE_KEY\", \"SSL_CA_BUNDLE_CRT\": \"$SSL_CA_BUNDLE_CRT\", \"SSL_CERTIFICATE_CRT\": \"$SSL_CERTIFICATE_CRT\"}" -UPDATED_SECRETS_STRING=$(aws secretsmanager get-secret-value --secret-id "$SECRET_MANAGER_ID" --region us-east-2 | jq -r '.SecretString' | jq ". + $CERT_FILE_VALUES") -aws secretsmanager put-secret-value --secret-id "$SECRET_MANAGER_ID" --region us-east-2 --secret-string "$UPDATED_SECRETS_STRING" --no-cli-pager --version-stages "$(date +%F)" "AWSCURRENT" - # get ARN using the hostname, update certs using ARN ARN=$(aws acm list-certificates --query 'CertificateSummaryList[*].[CertificateArn,DomainName]' --output text | grep -F "$HOST_NAME" | cut -f 1) echo "Updating $ARN certificate info" diff --git a/aws-secrets-sync.sh b/aws-secrets-sync.sh new file mode 100644 index 0000000..47e4f5b --- /dev/null +++ b/aws-secrets-sync.sh @@ -0,0 +1,11 @@ +SECRET_MANAGER_ID="/project-next/podcast-api/ssl" + +# AWS will remove new line characters, which are needed in below files - converting to base64 at the time of saving will resolve this issue +SSL_PRIVATE_KEY=$(base64 certs/private.key) +SSL_CA_BUNDLE_CRT=$(base64 certs/ca_bundle.crt) +SSL_CERTIFICATE_CRT=$(base64 certs/certificate.crt) + +# take current secrets and update the values associated with SSL files - then increment the secret version using today's date +CERT_FILE_VALUES="{\"SSL_PRIVATE_KEY\": \"$SSL_PRIVATE_KEY\", \"SSL_CA_BUNDLE_CRT\": \"$SSL_CA_BUNDLE_CRT\", \"SSL_CERTIFICATE_CRT\": \"$SSL_CERTIFICATE_CRT\"}" +UPDATED_SECRETS_STRING=$(aws secretsmanager get-secret-value --secret-id "$SECRET_MANAGER_ID" --region us-east-2 | jq -r '.SecretString' | jq ". + $CERT_FILE_VALUES") +aws secretsmanager put-secret-value --secret-id "$SECRET_MANAGER_ID" --region us-east-2 --secret-string "$UPDATED_SECRETS_STRING" --no-cli-pager --version-stages "$(date +%F)" "AWSCURRENT"