Пример #1
0
    def can_use_yaml_cfg_with_handler_override(self):
        with mock_ssm():
            options = {
                'PARAMETER_STORE_AWS_REGION': 'us-west-2',
                'PARAMETER_STORE_PREFIX': '/aumbry-test',
            }

            expected_cfg = SampleYamlConfig()
            expected_cfg.nope = 'testing'

            handler = GenericHandler()

            # Save Sample Config
            aumbry.save(aumbry.PARAM_STORE,
                        expected_cfg,
                        options,
                        handler=handler)

            # Retrieve back the config
            cfg = aumbry.load(aumbry.PARAM_STORE,
                              SampleGenericConfig,
                              options,
                              handler=handler)

        expect(cfg.nope).to.equal(expected_cfg.nope)
Пример #2
0
def command(arguments):
    options = build_options(arguments)
    file_path = arguments.path
    input_handler = JsonHandler()
    output_handler = None

    if arguments.file_type == 'yml':
        input_handler = YamlHandler()

    if arguments.dest == aumbry.PARAM_STORE:
        output_handler = GenericHandler()

    if not has_required(arguments.dest, options):
        print('Missing required options for destination type')
        return 1

    package_ref, _, name = arguments.config_class.partition(':')
    if not name:
        print('config_class: requires a package and class reference')
        print('Example: my_package.sub:AppConfig')
        return 1

    with PikeManager([arguments.package_root]):
        module = py.get_module_by_name(package_ref)
        config_cls = getattr(module, name)

        print('Loading Config File...')
        cfg = aumbry.load(aumbry.FILE,
                          config_cls, {'CONFIG_FILE_PATH': file_path},
                          handler=input_handler)

        print('Uploading Config...')
        aumbry.save(arguments.dest, cfg, options, handler=output_handler)
Пример #3
0
    def can_save(self, raw, cls):
        cfg = cls()
        cfg.nope = 'testing'

        with tempfile.NamedTemporaryFile() as temp:
            options = {'CONFIG_FILE_PATH': temp.name}
            aumbry.save(aumbry.FILE, cfg, options)

            # Load up the saved file
            loaded_cfg = aumbry.load(aumbry.FILE, cls, options)
            expect(loaded_cfg.nope).to.equal(cfg.nope)
Пример #4
0
    def can_save_and_load(self):
        cfg = SampleYamlConfig()
        cfg.nope = 'testing'

        with tempfile.NamedTemporaryFile() as temp:
            options = {
                'CONFIG_FILE_PATH': temp.name,
                'CONFIG_FILE_FERNET_KEY': Fernet.generate_key().decode('utf-8')
            }
            aumbry.save(aumbry.FERNET, cfg, options)

            # Load up the saved file
            loaded_cfg = aumbry.load(aumbry.FERNET, SampleYamlConfig, options)
            expect(loaded_cfg.nope).to.equal(cfg.nope)
Пример #5
0
    def can_successfully_update_existing_in_etcd(self):
        with requests_mock.Mocker() as mock:
            mock_save = mock.put('http://bam/v2/keys/test_key',
                                 status_code=200,
                                 text='{}')

            cfg = SampleYamlConfig()
            cfg.nope = 'testing'

            aumbry.save(aumbry.ETCD2,
                        cfg,
                        options={
                            'ETCD2_URI': 'http://bam',
                            'ETCD2_KEY': 'test_key',
                        })

            body = urllib.parse.unquote(mock_save.last_request.text)
            expect(body).to.equal('value=bm9wZTogdGVzdGluZwo=')
Пример #6
0
    def can_successfully_save_to_etcd(self):
        with requests_mock.Mocker() as mock:
            mock_save = mock.put('http://bam/v2/keys/test_key',
                                 status_code=201,
                                 text='{}')

            cfg = SampleYamlConfig()
            cfg.nope = 'testing'

            aumbry.save(aumbry.ETCD2,
                        cfg,
                        options={
                            'ETCD2_URI': 'http://bam',
                            'ETCD2_KEY': 'test_key',
                        })

            body = urllib.parse.unquote(mock_save.last_request.text)
            expect(body).to.equal('value=e25vcGU6IHRlc3Rpbmd9Cg==')
Пример #7
0
    def can_use_preprocessors(self, raw, cls):
        cfg = cls()
        cfg.nope = 'testing'

        with tempfile.NamedTemporaryFile() as temp:
            options = {'CONFIG_FILE_PATH': temp.name}
            aumbry.save(aumbry.FILE,
                        cfg,
                        options,
                        preprocessor=lambda data: base64.b64encode(data))

            expect('testing').not_to.be_in(temp.file.read().decode('utf-8'))

            # Load up the saved file
            loaded_cfg = aumbry.load(
                aumbry.FILE,
                cls,
                options,
                preprocessor=lambda data: base64.b64decode(data))
            expect(loaded_cfg.nope).to.equal(cfg.nope)
Пример #8
0
    def can_successfully_save_and_load(self):
        with mock_ssm():
            options = {
                'PARAMETER_STORE_AWS_REGION': 'us-west-2',
                'PARAMETER_STORE_PREFIX': '/aumbry-test',
            }
            expected_cfg = SampleGenericConfig()
            expected_cfg.nope = 'testing'
            expected_cfg.sample_list = ['trace']
            expected_cfg.sample_dict = {'trace': 'boom'}
            expected_cfg.sample_model = SampleJsonConfig()
            expected_cfg.sample_model.nope = 'testing2'

            # Save Sample Config
            aumbry.save(aumbry.PARAM_STORE, expected_cfg, options)

            # Retrieve back the config
            cfg = aumbry.load(aumbry.PARAM_STORE, SampleGenericConfig, options)

        expect(cfg.nope).to.equal(expected_cfg.nope)
        expect(cfg.sample_dict).to.equal({'trace': 'boom'})
        expect(cfg.sample_list).to.equal(expected_cfg.sample_list)
        expect(cfg.sample_model.nope).to.equal(expected_cfg.sample_model.nope)