Skip to content

Secrets Entity

The Secrets entity is kept under the following import statement:

from everysk.sdk.entities import Secrets


Attributes

Below we have the most common attributes used in the Secrets entity:

  • id: The unique identifier of the Secrets entity. Follows the format sec_<value>.

  • name: The name of the secrets entity.

  • description: The current description of the secrets entity.

  • data: A dictionary containing the secret values. This field is required and must be a non-empty dictionary.


Instantiating a Secrets Entity and Passing Attributes

To instantiate a Secrets entity, we can use the following code snippet:

secrets = Secrets()
type(secrets)
everysk.sdk.entities.secrets.base.Secrets

Now we can manually set the class attributes in order to properly configure our Secrets entity.

secrets.name = 'api-keys'
secrets.description = 'Third-party API credentials'
secrets.data = {'v1': {'openai': 'sk-abc123', 'stripe': 'sk-live-xyz'}}


Retrieving a Value by Path

The Secrets entity provides a class method value_from_path() that allows retrieving a specific value using a dot-notation path. The path must start with a valid secret id, followed by one or more keys separated by dots.

value = Secrets.value_from_path('sec_abc123.v1.openai')

If the path format is invalid or the secret ID does not match the expected format, a ValueError is raised:

Secrets.value_from_path('invalid-path')
# ValueError: Invalid path format. Expected format: "<secret_id>.<key1>.<key2>..."


Convert Secrets to a Dictionary

Most times when working with entities, there might be a point where we need to convert the entity to a dictionary, and to achieve this we simply use the to_dict() method:

secrets = Secrets()
type(secrets)
everysk.sdk.entities.secrets.base.Secrets

to_dict = secrets.to_dict()
type(to_dict)
# dict


Validating a Secrets Entity

The validate() method from the Secrets entity is used as a lazy validation method in order to check if the entity is valid or not by returning a boolean value:

secrets = Secrets(name='api-keys', data={'v1': {'key': 'value'}})
secrets.validate()
# True

In the case of an invalid entity, meaning that some field is missing or has an invalid value, the validate() method will raise a FieldValueError:

secrets = Secrets(name='api-keys')
secrets.validate()
# FieldValueError: data is required.