def test_get_default(self): config = Config(self.conf_file) runtime = config.get_default().get('configuration').get('runtime') eq_(runtime, 'python2.7') subnets = config.get_default().get('configuration').get( 'vpc_config').get('subnets') eq_(subnets, ['subnet-xxxxxxxx'])
def test_get_function_filename(self): config = Config(self.conf_file) eq_(config.get_function_filename(), "lambda_function.py") open(self.conf_file, "w").write(NODE_CONF) config = Config(self.conf_file) runtime = config.get_configuration().get("runtime") eq_(runtime, "nodejs") eq_(config.get_function_filename(), "lambda_function.js")
def test_get_function_filename(self): config = Config(self.conf_file) eq_(config.get_function_filename(), 'lambda_function.py') open(self.conf_file, 'w').write(NODE_CONF) config = Config(self.conf_file) runtime = config.get_configuration().get('runtime') eq_(runtime, 'nodejs') eq_(config.get_function_filename(), 'lambda_function.js')
def test_generate_lambda_secret(self): config = Config(self.conf_file) secret = config.generate_lambda_secret() eq_(secret, { 'region': 'us-east-1', 'cipher_texts': { 'foo': 'bar' } })
class BaseAction: __metaclass__ = ABCMeta _logger = None def __init__(self, args): self._config = Config(args.conf_file) self._dry_run = False logger_name = 'lamvery' if hasattr(args, 'dry_run'): self._dry_run = args.dry_run if self._dry_run: logger_name = '(Dry run) lamvery' self._logger = get_logger(logger_name) @abstractmethod def action(self): raise NotImplementedError def _get_client(self, cls): return cls( region=self._config.get_region(), profile=self._config.get_profile(), dry_run=self._dry_run) def get_lambda_client(self): return self._get_client(LambdaClient) def get_kms_client(self): return self._get_client(KmsClient) def get_events_client(self): return self._get_client(EventsClient) def get_logs_client(self): return self._get_client(LogsClient) def _get_diff(self, remote, local, keys): diff = {} for k in keys: r = remote.get(k[0]) l = local.get(k[1]) if r == l: diff[k[1]] = None else: diff[k[1]] = (r, l,) return diff def _print_diff(self, prefix, remote, local, keys): diff = self._get_diff(remote, local, keys) for k, v in diff.items(): if v is not None: self._logger.warn( '{p} {k}: {r} -> {l}'.format(p=prefix, k=k, r=v[0], l=v[1]))
def __init__(self, args): self._config = Config(args.conf_file) self._dry_run = False logger_name = 'lamvery' if hasattr(args, 'dry_run'): self._dry_run = args.dry_run if self._dry_run: logger_name = '(Dry run) lamvery' self._logger = get_logger(logger_name)
def test_generate_lambda_secret(self): config = Config(self.conf_file) secret = config.generate_lambda_secret() eq_( secret, { 'region': 'us-east-1', 'cipher_texts': { 'foo': 'bar' }, 'secret_files': { 'baz': 'qux' } })
class BaseAction: __metaclass__ = ABCMeta _logger = None def __init__(self, args): self._config = Config(args.conf_file) self._dry_run = False logger_name = 'lamvery' if hasattr(args, 'dry_run'): self._dry_run = args.dry_run if self._dry_run: logger_name = '(Dry run) lamvery' self._logger = get_logger(logger_name) @abstractmethod def action(self): raise NotImplementedError def get_client(self): return Client(region=self._config.get_region(), profile=self._config.get_profile(), dry_run=self._dry_run) def _get_diff(self, remote, local, keys): diff = {} for k in keys: r = remote.get(k[0]) l = local.get(k[1]) if r == l: diff[k[1]] = None else: diff[k[1]] = ( r, l, ) return diff def _print_diff(self, prefix, remote, local, keys): diff = self._get_diff(remote, local, keys) for k, v in diff.items(): if v is not None: self._logger.warn('{p} {k}: {r} -> {l}'.format(p=prefix, k=k, r=v[0], l=v[1]))
def test_get_function_filename(self): config = Config(self.conf_file) eq_(config.get_function_filename(), 'lambda_function.py') open(self.conf_file, 'w').write(NODE_CONF) config = Config(self.conf_file) eq_(config.get_function_filename(), 'lambda_function.js') open(self.conf_file, 'w').write(NODE43_CONF) config = Config(self.conf_file) eq_(config.get_function_filename(), 'lambda_function.js')
def test_get_runtime(self): config = Config(self.conf_file) eq_(config.get_runtime(), 'python2.7') open(self.conf_file, 'w').write(NODE_CONF) config = Config(self.conf_file) runtime = config.get_configuration().get('runtime') eq_(runtime, 'nodejs4.3') open(self.conf_file, 'w').write(NODE43_CONF) config = Config(self.conf_file) runtime = config.get_configuration().get('runtime') eq_(runtime, 'nodejs4.3')
def test_get_events(self): config = Config(self.conf_file) eq_(config.get_events().get('rules').pop().get('schedule'), 'rate(5 minutes)') config.load_events = Mock(return_value=None) eq_(config.get_events(), {'rules': []}) config.load_events = Mock(return_value=[{'rule': 'foo'}]) eq_(config.get_events(), {'rules': [{'rule': 'foo', 'name': 'foo'}]})
def test_get_profile(self): config = Config(self.conf_file) eq_(config.get_profile(), 'default')
def test_get_archive_name(self): config = Config(self.conf_file) eq_(config.get_archive_name(), 'test_lambda_function.zip')
def test_get_function_name(self): config = Config(self.conf_file) eq_(config.get_function_name(), 'test_lambda_function') config = Config('/foo/bar') eq_(config.get_function_name(), os.path.basename(os.getcwd()))
def test_escape(self): config = Config(self.conf_file) eq_(config.escape('{{ foo[\'bar\'] }}'), '\'{{ foo[\'\'bar\'\'] }}\'') eq_(config.escape('{% foo["bar"] %}'), '\'{% foo["bar"] %}\'')
def test_get_namespace(self): config = Config(self.conf_file) eq_(config.get_handler_namespace(), 'lambda_function')
def test_get_secret_file(self): config = Config(self.conf_file) eq_(config.get_secret_file(), '.test.secret.yml')
def test_get_secret(self): config = Config(self.conf_file) key = config.get_secret().get('key_id') eq_(key, '<key-id>')
def test_get_region(self): config = Config(self.conf_file) eq_(config.get_region(), 'us-east-1') config = Config('/foo/bar') eq_(config.get_region(), None)
def test_load_raw_secret(self): config = Config(self.conf_file) eq_(config.load_raw_secret().get('test_env'), "{{ env[$$PATH$$] }}")
def test_get_vpc_configuration(self): config = Config(self.conf_file) eq_(config.get_vpc_configuration().get('subnets'), ['subnet-xxxxxxxx']) config.get_configuration = Mock(return_value={}) eq_(config.get_vpc_configuration().get('subnets'), [])
def test_get_default(self): config = Config(self.conf_file) runtime = config.get_default().get('configuration').get('runtime') eq_(runtime, 'python2.7')
def get_default_secret(self): config = Config(self.conf_file) eq_( config.get_default_secret().get('key_id').get('<key-id>'), 'sample-rule-name')
def test_get_exclude(self): config = Config(self.conf_file) eq_(config.get_exclude(), ['^bar'])
def test_get_configuration(self): config = Config(self.conf_file) eq_(config.get_configuration().get('test_env'), os.environ.get('PATH'))
def test_load_exclude(self): config = Config(self.conf_file) eq_(config.load_exclude().pop(), '^bar')
def test_get_handler_function(self): config = Config(self.conf_file) eq_(config.get_handler_function(), 'lambda_handler')
def test_get_default_events(self): config = Config(self.conf_file) eq_(config.get_default_events().get('rules').pop().get('name'), 'sample-rule-name')
def test_raw_secret(self): config = Config(self.conf_file) eq_(config.load_raw_secret().get('test_env'), "{{ env['PATH'] }}")
def test_get_default_secret(self): config = Config(self.conf_file) eq_(config.get_default_secret().get('key_id'), '<key-id>')
def test_get_default_exclude(self): config = Config(self.conf_file) eq_(config.get_default_exclude().pop(), '^\\.test\\.exclude\\.yml$')
def test_get_default_api(self): config = Config(self.conf_file) eq_(config.get_default_api().get('api_id'), '<your-rest-api-id>') eq_( config.get_default_api().get('configuration').get('info'), {'title': 'Sample API'})
def test_get_default_hook(self): config = Config(self.conf_file) eq_(config.get_default_hook().get('build').get('pre'), []) eq_(config.get_default_hook().get('build').get('post'), [])
def test_get_default_api(self): config = Config(self.conf_file) eq_(config.get_default_api().get('api_id'), '<your-rest-api-id>') eq_(config.get_default_api().get('configuration').get('info'), {'title': 'Sample API'})
def test_get_default_events(self): config = Config(self.conf_file) eq_( config.get_default_events().pop().get('rule'), 'sample-rule-name')
def test_store_secret(self): config = Config(self.conf_file) config.store_secret('foo', 'bar') eq_(config.get_secret().get('key_id'), '<key-id>') eq_(config.get_secret().get('cipher_texts').get('foo'), 'bar')
def test_load_conf(self): config = Config(self.conf_file) eq_(config.load_conf().get('profile'), 'default')
def test_get_event_file(self): config = Config(self.conf_file) eq_(config.get_event_file(), '.test.event.yml')
def test_escape(self): config = Config(self.conf_file) eq_(config.escape("{{ foo['bar'] }}"), "'{{ foo[$$bar$$] }}'") eq_(config.escape('{% foo["bar"] %}'), '\'{% foo["bar"] %}\'')
def test_get_events(self): config = Config(self.conf_file) eq_(config.get_events().pop().get('schedule'), 'rate(5 minutes)') config.load_events = Mock(return_value=None) eq_(config.get_events(), [])
def test_save_api_id(self): config = Config(self.conf_file) config.save_api_id('foo') eq_(config.get_api_id(), 'foo') eq_(config.get_api_stage(), 'dev')
def test_load_events(self): config = Config(self.conf_file) eq_(config.load_events().pop().get('rule'), 'foo')
def test_store_secret_file(self): config = Config(self.conf_file) config.store_secret_file('baz', 'qux') eq_(config.get_secret().get('key_id'), '<key-id>') eq_(config.get_secret().get('secret_files').get('baz'), 'qux')
def test_load_secret(self): config = Config(self.conf_file) eq_(config.load_secret().get('cipher_texts'), {'foo': 'bar'})
def test_get_exclude_file(self): config = Config(self.conf_file) eq_(config.get_exclude_file(), '.test.exclude.yml')