def parse_data(data): for profile in data.get('AWSProfiles', []): AWSCredentialsManager.add_aws_profile( aws_profile=profile['AWS_PROFILE'], aws_access_key_id=profile['AWS_ACCESS_KEY_ID'], aws_secret_access_key=profile['AWS_SECRET_ACCESS_KEY'], aws_default_region=profile['AWS_DEFAULT_REGION'], ) for alarm_group in data.get('AlarmGroups', []): AlarmsManager.add_alarm_group(**alarm_group) for tag_group in data.get('TagGroups', []): TagsManager.add_tag_group(**tag_group) for directory_path in data.get('Configuration').get('Plugins', []): ConfigurationManager.add_plugins_directory(directory_path)
def update_ec2_tags(verbose=0): if verbose: click.echo('Updating EC2 tags\n') for group in TagsManager.get_groups_by_type('EC2'): AWSCredentialsManager.load_saved_environment_state() if group.get('AWSProfile'): AWSCredentialsManager.load_aws_profile(group['AWSProfile']) set_ec2_tags(instance_ids=group.get('Resources'), tag_key=group.get('TagKey'), tag_value=group.get('TagValue'), verbose=verbose)
def test_load_yaml_file_loads_alarm_groups_into_the_TagsManager(self): expected_group = { 'AWSProfile': 'fake-profile', 'TagKey': 'fake-key', 'TagValue': 'fake-value', 'Type': 'EC2', 'Resources': ['fake-resource'], } load_yaml_file(self.tmp_file.name) self.assertEqual(TagsManager.get_tag_group('fake-key', 'fake-value'), expected_group)
def test_get_groups_by_type(self): TagsManager.add_tag_group(**self.tag_group) self.assertEqual([self.tag_group], TagsManager.get_groups_by_type('EC2'))
def test_get_tag_group(self): TagsManager.add_tag_group(**self.tag_group) self.assertEqual(TagsManager.get_tag_group('fake-key', 'fake-value'), self.tag_group)
def test_add_tag_group(self): TagsManager.add_tag_group(**self.tag_group) self.assertEqual(TagsManager.TagGroups.get('fake-key:fake-value'), self.tag_group)