-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
generic fetcher: Add models for lockfile
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
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |