Skip to content

secretconfig

AttrDict for specifying user credentials or secrets.

SecretConfig

Bases: BaseModel

Simple model for handling secret in other config-models.

Source code in oteapi/models/secretconfig.py
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
class SecretConfig(BaseModel, json_dumps=json_dumps):
    """Simple model for handling secret in other config-models."""

    user: Optional[SecretStr] = Field(None, description="User name for authentication.")
    password: Optional[SecretStr] = Field(
        None, description="Password for authentication."
    )
    token: Optional[SecretStr] = Field(
        None,
        description="An access token for providing access and meta data to an application.",
    )
    client_id: Optional[SecretStr] = Field(
        None, description="Client ID for an OAUTH2 client."
    )
    client_secret: Optional[SecretStr] = Field(
        None, description="Client secret for an OAUTH2 client."
    )

client_id: Optional[SecretStr] = Field(None, description='Client ID for an OAUTH2 client.') class-attribute

client_secret: Optional[SecretStr] = Field(None, description='Client secret for an OAUTH2 client.') class-attribute

password: Optional[SecretStr] = Field(None, description='Password for authentication.') class-attribute

token: Optional[SecretStr] = Field(None, description='An access token for providing access and meta data to an application.') class-attribute

user: Optional[SecretStr] = Field(None, description='User name for authentication.') class-attribute

json_dumps(model, default)

Alternative function for dumping exposed secrets to json when model is serialized.

Parameters:

Name Type Description Default
model dict

The pydantic model to serialize.

required
default Callable[[Any], Any]

A pass-through to the standard json.dumps()'s default parameter. From the json.dumps() doc-string: default(obj) is a function that should return a serializable version of obj or raise TypeError. The default simply raises TypeError.

required

Returns:

Type Description
str

The result of json.dumps() after handling possible secrets.

Source code in oteapi/models/secretconfig.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
def json_dumps(model: dict, default: "Callable[[Any], Any]") -> "str":
    """Alternative function for dumping exposed
    secrets to json when model is serialized.

    Parameters:
        model: The pydantic model to serialize.
        default: A pass-through to the standard `json.dumps()`'s `default` parameter.
            From the `json.dumps()` doc-string: `default(obj)` is a function that should
            return a serializable version of `obj` or raise `TypeError`.
            The default simply raises `TypeError`.

    Returns:
        The result of `json.dumps()` after handling possible secrets.

    """
    return json.dumps(
        {
            key: (
                value.get_secret_value()
                if settings.expose_secrets and isinstance(value, SecretStr)
                else value
            )
            for key, value in model.items()
        },
        default=default,
    )