Skip to content

Commit

Permalink
Create different cache dir for AWS_PROFILE
Browse files Browse the repository at this point in the history
If don't create different cache dir, there will be some risk when
user use AWS_PROFILE switch in different production environments.
  • Loading branch information
Fred Chu committed Feb 20, 2016
1 parent 11f081c commit 49719ed
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions contrib/inventory/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ def read_settings(self):
cache_dir = os.path.expanduser(config.get('ec2', 'cache_path'))
if self.boto_profile:
cache_dir = os.path.join(cache_dir, 'profile_' + self.boto_profile)
if not None in [os.environ.get('AWS_PROFILE')]:
cache_dir = os.path.join(cache_dir, 'aws_profile_' + os.environ.get('AWS_PROFILE'))
else:
cache_dir = os.path.join(cache_dir, 'aws_profile_default')
if not os.path.exists(cache_dir):
os.makedirs(cache_dir)

Expand Down Expand Up @@ -480,7 +484,7 @@ def get_instances_by_region(self, region):
if e.error_code == 'AuthFailure':
error = self.get_auth_error_message()
else:
backend = 'Eucalyptus' if self.eucalyptus else 'AWS'
backend = 'Eucalyptus' if self.eucalyptus else 'AWS'
error = "Error connecting to %s backend.\n%s" % (backend, e.message)
self.fail_with_error(error, 'getting EC2 instances')

Expand Down Expand Up @@ -696,7 +700,7 @@ def add_instance(self, instance, region):
if self.nested_groups:
self.push_group(self.inventory, 'security_groups', key)
except AttributeError:
self.fail_with_error('\n'.join(['Package boto seems a bit older.',
self.fail_with_error('\n'.join(['Package boto seems a bit older.',
'Please upgrade boto >= 2.3.0.']))

# Inventory: Group by tag keys
Expand Down Expand Up @@ -800,7 +804,7 @@ def add_rds_instance(self, instance, region):
self.push_group(self.inventory, 'security_groups', key)

except AttributeError:
self.fail_with_error('\n'.join(['Package boto seems a bit older.',
self.fail_with_error('\n'.join(['Package boto seems a bit older.',
'Please upgrade boto >= 2.3.0.']))


Expand Down

0 comments on commit 49719ed

Please sign in to comment.