Skip to content

Commit 149525d

Browse files
author
Dougal Ballantyne
committed
Fixing issues with credentials in config file
1 parent 4bf2171 commit 149525d

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

cli/cfncluster/cfncluster.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ def create(args):
3535
except ValueError:
3636
pass
3737
capabilities = ["CAPABILITY_IAM"]
38-
cfnconn = boto.cloudformation.connect_to_region(config.region)
38+
cfnconn = boto.cloudformation.connect_to_region(config.region,aws_access_key_id=config.aws_access_key_id,
39+
aws_secret_access_key=config.aws_secret_access_key)
3940
try:
4041
logger.debug((config.template_url, config.parameters))
4142
stack = cfnconn.create_stack(('cfncluster-' + args.cluster_name),template_url=config.template_url,
@@ -68,8 +69,10 @@ def update(args):
6869
stack_name = ('cfncluster-' + args.cluster_name)
6970
config = cfnconfig.CfnClusterConfig(args)
7071
capabilities = ["CAPABILITY_IAM"]
71-
cfnconn = boto.cloudformation.connect_to_region(config.region)
72-
asgconn = boto.ec2.autoscale.connect_to_region(config.region)
72+
cfnconn = boto.cloudformation.connect_to_region(config.region,aws_access_key_id=config.aws_access_key_id,
73+
aws_secret_access_key=config.aws_secret_access_key)
74+
asgconn = boto.ec2.autoscale.connect_to_region(config.region,aws_access_key_id=config.aws_access_key_id,
75+
aws_secret_access_key=config.aws_secret_access_key)
7376
if not args.reset_desired:
7477
temp_resources = []
7578
resources = cfnconn.describe_stack_resources(stack_name)
@@ -117,7 +120,8 @@ def stop(args):
117120

118121
def list(args):
119122
config = cfnconfig.CfnClusterConfig(args)
120-
cfnconn = boto.cloudformation.connect_to_region(config.region)
123+
cfnconn = boto.cloudformation.connect_to_region(config.region,aws_access_key_id=config.aws_access_key_id,
124+
aws_secret_access_key=config.aws_secret_access_key)
121125
try:
122126
stacks = cfnconn.describe_stacks()
123127
for stack in stacks:
@@ -133,7 +137,8 @@ def list(args):
133137
sys.exit(0)
134138

135139
def get_ec2_instances(stack, config):
136-
cfnconn = boto.cloudformation.connect_to_region(config.region)
140+
cfnconn = boto.cloudformation.connect_to_region(config.region,aws_access_key_id=config.aws_access_key_id,
141+
aws_secret_access_key=config.aws_secret_access_key)
137142

138143
temp_resources = []
139144

@@ -154,8 +159,10 @@ def get_ec2_instances(stack, config):
154159
return instances
155160

156161
def get_asg_instances(stack, config):
157-
cfnconn = boto.cloudformation.connect_to_region(config.region)
158-
asgconn = boto.ec2.autoscale.connect_to_region(config.region)
162+
cfnconn = boto.cloudformation.connect_to_region(config.region,aws_access_key_id=config.aws_access_key_id,
163+
aws_secret_access_key=config.aws_secret_access_key)
164+
asgconn = boto.ec2.autoscale.connect_to_region(config.region,aws_access_key_id=config.aws_access_key_id,
165+
aws_secret_access_key=config.aws_secret_access_key)
159166

160167
temp_resources = []
161168

@@ -194,7 +201,8 @@ def instances(args):
194201
def status(args):
195202
stack = ('cfncluster-' + args.cluster_name)
196203
config = cfnconfig.CfnClusterConfig(args)
197-
cfnconn = boto.cloudformation.connect_to_region(config.region)
204+
cfnconn = boto.cloudformation.connect_to_region(config.region,aws_access_key_id=config.aws_access_key_id,
205+
aws_secret_access_key=config.aws_secret_access_key)
198206

199207
try:
200208
status = cfnconn.describe_stacks(stack)[0].stack_status
@@ -235,7 +243,8 @@ def delete(args):
235243
stack = ('cfncluster-' + args.cluster_name)
236244

237245
config = cfnconfig.CfnClusterConfig(args)
238-
cfnconn = boto.cloudformation.connect_to_region(config.region)
246+
cfnconn = boto.cloudformation.connect_to_region(config.region,aws_access_key_id=config.aws_access_key_id,
247+
aws_secret_access_key=config.aws_secret_access_key)
239248
try:
240249
cfnconn.delete_stack(stack)
241250
status = cfnconn.describe_stacks(stack)[0].stack_status
@@ -271,7 +280,8 @@ def delete(args):
271280
def sshmaster(args):
272281
stack = ('cfncluster-' + args.cluster_name)
273282
config = cfnconfig.CfnClusterConfig(args)
274-
cfnconn = boto.cloudformation.connect_to_region(config.region)
283+
cfnconn = boto.cloudformation.connect_to_region(config.region,aws_access_key_id=config.aws_access_key_id,
284+
aws_secret_access_key=config.aws_secret_access_key)
275285
outputs = cfnconn.describe_stacks(stack)[0].outputs
276286
if args.useprivateip:
277287
hostname = [ o for o in outputs if o.key == 'MasterPrivateIP' ][0].value

cli/cfncluster/cfnconfig.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,16 @@ def __init__(self, args):
8787
except ConfigParser.NoOptionError:
8888
self.region = 'us-east-1'
8989

90+
# Check if credentials have been provided in config
91+
try:
92+
self.aws_access_key_id = __config.get('aws', 'aws_access_key_id')
93+
except ConfigParser.NoOptionError:
94+
self.aws_access_key_id=None
95+
try:
96+
self.aws_secret_access_key = __config.get('aws', 'aws_secret_access_key')
97+
except ConfigParser.NoOptionError:
98+
self.aws_secret_access_key=None
99+
90100
# Determine the CloudFormation URL to be used
91101
# Config file or default
92102
try:
@@ -125,7 +135,7 @@ def __init__(self, args):
125135
install_type='InstallType', scheduler='Scheduler', cluster_type='ClusterType',
126136
spot_price='SpotPrice', custom_ami='CustomAMI', pre_install='PreInstallScript',
127137
post_install='PostInstallScript', proxy_server='ProxyServer',
128-
iam_policy='IAMPolicy')
138+
iam_policy='IAMPolicy', placement='Placement', placement_group='PlacementGroup')
129139

130140
# Loop over all the cluster options and add define to parameters, raise Exception if defined but null
131141
for key in self.__cluster_options:

0 commit comments

Comments
 (0)