-
Notifications
You must be signed in to change notification settings - Fork 275
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
Metadata API: validate root role names #1630
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,7 @@ | |
# 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"] | ||
TOP_LEVEL_ROLE_NAMES = {"root", "timestamp", "snapshot", "targets"} | ||
|
||
# T is a Generic type constraint for Metadata.signed | ||
T = TypeVar("T", "Root", "Timestamp", "Snapshot", "Targets") | ||
|
@@ -728,6 +729,9 @@ def __init__( | |
super().__init__(version, spec_version, expires, unrecognized_fields) | ||
self.consistent_snapshot = consistent_snapshot | ||
self.keys = keys | ||
if set(roles) != TOP_LEVEL_ROLE_NAMES: | ||
raise ValueError("Role names must be the top-level metadata roles") | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be helpful to include the received, i.e. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd avoid any complexity. We're preparing for one of two options:
complex error message would have very limited value in both cases |
||
self.roles = roles | ||
|
||
@classmethod | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that
set
s are unordered. If the original order, i.e.["root", "timestamp", "snapshot", "targets"]
, needs to be guaranteed, you can't useTOP_LEVEL_ROLE_NAMES
here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good note. I don't think the order matters here, am I right @jku?
Also, I decided to use a set, instead of a list for
TOP_LEVEL_ROLE_NAMES
because of this check:if set(roles) != TOP_LEVEL_ROLE_NAMES:
in tuf/api/metadata.py in Root.init() will result asfalse
even if roles have the same content as TOP_LEVEL_ROLE_NAMES. The reason is that one is a list and the other is a set.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think using a set makes sense. If it turns out that there are many use cases that require the same particular order of the top-level role names, we can still add another global that is a list, or make this one an ordered set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WFM