Skip to content

Commit 2e5aefb

Browse files
committed
Terraform managed file
1 parent 80e440e commit 2e5aefb

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

.ci/.ci-utility-files/common.sh

+49-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export DEBIAN_FRONTEND=noninteractive
4747
# if close to expiry. With credentials being handled by the doormat
4848
# action now, this is no longer needed but remains in case it's
4949
# needed for some reason in the future.
50-
function deprecated_aws() {
50+
function aws() {
5151
# Grab the actual aws cli path
5252
if ! aws_path="$(which aws)"; then
5353
(>&2 echo "AWS error: failed to locate aws cli executable")
@@ -699,6 +699,18 @@ function sns_publish() {
699699
local product="${1}"
700700
local region="${2}"
701701

702+
if [ -z "${RELEASE_AWS_ACCESS_KEY_ID}" ]; then
703+
fail "Missing AWS access key ID for SNS publish"
704+
fi
705+
706+
if [ -z "${RELEASE_AWS_SECRET_ACCESS_KEY}" ]; then
707+
fail "Missing AWS access key for SNS publish"
708+
fi
709+
710+
if [ -z "${RELEASE_AWS_ASSUME_ROLE_ARN}" ]; then
711+
fail "Missing AWS role ARN for SNS publish"
712+
fi
713+
702714
if [ -z "${product}" ]; then
703715
product="${repo_name}"
704716
fi
@@ -707,12 +719,48 @@ function sns_publish() {
707719
region="us-east-1"
708720
fi
709721

722+
local core_id core_key old_id old_key old_token old_role old_expiration old_region
723+
if [ -n "${AWS_ACCESS_KEY_ID}" ]; then
724+
# Store current credentials to be restored
725+
core_id="${CORE_AWS_ACCESS_KEY_ID}"
726+
core_key="${CORE_AWS_SECRET_ACCESS_KEY}"
727+
old_id="${AWS_ACCESS_KEY_ID}"
728+
old_key="${AWS_SECRET_ACCESS_KEY}"
729+
old_token="${AWS_SESSION_TOKEN}"
730+
old_role="${AWS_ASSUME_ROLE_ARN}"
731+
old_expiration="${AWS_SESSION_EXPIRATION}"
732+
old_region="${AWS_REGION}"
733+
unset AWS_SESSION_TOKEN
734+
fi
735+
736+
export AWS_ACCESS_KEY_ID="${RELEASE_AWS_ACCESS_KEY_ID}"
737+
export AWS_SECRET_ACCESS_KEY="${RELEASE_AWS_SECRET_ACCESS_KEY}"
738+
export AWS_ASSUME_ROLE_ARN="${RELEASE_AWS_ASSUME_ROLE_ARN}"
739+
export AWS_REGION="${region}"
740+
741+
# Validate the creds properly assume role and function
742+
wrap aws configure list \
743+
"Failed to reconfigure AWS credentials for release notification"
744+
745+
# Now send the release notification
710746
echo "Sending notification to update package repositories... "
711747
message=$(jq --null-input --arg product "$product" '{"product": $product}')
712748
wrap_stream aws sns publish --region "${region}" --topic-arn "${HC_RELEASES_PROD_SNS_TOPIC}" --message "${message}" \
713749
"Failed to send SNS message for package repository update"
714750
echo "complete!"
715751

752+
# Before we finish restore the previously set credentials if we unset them
753+
if [ -n "${core_id}" ]; then
754+
export CORE_AWS_ACCESS_KEY_ID="${core_id}"
755+
export CORE_AWS_SECRET_ACCESS_KEY="${core_key}"
756+
export AWS_ACCESS_KEY_ID="${old_id}"
757+
export AWS_SECRET_ACCESS_KEY="${old_key}"
758+
export AWS_SESSION_TOKEN="${old_token}"
759+
export AWS_ASSUME_ROLE_ARN="${old_role}"
760+
export AWS_SESSION_EXPIRATION="${old_expiration}"
761+
export AWS_REGION="${old_region}"
762+
fi
763+
716764
return 0
717765
}
718766

0 commit comments

Comments
 (0)