Пример #1
0
    def test_hide_nested_list(self) -> None:
        def hider(secret_data: SecretData) -> None:
            if not isinstance(secret_data.secret, SecretAddress):
                secret_data.secret = SecretAddress(url="blah blah")

        job_template_index = JobTemplateIndex(
            name="test",
            template=JobTemplate(
                os=OS.linux,
                job=JobConfig(name="test",
                              build="test",
                              project="test",
                              duration=1),
                tasks=[],
                notifications=[
                    JobTemplateNotification(
                        container_type=ContainerType.unique_inputs,
                        notification=NotificationConfig(config=TeamsTemplate(
                            url=SecretData(secret="http://test"))),
                    )
                ],
                user_fields=[],
            ),
        )
        ORMMixin.hide_secrets(job_template_index, hider)
        notification = job_template_index.template.notifications[
            0].notification
        if isinstance(notification.config, TeamsTemplate):
            self.assertIsInstance(notification.config.url, SecretData)
            self.assertIsInstance(notification.config.url.secret,
                                  SecretAddress)
        else:
            self.fail(f"Invalid config type {type(notification.config)}")
Пример #2
0
    def test_hide(self) -> None:
        notification = Notification(
            container=Container("data"),
            config=TeamsTemplate(url=SecretData(secret="http://test")),
        )
        notification = hide_secrets(notification, hider)

        if isinstance(notification.config, TeamsTemplate):
            self.assertIsInstance(notification.config.url, SecretData)
            self.assertIsInstance(notification.config.url.secret,
                                  SecretAddress)
        else:
            self.fail(f"Invalid config type {type(notification.config)}")
Пример #3
0
def save_to_keyvault(secret_data: SecretData) -> None:
    if isinstance(secret_data.secret, SecretAddress):
        return

    secret_name = str(uuid4())
    if isinstance(secret_data.secret, str):
        secret_value = secret_data.secret
    elif isinstance(secret_data.secret, BaseModel):
        secret_value = secret_data.secret.json()
    else:
        raise Exception("invalid secret data")

    kv = store_in_keyvault(get_keyvault_address(), secret_name, secret_value)
    secret_data.secret = SecretAddress(url=kv.id)
Пример #4
0
 def hider(secret_data: SecretData) -> None:
     if not isinstance(secret_data.secret, SecretAddress):
         secret_data.secret = SecretAddress(url="blah blah")
Пример #5
0
    def test_delete(self) -> None:
        self.count = 0

        def deleter(secret_data: SecretData) -> None:
            self.count += 1

        delete_secrets(WithSecret(a=SecretData("a")), deleter)
        self.assertEqual(self.count, 1)

        delete_secrets(
            WithList(a=[
                WithSecret(a=SecretData("a")),
                WithSecret(a=SecretData("b")),
            ]),
            deleter,
        )
        self.assertEqual(self.count, 3)

        delete_secrets(
            WithDict(
                a={
                    "a": SecretData("a"),
                    "b": SecretData("b")
                },
                b={
                    "a": WithSecret(a=SecretData("a")),
                    "b": WithSecret(a=SecretData("a")),
                },
            ),
            deleter,
        )
        self.assertEqual(self.count, 7)

        delete_secrets(
            Nested(
                a=WithSecret(a=SecretData("a")),
                b=WithDict(a={"a": SecretData("a")},
                           b={"a": WithSecret(a=SecretData("a"))}),
                c=WithList(a=[
                    WithSecret(a=SecretData("a")),
                    WithSecret(a=SecretData("b"))
                ]),
            ),
            deleter,
        )
        self.assertEqual(self.count, 12)