Skip to content

Entity and methods

Secret

Bases: VersionedEntity

A class representing a secret.

Source code in digitalhub_core/entities/secret/entity.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
class Secret(VersionedEntity):
    """
    A class representing a secret.
    """

    ENTITY_TYPE = EntityTypes.SECRET.value

    def __init__(
        self,
        project: str,
        name: str,
        uuid: str,
        kind: str,
        metadata: Metadata,
        spec: SecretSpec,
        status: SecretStatus,
        user: str | None = None,
    ) -> None:
        super().__init__(project, name, uuid, kind, metadata, spec, status, user)
        self.spec: SecretSpec
        self.status: SecretStatus

    ##############################
    #  Secret methods
    ##############################

    def set_secret_value(self, value: str) -> None:
        """
        Update the secret value with a new one.

        Parameters
        ----------
        value : str
            Value of the secret.

        Returns
        -------
        None
        """
        if self._context().local:
            raise NotImplementedError("set_secret() is not implemented for local projects.")

        obj = {self.name: value}
        set_data_api(self.project, self.ENTITY_TYPE, obj)

    def read_secret_value(self) -> dict:
        """
        Read the secret value from backend.

        Returns
        -------
        str
            Value of the secret.
        """
        if self._context().local:
            raise NotImplementedError("read_secret() is not implemented for local projects.")

        params = {"keys": self.name}
        return get_data_api(self.project, self.ENTITY_TYPE, params=params)

read_secret_value()

Read the secret value from backend.

Returns:

Type Description
str

Value of the secret.

Source code in digitalhub_core/entities/secret/entity.py
60
61
62
63
64
65
66
67
68
69
70
71
72
73
def read_secret_value(self) -> dict:
    """
    Read the secret value from backend.

    Returns
    -------
    str
        Value of the secret.
    """
    if self._context().local:
        raise NotImplementedError("read_secret() is not implemented for local projects.")

    params = {"keys": self.name}
    return get_data_api(self.project, self.ENTITY_TYPE, params=params)

set_secret_value(value)

Update the secret value with a new one.

Parameters:

Name Type Description Default
value str

Value of the secret.

required

Returns:

Type Description
None
Source code in digitalhub_core/entities/secret/entity.py
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
def set_secret_value(self, value: str) -> None:
    """
    Update the secret value with a new one.

    Parameters
    ----------
    value : str
        Value of the secret.

    Returns
    -------
    None
    """
    if self._context().local:
        raise NotImplementedError("set_secret() is not implemented for local projects.")

    obj = {self.name: value}
    set_data_api(self.project, self.ENTITY_TYPE, obj)