Ir para o conteúdo

tempest_fastapi_sdk.artifacts

Registro de artefatos binários versionados: no banco, ativáveis e com digest.

« Documentos e arquivos


ArtifactVersionMixin

Bases: _MixinBase

Columns for a versioned, activatable binary artifact.

Mix into a concrete BaseModel table so an artifact name can hold many versions with exactly one is_current per name.

Attributes:

Name Type Description
name str

Indexed logical artifact key. Many versions share one name; the manifest resolves the current one per name.

version str

Opaque, human-facing version label (e.g. "1.2.0" or a build hash). Not parsed or ordered by the SDK.

file_key str

Object-storage key of the uploaded bytes. Immutable once written — checksums are derived from it on demand and memoized by this key.

is_current bool

Whether this row is the version currently served for its name. Defaults to False; exactly one row per name should be True (enforced by the activate action, not a DB constraint).

ArtifactRegistry

ArtifactRegistry(
    repository: BaseRepository[TModel],
    *,
    minio: AsyncMinIOClient | None = None,
    bucket: str | None = None,
)

Bases: Generic[TModel]

Resolve, list and activate versions of a binary artifact.

Generic over the concrete :class:~tempest_fastapi_sdk.artifacts.ArtifactVersionMixin table so every method returns the project's own rows. The optional minio / bucket pair is not used by the registry itself — it is held so callers (and the manifest digest_source) can reach object storage without threading a second dependency through.

Generic parameters

TModel: The concrete artifact-version model.

Attributes:

Name Type Description
repository BaseRepository[TModel]

Data access for the artifact-version table.

minio AsyncMinIOClient | None

Optional object-storage client for digesting / serving the stored bytes.

bucket str | None

Optional bucket the artifact objects live in.

Initialize the registry.

Parameters:

Name Type Description Default
repository BaseRepository[TModel]

Repository bound to the concrete artifact-version model.

required
minio AsyncMinIOClient | None

Optional object-storage client used to digest / serve the stored bytes.

None
bucket str | None

Optional bucket the objects live in.

None

current async

current(name: str) -> TModel | None

Return the current version for name, or None.

Parameters:

Name Type Description Default
name str

The logical artifact key.

required

Returns:

Type Description
TModel | None

TModel | None: The row flagged is_current for name,

TModel | None

or None when no version has been activated yet.

list_current async

list_current() -> list[TModel]

Return the current version of every artifact.

Returns:

Type Description
list[TModel]

list[TModel]: One is_current row per name ([]

list[TModel]

when nothing has been activated yet).

activate async

activate(version_id: UUID) -> TModel

Make one version the current one for its name.

Flips is_current on the selected row and clears it on every sibling of the same name in a single transaction, so exactly one version per name is ever current.

Parameters:

Name Type Description Default
version_id UUID

Primary key of the version to activate.

required

Returns:

Name Type Description
TModel TModel

The activated row (refreshed).

Raises:

Type Description
AppException

The repository's not_found_exception when no version with version_id exists.

ArtifactManifestEntry

Bases: BaseSchema

One current-artifact row reduced to the manifest essentials.

Serialization-agnostic on purpose: it carries the identity and integrity fields every manifest needs and leaves URL scheme, caching hints and the enclosing envelope to the application.

Attributes:

Name Type Description
name str

Logical artifact key.

version str

Opaque version label of the current row.

file_key str

Object-storage key of the current bytes.

sha256 str

Hex SHA-256 of the current bytes.

size int

Size of the current bytes, in bytes.

build_manifest_entries async

build_manifest_entries(
    registry: ArtifactRegistry[TModel],
    *,
    digest_source: Callable[[TModel], Awaitable[tuple[str, int]]],
) -> list[ArtifactManifestEntry]

Build manifest entries from a registry's current rows.

Stays serialization-agnostic: it resolves the current version of every artifact and asks digest_source for each row's (sha256, size). The caller's digest_source decides where the bytes come from — typically :func:~tempest_fastapi_sdk.artifacts.object_digest against MinIO, with a :func:~tempest_fastapi_sdk.artifacts.file_digest fallback to a bundled on-disk file.

Parameters:

Name Type Description Default
registry ArtifactRegistry[TModel]

The registry to read current rows from.

required
digest_source Callable[[TModel], Awaitable[tuple[str, int]]]

Async function mapping a current row to its (sha256, size).

required

Returns:

Type Description
list[ArtifactManifestEntry]

list[ArtifactManifestEntry]: One entry per current artifact

list[ArtifactManifestEntry]

([] when nothing has been activated).

file_digest async

file_digest(path: str | Path) -> tuple[str, int]

Return the streamed (sha256, size) of an on-disk file, memoized.

The file read runs in a worker thread (asyncio.to_thread) so the event loop stays responsive; the result is cached by the resolved path string, so repeat calls never re-read the file.

Parameters:

Name Type Description Default
path str | Path

Path to the file to digest.

required

Returns:

Type Description
tuple[str, int]

tuple[str, int]: The hex SHA-256 and the size in bytes.

object_digest async

object_digest(client: AsyncMinIOClient, bucket: str, key: str) -> tuple[str, int]

Return the streamed (sha256, size) of a stored object, memoized.

Streams the object from MinIO/S3 chunk by chunk (never loading the whole payload into memory) and caches the result by (bucket, key) — safe because an object key is immutable for its content.

Parameters:

Name Type Description Default
client AsyncMinIOClient

The object-storage client.

required
bucket str

The bucket the object lives in.

required
key str

The object key.

required

Returns:

Type Description
tuple[str, int]

tuple[str, int]: The hex SHA-256 and the size in bytes.

make_activate_artifact_action

make_activate_artifact_action(
    *,
    label: str = "Activate version",
    name: str = "activate_artifact",
    dangerous: bool = False,
) -> AdminAction

Build an admin action that activates the selected artifact version.

Register the returned action's handler on an AdminModel::

action = make_activate_artifact_action(label="Ativar versão")
site.register(AdminModel(model=ModelVersion, actions=[action.handler]))

Parameters:

Name Type Description Default
label str

Dropdown label shown to the operator.

'Activate version'
name str

Stable identifier (the submitted form value); must be unique among the model's actions.

'activate_artifact'
dangerous bool

Flag the action as destructive for a stronger UI confirm.

False

Returns:

Name Type Description
AdminAction AdminAction

The action metadata + handler. Its handler

AdminAction

carries the @admin_action marker, so pass action.handler

AdminAction

to AdminModel(actions=[...]).