Skip to content

Commit ef4eefc

Browse files
author
Kairo de Araujo
committed
Revert not related changes in repository_simulator
Revert not related changes in repository_simulator to the actual PR. Signed-off-by: Kairo de Araujo <[email protected]>
1 parent df3dd90 commit ef4eefc

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

tests/repository_simulator.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def targets(self) -> Targets:
149149

150150
def all_targets(self) -> Iterator[Tuple[str, Targets]]:
151151
"""Yield role name and signed portion of targets one by one."""
152-
yield "targets", self.md_targets.signed
152+
yield Targets.type, self.md_targets.signed
153153
for role, md in self.md_delegates.items():
154154
yield role, md.signed
155155

@@ -191,7 +191,7 @@ def _initialize(self) -> None:
191191
def publish_root(self) -> None:
192192
"""Sign and store a new serialized version of root."""
193193
self.md_root.signatures.clear()
194-
for signer in self.signers["root"].values():
194+
for signer in self.signers[Root.type].values():
195195
self.md_root.sign(signer, append=True)
196196

197197
self.signed_roots.append(self.md_root.to_bytes(JSONSerializer()))
@@ -207,8 +207,8 @@ def fetch(self, url: str) -> Iterator[bytes]:
207207
ver_and_name = path[len("/metadata/") :][: -len(".json")]
208208
version_str, _, role = ver_and_name.partition(".")
209209
# root is always version-prefixed while timestamp is always NOT
210-
if role == "root" or (
211-
self.root.consistent_snapshot and ver_and_name != "timestamp"
210+
if role == Root.type or (
211+
self.root.consistent_snapshot and ver_and_name != Timestamp.type
212212
):
213213
version: Optional[int] = int(version_str)
214214
else:
@@ -262,7 +262,7 @@ def _fetch_metadata(
262262
"""
263263
self.fetch_tracker.metadata.append((role, version))
264264

265-
if role == "root":
265+
if role == Root.type:
266266
# return a version previously serialized in publish_root()
267267
if version is None or version > len(self.signed_roots):
268268
raise FetcherHTTPError(f"Unknown root version {version}", 404)
@@ -271,11 +271,11 @@ def _fetch_metadata(
271271

272272
# sign and serialize the requested metadata
273273
md: Optional[Metadata]
274-
if role == "timestamp":
274+
if role == Timestamp.type:
275275
md = self.md_timestamp
276-
elif role == "snapshot":
276+
elif role == Snapshot.type:
277277
md = self.md_snapshot
278-
elif role == "targets":
278+
elif role == Targets.type:
279279
md = self.md_targets
280280
else:
281281
md = self.md_delegates.get(role)
@@ -311,7 +311,7 @@ def update_timestamp(self) -> None:
311311
self.timestamp.snapshot_meta.version = self.snapshot.version
312312

313313
if self.compute_metafile_hashes_length:
314-
hashes, length = self._compute_hashes_and_length("snapshot")
314+
hashes, length = self._compute_hashes_and_length(Snapshot.type)
315315
self.timestamp.snapshot_meta.hashes = hashes
316316
self.timestamp.snapshot_meta.length = length
317317

@@ -334,7 +334,7 @@ def update_snapshot(self) -> None:
334334

335335
def add_target(self, role: str, data: bytes, path: str) -> None:
336336
"""Create a target from data and add it to the target_files."""
337-
if role == "targets":
337+
if role == Targets.type:
338338
targets = self.targets
339339
else:
340340
targets = self.md_delegates[role].signed
@@ -353,7 +353,7 @@ def add_delegation(
353353
hash_prefixes: Optional[List[str]],
354354
) -> None:
355355
"""Add delegated target role to the repository."""
356-
if delegator_name == "targets":
356+
if delegator_name == Targets.type:
357357
delegator = self.targets
358358
else:
359359
delegator = self.md_delegates[delegator_name].signed
@@ -389,9 +389,9 @@ def write(self) -> None:
389389

390390
for ver in range(1, len(self.signed_roots) + 1):
391391
with open(os.path.join(dest_dir, f"{ver}.root.json"), "wb") as f:
392-
f.write(self._fetch_metadata("root", ver))
392+
f.write(self._fetch_metadata(Root.type, ver))
393393

394-
for role in ["timestamp", "snapshot", "targets"]:
394+
for role in [Timestamp.type, Snapshot.type, Targets.type]:
395395
with open(os.path.join(dest_dir, f"{role}.json"), "wb") as f:
396396
f.write(self._fetch_metadata(role))
397397

0 commit comments

Comments
 (0)