Skip to content

Commit 4158272

Browse files
committed
Use TOP_LEVEL_ROLE_NAMES across TUF
Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
1 parent 9bc55ee commit 4158272

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

tests/repository_simulator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
from typing import Dict, Iterator, List, Optional, Tuple
5757
from urllib import parse
5858

59+
from tuf.api.metadata import TOP_LEVEL_ROLE_NAMES
5960
from tuf.api.serialization.json import JSONSerializer
6061
from tuf.exceptions import FetcherHTTPError
6162
from tuf.api.metadata import (
@@ -152,11 +153,10 @@ def _initialize(self):
152153
timestamp = Timestamp(1, SPEC_VER, self.safe_expiry, snapshot_meta)
153154
self.md_timestamp = Metadata(timestamp, OrderedDict())
154155

155-
top_level_md = ["root", "timestamp", "snapshot", "targets"]
156-
roles = {role_name: Role([], 1) for role_name in top_level_md}
156+
roles = {role_name: Role([], 1) for role_name in TOP_LEVEL_ROLE_NAMES}
157157
root = Root(1, SPEC_VER, self.safe_expiry, {}, roles, True)
158158

159-
for role in top_level_md:
159+
for role in TOP_LEVEL_ROLE_NAMES:
160160
key, signer = self.create_key()
161161
root.add_key(role, key)
162162
# store the private key

tuf/api/metadata.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,8 +729,7 @@ def __init__(
729729
super().__init__(version, spec_version, expires, unrecognized_fields)
730730
self.consistent_snapshot = consistent_snapshot
731731
self.keys = keys
732-
mandatory_roles = ["root", "timestamp", "snapshot", "targets"]
733-
if not (len(roles) == 4 and all(r in roles for r in mandatory_roles)):
732+
if set(roles) != TOP_LEVEL_ROLE_NAMES:
734733
raise ValueError("Role names must be the top-level metadata roles")
735734

736735
self.roles = roles

0 commit comments

Comments
 (0)