Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New metadata API: spec_version attribute validation #1430

Merged
merged 2 commits into from
Jun 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion tuf/api/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
# and currently, we are above 1000 lines by a small margin.
# pylint: disable=C0302

# We aim to support SPECIFICATION_VERSION and require the input metadata
# files to have the same major version (the first number) as ours.
SPECIFICATION_VERSION = ["1", "0", "19"]


class Metadata:
"""A container for signed TUF metadata.
Expand Down Expand Up @@ -290,10 +294,19 @@ def __init__(
expires: datetime,
unrecognized_fields: Optional[Mapping[str, Any]] = None,
) -> None:
spec_list = spec_version.split(".")
if (
len(spec_list) != 3
or not all(el.isdigit() for el in spec_list)
or spec_list[0] != SPECIFICATION_VERSION[0]
):
raise ValueError(
f"Unsupported spec_version, got {spec_list}, "
f"supported {'.'.join(SPECIFICATION_VERSION)}"
)
self.spec_version = spec_version
self.expires = expires

# TODO: Should we separate data validation from constructor?
if version <= 0:
raise ValueError(f"version must be > 0, got {version}")
self.version = version
Expand Down