Skip to content

Commit a37df2e

Browse files
committed
Simulator: make _fetch_{metadata,target} public
Make _fetch_metadata and _fetch_taget public by renaming them to fetch_metadata and fetch_target. This will allow the removal of multiple pylint disables because of "accessing private members". Signed-off-by: Martin Vrachev <[email protected]>
1 parent d5d0b94 commit a37df2e

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

tests/repository_simulator.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def fetch(self, url: str) -> Iterator[bytes]:
216216
role = ver_and_name
217217
version = None
218218

219-
yield self._fetch_metadata(role, version)
219+
yield self.fetch_metadata(role, version)
220220
elif path.startswith("/targets/"):
221221
# figure out target path and hash prefix
222222
target_path = path[len("/targets/") :]
@@ -228,11 +228,11 @@ def fetch(self, url: str) -> Iterator[bytes]:
228228
prefix, _, filename = prefixed_filename.partition(".")
229229
target_path = f"{dir_parts}{sep}{filename}"
230230

231-
yield self._fetch_target(target_path, prefix)
231+
yield self.fetch_target(target_path, prefix)
232232
else:
233233
raise FetcherHTTPError(f"Unknown path '{path}'", 404)
234234

235-
def _fetch_target(
235+
def fetch_target(
236236
self, target_path: str, target_hash: Optional[str]
237237
) -> bytes:
238238
"""Return data for 'target_path', checking 'target_hash' if it is given.
@@ -253,9 +253,7 @@ def _fetch_target(
253253
logger.debug("fetched target %s", target_path)
254254
return repo_target.data
255255

256-
def _fetch_metadata(
257-
self, role: str, version: Optional[int] = None
258-
) -> bytes:
256+
def fetch_metadata(self, role: str, version: Optional[int] = None) -> bytes:
259257
"""Return signed metadata for 'role', using 'version' if it is given.
260258
261259
If version is None, non-versioned metadata is being requested.
@@ -298,7 +296,7 @@ def _fetch_metadata(
298296
def _compute_hashes_and_length(
299297
self, role: str
300298
) -> Tuple[Dict[str, str], int]:
301-
data = self._fetch_metadata(role)
299+
data = self.fetch_metadata(role)
302300
digest_object = sslib_hash.digest(sslib_hash.DEFAULT_HASH_ALGORITHM)
303301
digest_object.update(data)
304302
hashes = {sslib_hash.DEFAULT_HASH_ALGORITHM: digest_object.hexdigest()}
@@ -392,12 +390,12 @@ def write(self) -> None:
392390

393391
for ver in range(1, len(self.signed_roots) + 1):
394392
with open(os.path.join(dest_dir, f"{ver}.root.json"), "wb") as f:
395-
f.write(self._fetch_metadata(Root.type, ver))
393+
f.write(self.fetch_metadata(Root.type, ver))
396394

397395
for role in [Timestamp.type, Snapshot.type, Targets.type]:
398396
with open(os.path.join(dest_dir, f"{role}.json"), "wb") as f:
399-
f.write(self._fetch_metadata(role))
397+
f.write(self.fetch_metadata(role))
400398

401399
for role in self.md_delegates:
402400
with open(os.path.join(dest_dir, f"{role}.json"), "wb") as f:
403-
f.write(self._fetch_metadata(role))
401+
f.write(self.fetch_metadata(role))

tests/test_updater_key_rotations.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ def test_non_root_rotations(self, md_version: MdVersion) -> None:
268268
self._run_refresh()
269269

270270
# Call fetch_metadata to sign metadata with new keys
271-
expected_local_md: bytes = self.sim._fetch_metadata(role)
271+
expected_local_md: bytes = self.sim.fetch_metadata(role)
272272
# assert local metadata role is on disk as expected
273273
md_path = os.path.join(self.metadata_dir, f"{role}.json")
274274
with open(md_path, "rb") as f:

tests/test_updater_top_level_update.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ def _assert_content_equals(
9090
self, role: str, version: Optional[int] = None
9191
) -> None:
9292
"""Assert that local file content is the expected"""
93-
# pylint: disable=protected-access
94-
expected_content = self.sim._fetch_metadata(role, version)
93+
expected_content = self.sim.fetch_metadata(role, version)
9594
with open(os.path.join(self.metadata_dir, f"{role}.json"), "rb") as f:
9695
self.assertEqual(f.read(), expected_content)
9796

0 commit comments

Comments
 (0)