Blame SOURCES/bz1673468-fence_aws-improve-parameter-logic.patch

97bc7e
From 1c2f791b6b2be13bcceaa096df52654164b1f6cb Mon Sep 17 00:00:00 2001
97bc7e
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
97bc7e
Date: Thu, 5 Mar 2020 14:10:29 +0100
97bc7e
Subject: [PATCH] fence_aws: improve connect parameter logic, so region can be
97bc7e
 specified as parameter, while using role or keys from ~/.aws/config
97bc7e
97bc7e
---
97bc7e
 agents/aws/fence_aws.py | 27 +++++++++------------------
97bc7e
 1 file changed, 9 insertions(+), 18 deletions(-)
97bc7e
97bc7e
diff --git a/agents/aws/fence_aws.py b/agents/aws/fence_aws.py
97bc7e
index 74321e8e..4a4d9de2 100644
97bc7e
--- a/agents/aws/fence_aws.py
97bc7e
+++ b/agents/aws/fence_aws.py
97bc7e
@@ -99,24 +99,15 @@
97bc7e
 
97bc7e
 	run_delay(options)
97bc7e
 
97bc7e
-	if "--region" in options and "--access-key" in options and "--secret-key" in options:  
97bc7e
-		region = options["--region"]
97bc7e
-		access_key = options["--access-key"]
97bc7e
-		secret_key = options["--secret-key"]
97bc7e
-		try:
97bc7e
-			conn = boto3.resource('ec2', region_name=region,
97bc7e
-					      aws_access_key_id=access_key,
97bc7e
-					      aws_secret_access_key=secret_key)
97bc7e
-		except:
97bc7e
-			fail_usage("Failed: Unable to connect to AWS. Check your configuration.")
97bc7e
-	else:
97bc7e
-		# If setup with "aws configure" or manually in
97bc7e
-		# ~/.aws/credentials
97bc7e
-		try:
97bc7e
-			conn = boto3.resource('ec2')
97bc7e
-		except:
97bc7e
-			# If any of region/access/secret are missing
97bc7e
-			fail_usage("Failed: Unable to connect to AWS. Check your configuration.")
97bc7e
+	region = options.get("--region")
97bc7e
+	access_key = options.get("--access-key")
97bc7e
+	secret_key = options.get("--secret-key")
97bc7e
+	try:
97bc7e
+		conn = boto3.resource('ec2', region_name=region,
97bc7e
+				      aws_access_key_id=access_key,
97bc7e
+				      aws_secret_access_key=secret_key)
97bc7e
+	except:
97bc7e
+		fail_usage("Failed: Unable to connect to AWS. Check your configuration.")
97bc7e
 
97bc7e
 	# Operate the fencing device
97bc7e
 	result = fence_action(conn, options, set_power_status, get_power_status, get_nodes_list)