Skip to content

Commit

Permalink
de-coupling logic
Browse files Browse the repository at this point in the history
  • Loading branch information
rtomyj committed Mar 17, 2024
1 parent 3addf45 commit 3339347
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
11 changes: 0 additions & 11 deletions aws-cert-update.sh
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
11 changes: 11 additions & 0 deletions aws-secrets-sync.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 3339347

Please sign in to comment.