Пример #1
0
 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'])
Пример #2
0
    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")
Пример #3
0
    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')
Пример #4
0
 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'
         }
     })
Пример #5
0
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]))
Пример #6
0
    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)
Пример #7
0
 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'
             }
         })
Пример #8
0
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]))
Пример #9
0
    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')
Пример #10
0
    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')
Пример #11
0
 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'}]})
Пример #12
0
    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')
Пример #13
0
    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)
Пример #14
0
 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'}]})
Пример #15
0
 def test_get_profile(self):
     config = Config(self.conf_file)
     eq_(config.get_profile(), 'default')
Пример #16
0
 def test_get_archive_name(self):
     config = Config(self.conf_file)
     eq_(config.get_archive_name(), 'test_lambda_function.zip')
Пример #17
0
 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()))
Пример #18
0
 def test_escape(self):
     config = Config(self.conf_file)
     eq_(config.escape('{{ foo[\'bar\'] }}'), '\'{{ foo[\'\'bar\'\'] }}\'')
     eq_(config.escape('{% foo["bar"] %}'), '\'{% foo["bar"] %}\'')
Пример #19
0
 def test_get_namespace(self):
     config = Config(self.conf_file)
     eq_(config.get_handler_namespace(), 'lambda_function')
Пример #20
0
 def test_get_secret_file(self):
     config = Config(self.conf_file)
     eq_(config.get_secret_file(), '.test.secret.yml')
Пример #21
0
 def test_get_secret(self):
     config = Config(self.conf_file)
     key = config.get_secret().get('key_id')
     eq_(key, '<key-id>')
Пример #22
0
 def test_get_profile(self):
     config = Config(self.conf_file)
     eq_(config.get_profile(), 'default')
Пример #23
0
 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)
Пример #24
0
 def test_get_archive_name(self):
     config = Config(self.conf_file)
     eq_(config.get_archive_name(), 'test_lambda_function.zip')
Пример #25
0
 def test_load_raw_secret(self):
     config = Config(self.conf_file)
     eq_(config.load_raw_secret().get('test_env'), "{{ env[$$PATH$$] }}")
Пример #26
0
 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()))
Пример #27
0
 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'), [])
Пример #28
0
 def test_get_default(self):
     config = Config(self.conf_file)
     runtime = config.get_default().get('configuration').get('runtime')
     eq_(runtime, 'python2.7')
Пример #29
0
 def get_default_secret(self):
     config = Config(self.conf_file)
     eq_(
         config.get_default_secret().get('key_id').get('<key-id>'),
         'sample-rule-name')
Пример #30
0
 def test_get_exclude(self):
     config = Config(self.conf_file)
     eq_(config.get_exclude(), ['^bar'])
Пример #31
0
 def test_get_configuration(self):
     config = Config(self.conf_file)
     eq_(config.get_configuration().get('test_env'), os.environ.get('PATH'))
Пример #32
0
 def test_load_exclude(self):
     config = Config(self.conf_file)
     eq_(config.load_exclude().pop(), '^bar')
Пример #33
0
 def test_get_handler_function(self):
     config = Config(self.conf_file)
     eq_(config.get_handler_function(), 'lambda_handler')
Пример #34
0
 def test_get_default_events(self):
     config = Config(self.conf_file)
     eq_(config.get_default_events().get('rules').pop().get('name'),
         'sample-rule-name')
Пример #35
0
 def test_raw_secret(self):
     config = Config(self.conf_file)
     eq_(config.load_raw_secret().get('test_env'), "{{ env['PATH'] }}")
Пример #36
0
 def test_get_default_secret(self):
     config = Config(self.conf_file)
     eq_(config.get_default_secret().get('key_id'), '<key-id>')
Пример #37
0
 def test_get_configuration(self):
     config = Config(self.conf_file)
     eq_(config.get_configuration().get('test_env'), os.environ.get('PATH'))
Пример #38
0
 def test_get_default_exclude(self):
     config = Config(self.conf_file)
     eq_(config.get_default_exclude().pop(), '^\\.test\\.exclude\\.yml$')
Пример #39
0
 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'})
Пример #40
0
 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'), [])
Пример #41
0
 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)
Пример #42
0
 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'})
Пример #43
0
 def test_get_exclude(self):
     config = Config(self.conf_file)
     eq_(config.get_exclude(), ['^bar'])
Пример #44
0
 def test_get_secret(self):
     config = Config(self.conf_file)
     key = config.get_secret().get('key_id')
     eq_(key, '<key-id>')
Пример #45
0
 def test_get_default_events(self):
     config = Config(self.conf_file)
     eq_(
         config.get_default_events().pop().get('rule'),
         'sample-rule-name')
Пример #46
0
 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')
Пример #47
0
 def test_get_default_exclude(self):
     config = Config(self.conf_file)
     eq_(config.get_default_exclude().pop(), '^\\.test\\.exclude\\.yml$')
Пример #48
0
 def test_load_conf(self):
     config = Config(self.conf_file)
     eq_(config.load_conf().get('profile'), 'default')
Пример #49
0
 def test_get_event_file(self):
     config = Config(self.conf_file)
     eq_(config.get_event_file(), '.test.event.yml')
Пример #50
0
 def test_escape(self):
     config = Config(self.conf_file)
     eq_(config.escape("{{ foo['bar'] }}"), "'{{ foo[$$bar$$] }}'")
     eq_(config.escape('{% foo["bar"] %}'), '\'{% foo["bar"] %}\'')
Пример #51
0
 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(), [])
Пример #52
0
 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')
Пример #53
0
 def test_load_events(self):
     config = Config(self.conf_file)
     eq_(config.load_events().pop().get('rule'), 'foo')
Пример #54
0
 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')
Пример #55
0
 def test_load_secret(self):
     config = Config(self.conf_file)
     eq_(config.load_secret().get('cipher_texts'), {'foo': 'bar'})
Пример #56
0
 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')
Пример #57
0
 def test_load_exclude(self):
     config = Config(self.conf_file)
     eq_(config.load_exclude().pop(), '^bar')
Пример #58
0
 def test_get_exclude_file(self):
     config = Config(self.conf_file)
     eq_(config.get_exclude_file(), '.test.exclude.yml')
Пример #59
0
 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')
Пример #60
0
 def test_get_exclude_file(self):
     config = Config(self.conf_file)
     eq_(config.get_exclude_file(), '.test.exclude.yml')