@@ -47,7 +47,7 @@ export DEBIAN_FRONTEND=noninteractive
47
47
# if close to expiry. With credentials being handled by the doormat
48
48
# action now, this is no longer needed but remains in case it's
49
49
# needed for some reason in the future.
50
- function deprecated_aws () {
50
+ function aws () {
51
51
# Grab the actual aws cli path
52
52
if ! aws_path=" $( which aws) " ; then
53
53
(>&2 echo " AWS error: failed to locate aws cli executable" )
@@ -699,6 +699,18 @@ function sns_publish() {
699
699
local product=" ${1} "
700
700
local region=" ${2} "
701
701
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
+
702
714
if [ -z " ${product} " ]; then
703
715
product=" ${repo_name} "
704
716
fi
@@ -707,12 +719,48 @@ function sns_publish() {
707
719
region=" us-east-1"
708
720
fi
709
721
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
710
746
echo " Sending notification to update package repositories... "
711
747
message=$( jq --null-input --arg product " $product " ' {"product": $product}' )
712
748
wrap_stream aws sns publish --region " ${region} " --topic-arn " ${HC_RELEASES_PROD_SNS_TOPIC} " --message " ${message} " \
713
749
" Failed to send SNS message for package repository update"
714
750
echo " complete!"
715
751
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
+
716
764
return 0
717
765
}
718
766
0 commit comments