def test_convert_leaves_to_values_all_config_value_leaves(self):
        source_values = {
            Config.TSSC_CONFIG_KEY: {
                'step-foo': [{
                    'implementer': ConfigValue('foo1', None, None),
                    'config': {
                        'test1': ConfigValue('foo', None, None)
                    }
                }]
            }
        }

        converted = ConfigValue.convert_leaves_to_values(source_values)

        self.assertEqual(
            converted, {
                Config.TSSC_CONFIG_KEY: {
                    'step-foo': [{
                        'implementer': 'foo1',
                        'config': {
                            'test1': 'foo',
                        }
                    }]
                }
            })
    def test_convert_leaves_to_config_values_0(self):
        source = {
            Config.TSSC_CONFIG_KEY: {
                'step-foo': [{
                    'implementer': 'foo1',
                    'config': {
                        'test1': 'foo'
                    }
                }]
            }
        }

        ConfigValue.convert_leaves_to_config_values(
            values=source[Config.TSSC_CONFIG_KEY],
            parent_source=source,
            path_parts=[Config.TSSC_CONFIG_KEY])

        expected = {
            Config.TSSC_CONFIG_KEY: {
                'step-foo': [{
                    'implementer': ConfigValue('foo1', None, None),
                    'config': {
                        'test1': ConfigValue('foo', None, None)
                    }
                }]
            }
        }

        self.assertEqual(source, expected)
    def test_convert_leaves_to_values_mixed_leaves(self):
        source_values = {
            Config.TSSC_CONFIG_KEY: {
                'step-foo': [{
                    'implementer': ConfigValue('foo1', None, None),
                    'config': {
                        'test1': ConfigValue('foo', None, None),
                        'test': 'not a tssc config value object'
                    }
                }]
            }
        }

        converted = ConfigValue.convert_leaves_to_values(source_values)

        self.assertEqual(
            converted, {
                Config.TSSC_CONFIG_KEY: {
                    'step-foo': [{
                        'implementer': 'foo1',
                        'config': {
                            'test1': 'foo',
                            'test': 'not a tssc config value object'
                        }
                    }]
                }
            })
    def test_global_defaults(self):
        tssc_config = Config({
            Config.TSSC_CONFIG_KEY: {
                'global-defaults': {
                    'test1': 'global-default-1',
                    'test2': 'global-default-2'
                },
                'step-foo': [{
                    'implementer': 'foo1',
                    'config': {
                        'test1': 'foo'
                    }
                }]
            }
        })

        step_config = tssc_config.get_step_config('step-foo')
        sub_step = step_config.get_sub_step('foo1')

        self.assertEqual(
            sub_step.global_defaults, {
                'test1':
                ConfigValue('global-default-1', None,
                            ["tssc-config", "global-defaults", "test1"]),
                'test2':
                ConfigValue('global-default-2', None,
                            ["tssc-config", "global-defaults", "test2"])
            })
Exemple #5
0
    def test_list_of_config_value(self, container_registry_login_mock):
        registries = [
            ConfigValue({
                'uri': 'registry.redhat.io',
                'username': '******',
                'password': '******'
            }),
            ConfigValue({
                'uri': 'registry.internal.example.xyz',
                'username': '******',
                'password': '******'
            })
        ]

        container_registries_login(registries)

        calls = [
            call(container_registry_uri='registry.redhat.io',
                 container_registry_username='******',
                 container_registry_password='******',
                 container_registry_tls_verify=True,
                 containers_config_auth_file=None),
            call(container_registry_uri='registry.internal.example.xyz',
                 container_registry_username='******',
                 container_registry_password='******',
                 container_registry_tls_verify=True,
                 containers_config_auth_file=None)
        ]
        container_registry_login_mock.assert_has_calls(calls)
    def test_value_decyrpt(self, sops_mock):
        encrypted_config_file_path = os.path.join(
            os.path.dirname(__file__), 'decryptors', 'files',
            'tssc-config-secret-stuff.yml')

        config_value = ConfigValue(
            value=
            'ENC[AES256_GCM,data:UGKfnzsSrciR7GXZJhOCMmFrz3Y6V3pZsd3P,iv:yuReqA+n+rRXVHMc+2US5t7yPx54sooZSXWV4KLjDIs=,tag:jueP7/ZWLfYrEuhh+4eS8g==,type:str]',
            parent_source=encrypted_config_file_path,
            path_parts=[
                'tssc-config', 'global-environment-defaults', 'DEV',
                'kube-api-token'
            ])

        DecryptionUtils.register_config_value_decryptor(SOPS())

        sops_mock.side_effect = create_sops_side_effect('mock decrypted value')
        decrypted_value = config_value.value
        sops_mock.assert_called_once_with(
            '--decrypt',
            '--extract=["tssc-config"]["global-environment-defaults"]["DEV"]["kube-api-token"]',
            None,
            encrypted_config_file_path,
            _in=None,
            _out=Any(StringIO),
            _err=Any(StringIO))
        self.assertEqual(decrypted_value, 'mock decrypted value')
Exemple #7
0
    def test_configvalue_params(self, which_mock, container_command_mock):
        which_mock.side_effect = create_which_side_effect(
            cmd='buildah', cmd_path='/mock/buildah')

        container_registry_login(
            container_registry_uri=ConfigValue('registry.example.xyz'),
            container_registry_username=ConfigValue('example'),
            container_registry_password=ConfigValue('nope'),
            container_registry_tls_verify=ConfigValue(True),
            containers_config_auth_file=ConfigValue('/tmp/test/auth.json'))

        container_command_mock.bake.assert_called_once()
        container_command_mock.bake().login.bake.assert_called_once_with(
            password_stdin=True,
            username='******',
            tls_verify='true',
            authfile='/tmp/test/auth.json')
        container_command_mock.bake().login.bake().assert_called_once_with(
            'registry.example.xyz',
            _in='nope',
            _out=Any(IOBase),
            _err=Any(IOBase),
            _tee='err')
    def test__eq__is_not_equal_different_objects(self):
        test1 = ConfigValue('foo1', None, None)
        test2 = "foo1"

        self.assertNotEqual(test1, test2)
    def test__eq__is_not_equal_both_tssc_config_value_objects(self):
        test1 = ConfigValue('foo1', None, None)
        test2 = ConfigValue('foo2', None, None)

        self.assertNotEqual(test1, test2)
    def test__eq__is_equal_diff_source_and_path_parts(self):
        test1 = ConfigValue('foo1', "does not matter for equality", ['a', 'b'])
        test2 = ConfigValue('foo1', "really does not matter for equality",
                            ['1', '2'])

        self.assertEqual(test1, test2)
    def test__eq__is_equal_diff_path_parts(self):
        test1 = ConfigValue('foo1', None, ['a', 'b'])
        test2 = ConfigValue('foo1', None, ['1', '2'])

        self.assertEqual(test1, test2)
    def test__eq__is_equal_diff_source(self):
        test1 = ConfigValue('foo1', "does not matter for equality", None)
        test2 = ConfigValue('foo1', "really does not matter for equality",
                            None)

        self.assertEqual(test1, test2)
    def test__eq__is_equal_basic(self):
        test1 = ConfigValue('foo1', None, None)
        test2 = ConfigValue('foo1', None, None)

        self.assertEqual(test1, test2)