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

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