Blame SOURCES/bz1759115-aws-vpc-route53-3-awscli-property.patch

42b704
From 01d3e07ec6c5240633633cb56d1bc915190f40a5 Mon Sep 17 00:00:00 2001
42b704
From: Brandon Perkins <bperkins@redhat.com>
42b704
Date: Fri, 24 Apr 2020 18:19:19 -0400
42b704
Subject: [PATCH 1/4] Replace aws command line with OCF_RESKEY_awscli property.
42b704
42b704
---
42b704
 heartbeat/aws-vpc-move-ip | 6 +++---
42b704
 1 file changed, 3 insertions(+), 3 deletions(-)
42b704
42b704
diff --git a/heartbeat/aws-vpc-move-ip b/heartbeat/aws-vpc-move-ip
42b704
index 26ca6007d..af697adbe 100755
42b704
--- a/heartbeat/aws-vpc-move-ip
42b704
+++ b/heartbeat/aws-vpc-move-ip
42b704
@@ -159,14 +159,14 @@ END
42b704
 execute_cmd_as_role(){
42b704
 	cmd=$1
42b704
 	role=$2
42b704
-	output="$(aws sts assume-role --role-arn $role --role-session-name AWSCLI-RouteTableUpdate --profile $OCF_RESKEY_profile --output=text)"
42b704
+	output="$($OCF_RESKEY_awscli sts assume-role --role-arn $role --role-session-name AWSCLI-RouteTableUpdate --profile $OCF_RESKEY_profile --output=text)"
42b704
 	export AWS_ACCESS_KEY_ID="$(echo $output | awk -F" " '$4=="CREDENTIALS" {print $5}')"
42b704
 	export AWS_SECRET_ACCESS_KEY="$(echo $output | awk -F" " '$4=="CREDENTIALS" {print $7}')"
42b704
 	export AWS_SESSION_TOKEN="$(echo $output | awk -F" " '$4=="CREDENTIALS" {print $8}')"
42b704
 
42b704
 	#Execute command
42b704
 	ocf_log debug "Assumed Role ${role}"
42b704
-	ocf_log debug "$(aws sts get-caller-identity)"
42b704
+	ocf_log debug "$($OCF_RESKEY_awscli sts get-caller-identity)"
42b704
 	ocf_log debug "executing command: $cmd"
42b704
 	response="$($cmd)"
42b704
 	unset output AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN
42b704
@@ -181,7 +181,7 @@ ec2ip_set_address_param_compat(){
42b704
 }
42b704
 
42b704
 ec2ip_validate() {
42b704
-	for cmd in aws ip curl; do
42b704
+	for cmd in $OCF_RESKEY_awscli ip curl; do
42b704
 		check_binary "$cmd"
42b704
 	done
42b704
 
42b704
42b704
From 20466ba91c21a489303774ac9a1f5f5fd7b86f12 Mon Sep 17 00:00:00 2001
42b704
From: Brandon Perkins <bperkins@redhat.com>
42b704
Date: Fri, 24 Apr 2020 18:20:17 -0400
42b704
Subject: [PATCH 2/4] - Replace aws command line with OCF_RESKEY_awscli
42b704
 property. - Add OCF_RESKEY_awscli and OCF_RESKEY_profile default variables. -
42b704
 Add awscli (Path to AWS CLI tools) parameter. - Remove required attribute on
42b704
 profile parameter. - Replace --profile $OCF_RESKEY_profile with
42b704
 AWS_PROFILE_OPT.
42b704
42b704
---
42b704
 heartbeat/aws-vpc-route53.in | 71 ++++++++++++++++++++++--------------
42b704
 1 file changed, 43 insertions(+), 28 deletions(-)
42b704
42b704
diff --git a/heartbeat/aws-vpc-route53.in b/heartbeat/aws-vpc-route53.in
42b704
index ca6556951..3042b345b 100644
42b704
--- a/heartbeat/aws-vpc-route53.in
42b704
+++ b/heartbeat/aws-vpc-route53.in
42b704
@@ -43,11 +43,16 @@
42b704
 : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
42b704
 . ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
42b704
 
42b704
+# Defaults
42b704
+OCF_RESKEY_awscli_default="/usr/bin/aws"
42b704
+OCF_RESKEY_profile_default="default"
42b704
 OCF_RESKEY_hostedzoneid_default=""
42b704
 OCF_RESKEY_fullname_default=""
42b704
 OCF_RESKEY_ip_default="local"
42b704
 OCF_RESKEY_ttl_default=10
42b704
 
42b704
+: ${OCF_RESKEY_awscli=${OCF_RESKEY_awscli_default}}
42b704
+: ${OCF_RESKEY_profile=${OCF_RESKEY_profile_default}}
42b704
 : ${OCF_RESKEY_hostedzoneid:=${OCF_RESKEY_hostedzoneid_default}}
42b704
 : ${OCF_RESKEY_fullname:=${OCF_RESKEY_fullname_default}}
42b704
 : ${OCF_RESKEY_ip:=${OCF_RESKEY_ip_default}}
42b704
@@ -103,7 +108,35 @@ primitive res_route53 ocf:heartbeat:aws-vpc-route53 \
42b704
 		meta target-role=Started
42b704
 </longdesc>
42b704
 <shortdesc lang="en">Update Route53 VPC record for AWS EC2</shortdesc>
42b704
+
42b704
 <parameters>
42b704
+<parameter name="awscli">
42b704
+<longdesc lang="en">
42b704
+Path to command line tools for AWS
42b704
+</longdesc>
42b704
+<shortdesc lang="en">Path to AWS CLI tools</shortdesc>
42b704
+<content type="string" default="${OCF_RESKEY_awscli_default}" />
42b704
+</parameter>
42b704
+
42b704
+<parameter name="profile">
42b704
+<longdesc lang="en">
42b704
+The name of the AWS CLI profile of the root account. This
42b704
+profile will have to use the "text" format for CLI output.
42b704
+The file /root/.aws/config should have an entry which looks
42b704
+like:
42b704
+
42b704
+  [profile cluster]
42b704
+	region = us-east-1
42b704
+	output = text
42b704
+
42b704
+"cluster" is the name which has to be used in the cluster
42b704
+configuration. The region has to be the current one. The
42b704
+output has to be "text".
42b704
+</longdesc>
42b704
+<shortdesc lang="en">AWS Profile Name</shortdesc>
42b704
+<content type="string" default="${OCF_RESKEY_profile_default}" />
42b704
+</parameter>
42b704
+
42b704
 <parameter name="hostedzoneid" required="1">
42b704
 <longdesc lang="en">
42b704
 Hosted zone ID of Route 53. This is the table of
42b704
@@ -112,6 +145,7 @@ the Route 53 record.
42b704
 <shortdesc lang="en">AWS hosted zone ID</shortdesc>
42b704
 <content type="string" default="${OCF_RESKEY_hostedzoneid_default}" />
42b704
 </parameter>
42b704
+
42b704
 <parameter name="fullname" required="1">
42b704
 <longdesc lang="en">
42b704
 The full name of the service which will host the IP address.
42b704
@@ -121,6 +155,7 @@ Note: The trailing dot is important to Route53!
42b704
 <shortdesc lang="en">Full service name</shortdesc>
42b704
 <content type="string" default="${OCF_RESKEY_fullname_default}" />
42b704
 </parameter>
42b704
+
42b704
 <parameter name="ip" required="0">
42b704
 <longdesc lang="en">
42b704
 IP (local (default), public or secondary private IP address (e.g. 10.0.0.1).
42b704
@@ -130,6 +165,7 @@ A secondary private IP can be setup with the awsvip agent.
42b704
 <shortdesc lang="en">Type of IP or secondary private IP address (local, public or e.g. 10.0.0.1)</shortdesc>
42b704
 <content type="string" default="${OCF_RESKEY_ip_default}" />
42b704
 </parameter>
42b704
+
42b704
 <parameter name="ttl" required="0">
42b704
 <longdesc lang="en">
42b704
 Time to live for Route53 ARECORD
42b704
@@ -137,25 +173,8 @@ Time to live for Route53 ARECORD
42b704
 <shortdesc lang="en">ARECORD TTL</shortdesc>
42b704
 <content type="string" default="${OCF_RESKEY_ttl_default}" />
42b704
 </parameter>
42b704
-<parameter name="profile" required="1">
42b704
-<longdesc lang="en">
42b704
-The name of the AWS CLI profile of the root account. This
42b704
-profile will have to use the "text" format for CLI output.
42b704
-The file /root/.aws/config should have an entry which looks
42b704
-like:
42b704
-
42b704
-  [profile cluster]
42b704
-	region = us-east-1
42b704
-	output = text
42b704
-
42b704
-"cluster" is the name which has to be used in the cluster
42b704
-configuration. The region has to be the current one. The
42b704
-output has to be "text".
42b704
-</longdesc>
42b704
-<shortdesc lang="en">AWS Profile Name</shortdesc>
42b704
-<content type="string" default="" />
42b704
-</parameter>
42b704
 </parameters>
42b704
+
42b704
 <actions>
42b704
 <action name="start" timeout="180s" />
42b704
 <action name="stop" timeout="180s" />
42b704
@@ -198,17 +217,13 @@ r53_validate() {
42b704
 	[[ -z "$OCF_RESKEY_ttl" ]] && ocf_log error "TTL not set $OCF_RESKEY_ttl!" && exit $OCF_ERR_CONFIGURED
42b704
 
42b704
 	ocf_log debug "Testing aws command"
42b704
-	aws --version 2>&1
42b704
+	$OCF_RESKEY_awscli --version 2>&1
42b704
 	if [ "$?" -gt 0 ]; then
42b704
 		ocf_log error "Error while executing aws command as user root! Please check if AWS CLI tools (Python flavor) are properly installed and configured." && exit $OCF_ERR_INSTALLED
42b704
 	fi
42b704
 	ocf_log debug "ok"
42b704
 
42b704
-	if [ -n "$OCF_RESKEY_profile" ]; then
42b704
-		AWS_PROFILE_OPT="--profile $OCF_RESKEY_profile --cli-connect-timeout 10"
42b704
-	else
42b704
-		AWS_PROFILE_OPT="--profile default --cli-connect-timeout 10"
42b704
-	fi
42b704
+	AWS_PROFILE_OPT="--profile $OCF_RESKEY_profile --cli-connect-timeout 10"
42b704
 
42b704
 	return $OCF_SUCCESS
42b704
 }
42b704
@@ -261,7 +276,7 @@ r53_monitor() {
42b704
 	#
42b704
 	if [ "$__OCF_ACTION" = "start" ] || ocf_is_probe ; then
42b704
 		#
42b704
-		cmd="aws $AWS_PROFILE_OPT route53 list-resource-record-sets --hosted-zone-id $OCF_RESKEY_hostedzoneid --query ResourceRecordSets[?Name=='$OCF_RESKEY_fullname']"
42b704
+		cmd="$OCF_RESKEY_awscli $AWS_PROFILE_OPT route53 list-resource-record-sets --hosted-zone-id $OCF_RESKEY_hostedzoneid --query ResourceRecordSets[?Name=='$OCF_RESKEY_fullname']"
42b704
 		ocf_log info "Route53 Agent Starting or probing - executing monitoring API call: $cmd"
42b704
 		CLIRES="$($cmd 2>&1)"
42b704
 		rc=$?
42b704
@@ -293,7 +308,7 @@ r53_monitor() {
42b704
 		#
42b704
 		if  [[ ! $ARECORD =~ $IPREGEX ]] || [ $rc -ne 0 ]; then
42b704
 			ocf_log info "Fallback to Route53 API query due to DNS resolution failure"
42b704
-			cmd="aws $AWS_PROFILE_OPT route53 list-resource-record-sets --hosted-zone-id $OCF_RESKEY_hostedzoneid --query ResourceRecordSets[?Name=='$OCF_RESKEY_fullname']"
42b704
+			cmd="$OCF_RESKEY_awscli $AWS_PROFILE_OPT route53 list-resource-record-sets --hosted-zone-id $OCF_RESKEY_hostedzoneid --query ResourceRecordSets[?Name=='$OCF_RESKEY_fullname']"
42b704
 			ocf_log debug "executing monitoring API call: $cmd"
42b704
 			CLIRES="$($cmd 2>&1)"
42b704
 			rc=$?
42b704
@@ -372,7 +387,7 @@ _update_record() {
42b704
 		  ]
42b704
 	}
42b704
 	EOF
42b704
-	cmd="aws --profile $OCF_RESKEY_profile route53 change-resource-record-sets --hosted-zone-id $OCF_RESKEY_hostedzoneid --change-batch file://$ROUTE53RECORD "
42b704
+	cmd="$OCF_RESKEY_awscli $AWS_PROFILE_OPT route53 change-resource-record-sets --hosted-zone-id $OCF_RESKEY_hostedzoneid --change-batch file://$ROUTE53RECORD "
42b704
 	ocf_log debug "Executing command: $cmd"
42b704
 	CLIRES="$($cmd 2>&1)"
42b704
 	rc=$?
42b704
@@ -392,7 +407,7 @@ _update_record() {
42b704
 	MYSECONDS=20
42b704
 	while [ "$STATUS" = 'PENDING' ]; do
42b704
 		sleep $MYSECONDS
42b704
-		STATUS="$(aws --profile $OCF_RESKEY_profile route53 get-change --id $CHANGEID | grep CHANGEINFO | awk -F'\t' '{ print $4 }' |cut -d'"' -f 2 )"
42b704
+		STATUS="$($OCF_RESKEY_awscli $AWS_PROFILE_OPT route53 get-change --id $CHANGEID | grep CHANGEINFO | awk -F'\t' '{ print $4 }' |cut -d'"' -f 2 )"
42b704
 		ocf_log debug "Waited for $MYSECONDS seconds and checked execution of Route 53 update status: $STATUS "
42b704
 	done
42b704
 }
42b704
42b704
From 113bee3ae17a8d610edc0e3879b56e96efbe8b31 Mon Sep 17 00:00:00 2001
42b704
From: Brandon Perkins <bperkins@redhat.com>
42b704
Date: Mon, 27 Apr 2020 11:08:27 -0400
42b704
Subject: [PATCH 3/4] Move AWS_PROFILE_OPT before the start/stop/etc and after
42b704
 the usage/meta-data case statements.
42b704
42b704
---
42b704
 heartbeat/aws-vpc-route53.in | 7 +++++--
42b704
 1 file changed, 5 insertions(+), 2 deletions(-)
42b704
42b704
diff --git a/heartbeat/aws-vpc-route53.in b/heartbeat/aws-vpc-route53.in
42b704
index 3042b345b..ee4f8afcb 100644
42b704
--- a/heartbeat/aws-vpc-route53.in
42b704
+++ b/heartbeat/aws-vpc-route53.in
42b704
@@ -223,8 +223,6 @@ r53_validate() {
42b704
 	fi
42b704
 	ocf_log debug "ok"
42b704
 
42b704
-	AWS_PROFILE_OPT="--profile $OCF_RESKEY_profile --cli-connect-timeout 10"
42b704
-
42b704
 	return $OCF_SUCCESS
42b704
 }
42b704
 
42b704
@@ -423,6 +421,11 @@ case $__OCF_ACTION in
42b704
 		metadata
42b704
 		exit $OCF_SUCCESS
42b704
 		;;
42b704
+esac
42b704
+
42b704
+AWS_PROFILE_OPT="--profile $OCF_RESKEY_profile --cli-connect-timeout 10"
42b704
+
42b704
+case $__OCF_ACTION in
42b704
 	start)
42b704
 		r53_validate || exit $?
42b704
 		r53_start
42b704
42b704
From 8f46c90a73731be0c8f99adcd718f7cfc2d52002 Mon Sep 17 00:00:00 2001
42b704
From: Brandon Perkins <bperkins@redhat.com>
42b704
Date: Mon, 27 Apr 2020 11:54:22 -0400
42b704
Subject: [PATCH 4/4] Move AWS_PROFILE_OPT before functions and after
42b704
 initialization.
42b704
42b704
---
42b704
 heartbeat/aws-vpc-route53.in | 10 +++++-----
42b704
 1 file changed, 5 insertions(+), 5 deletions(-)
42b704
42b704
diff --git a/heartbeat/aws-vpc-route53.in b/heartbeat/aws-vpc-route53.in
42b704
index ee4f8afcb..b06b93726 100644
42b704
--- a/heartbeat/aws-vpc-route53.in
42b704
+++ b/heartbeat/aws-vpc-route53.in
42b704
@@ -37,6 +37,7 @@
42b704
 #
42b704
 # Mar. 15, 2017, vers 1.0.2
42b704
 
42b704
+
42b704
 #######################################################################
42b704
 # Initialization:
42b704
 
42b704
@@ -57,9 +58,13 @@ OCF_RESKEY_ttl_default=10
42b704
 : ${OCF_RESKEY_fullname:=${OCF_RESKEY_fullname_default}}
42b704
 : ${OCF_RESKEY_ip:=${OCF_RESKEY_ip_default}}
42b704
 : ${OCF_RESKEY_ttl:=${OCF_RESKEY_ttl_default}}
42b704
+#######################################################################
42b704
+
42b704
 
42b704
+AWS_PROFILE_OPT="--profile $OCF_RESKEY_profile --cli-connect-timeout 10"
42b704
 #######################################################################
42b704
 
42b704
+
42b704
 usage() {
42b704
 	cat <<-EOT
42b704
 	usage: $0 {start|stop|status|monitor|validate-all|meta-data}
42b704
@@ -421,11 +426,6 @@ case $__OCF_ACTION in
42b704
 		metadata
42b704
 		exit $OCF_SUCCESS
42b704
 		;;
42b704
-esac
42b704
-
42b704
-AWS_PROFILE_OPT="--profile $OCF_RESKEY_profile --cli-connect-timeout 10"
42b704
-
42b704
-case $__OCF_ACTION in
42b704
 	start)
42b704
 		r53_validate || exit $?
42b704
 		r53_start