Skip to content

Manage secrets

The CRUD methods create, read, update, and delete secrets. They can be called directly from the SDK or through a Project object. When using a Project object, omit the project parameter and pass every other parameter as a keyword argument. For creation, see Create a secret and the secret kind.

Read

Use the read methods to retrieve secrets from the backend or load them from a YAML descriptor.

get_secret

Get a secret entity from the backend.

Parameters:

Name Type Description Default
identifier str

Entity name or entity key (store://<project>/<entity_type>/<kind>/<(name>:)<uuid>).

required
project str

Project name. Required when identifier is an entity name.

None
entity_id str

Entity identifier used to select a specific version when identifier is an entity key.

None

Returns:

Type Description
Secret

Retrieved secret entity.

Examples:

Retrieve the latest version by name and project, or by entity key:

import digitalhub as dh

secret = dh.get_secret("my-secret", "my-project")
secret = dh.get_secret("store://my-project/secret/secret/my-secret:123e4567-e89b-42d3-a456-426614174000")
list_secrets

List the latest versions of secret entities in a project.

Parameters:

Name Type Description Default
project str

Project name.

required

Returns:

Type Description
list[Secret]

Latest versions of secret entities in the project.

Examples:

List secrets in a project:

import digitalhub as dh

secrets = dh.list_secrets(project="my-project")
import_secret

Import a secret entity from a YAML file or entity key.

Parameters:

Name Type Description Default
file str

Path to a YAML file containing the entity descriptor. Provide either file or key.

None
key str

Entity key (store://<project>/<entity_type>/<kind>/<(name>:)<uuid>). Provide either file or key.

None
reset_id bool

Whether to generate a new entity identifier instead of preserving the identifier from the imported entity.

False
context str

Project name used for context resolution. If omitted, the project from the entity descriptor is used.

None

Returns:

Type Description
Secret

Imported secret entity.

Examples:

Import a secret from a YAML file or entity key:

import digitalhub as dh

secret = dh.import_secret(file="my-secret.yaml")
secret = dh.import_secret(key="store://my-project/secret/secret/my-secret:123e4567-e89b-42d3-a456-426614174000")

Update

Update a secret after changing its mutable metadata.

update_secret

Update a secret entity in the backend.

Parameters:

Name Type Description Default
entity Secret

Entity to update. The entity specification is immutable.

required

Returns:

Type Description
Secret

Updated secret entity.

Examples:

Update a secret after changing its mutable metadata:

import digitalhub as dh

secret = dh.get_secret("my-secret", "my-project")
secret.set_description("Updated secret")
secret = dh.update_secret(secret)

Delete

Delete one secret version or all versions of a secret.

delete_secret

Delete one or more versions of a secret entity from the backend.

Parameters:

Name Type Description Default
identifier str

Entity name or entity key (store://<project>/<entity_type>/<kind>/<(name>:)<uuid>). Use an entity name when delete_all_versions is True.

required
project str

Project name. Required when identifier is an entity name.

None
entity_id str

Identifier of the version to delete. Required when delete_all_versions is False and identifier does not contain the version identifier.

None
delete_all_versions bool

Whether to delete all versions of the named entity. When False, only one version is deleted.

False

Returns:

Type Description
dict

Response data from the backend.

Examples:

Delete a version by key, or delete all versions by name and project:

import digitalhub as dh

dh.delete_secret("store://my-project/secret/secret/my-secret:123e4567-e89b-42d3-a456-426614174000")
dh.delete_secret("my-secret", "my-project", delete_all_versions=True)