Skip to content

Commit

Permalink
generic fetcher: Add models for lockfile
Browse files Browse the repository at this point in the history
Adds pydantic models that will be used to represent and validate
the lockfile for the generic fetcher.

Signed-off-by: Jan Koscielniak <[email protected]>
  • Loading branch information
kosciCZ authored and eskultety committed Oct 15, 2024
1 parent d47d051 commit be0887e
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions cachi2/core/package_managers/generic/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from typing import Literal, Optional

from pydantic import BaseModel, field_validator


class LockfileMetadata(BaseModel):
"""Defines format of the metadata section in the lockfile."""

version: Literal["1.0"]


class LockfileArtifact(BaseModel):
"""Defines format of a single artifact in the lockfile."""

download_url: str
target: Optional[str] = None
checksums: dict[str, str]

@field_validator("checksums")
@classmethod
def no_empty_checksums(cls, value: dict[str, str]) -> dict[str, str]:
"""
Validate that at least one checksum is present for an artifact.
:param value: the checksums dict to validate
:return: the validated checksum dict
"""
if len(value) == 0:
raise ValueError("At least one checksum must be provided.")
return value


class GenericLockfileV1(BaseModel):
"""Defines format of the cachi2 generic lockfile, version 1.0."""

metadata: LockfileMetadata
artifacts: list[LockfileArtifact]

0 comments on commit be0887e

Please sign in to comment.