mirror of
https://github.com/theupdateframework/python-tuf
synced 2026-05-24 10:08:28 +00:00
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 <mvrachev@vmware.com>
This commit is contained in:
parent
d5d0b94f62
commit
a37df2eab4
3 changed files with 10 additions and 13 deletions
|
|
@ -216,7 +216,7 @@ def fetch(self, url: str) -> Iterator[bytes]:
|
|||
role = ver_and_name
|
||||
version = None
|
||||
|
||||
yield self._fetch_metadata(role, version)
|
||||
yield self.fetch_metadata(role, version)
|
||||
elif path.startswith("/targets/"):
|
||||
# figure out target path and hash prefix
|
||||
target_path = path[len("/targets/") :]
|
||||
|
|
@ -228,11 +228,11 @@ def fetch(self, url: str) -> Iterator[bytes]:
|
|||
prefix, _, filename = prefixed_filename.partition(".")
|
||||
target_path = f"{dir_parts}{sep}{filename}"
|
||||
|
||||
yield self._fetch_target(target_path, prefix)
|
||||
yield self.fetch_target(target_path, prefix)
|
||||
else:
|
||||
raise FetcherHTTPError(f"Unknown path '{path}'", 404)
|
||||
|
||||
def _fetch_target(
|
||||
def fetch_target(
|
||||
self, target_path: str, target_hash: Optional[str]
|
||||
) -> bytes:
|
||||
"""Return data for 'target_path', checking 'target_hash' if it is given.
|
||||
|
|
@ -253,9 +253,7 @@ def _fetch_target(
|
|||
logger.debug("fetched target %s", target_path)
|
||||
return repo_target.data
|
||||
|
||||
def _fetch_metadata(
|
||||
self, role: str, version: Optional[int] = None
|
||||
) -> bytes:
|
||||
def fetch_metadata(self, role: str, version: Optional[int] = None) -> bytes:
|
||||
"""Return signed metadata for 'role', using 'version' if it is given.
|
||||
|
||||
If version is None, non-versioned metadata is being requested.
|
||||
|
|
@ -298,7 +296,7 @@ def _fetch_metadata(
|
|||
def _compute_hashes_and_length(
|
||||
self, role: str
|
||||
) -> Tuple[Dict[str, str], int]:
|
||||
data = self._fetch_metadata(role)
|
||||
data = self.fetch_metadata(role)
|
||||
digest_object = sslib_hash.digest(sslib_hash.DEFAULT_HASH_ALGORITHM)
|
||||
digest_object.update(data)
|
||||
hashes = {sslib_hash.DEFAULT_HASH_ALGORITHM: digest_object.hexdigest()}
|
||||
|
|
@ -392,12 +390,12 @@ def write(self) -> None:
|
|||
|
||||
for ver in range(1, len(self.signed_roots) + 1):
|
||||
with open(os.path.join(dest_dir, f"{ver}.root.json"), "wb") as f:
|
||||
f.write(self._fetch_metadata(Root.type, ver))
|
||||
f.write(self.fetch_metadata(Root.type, ver))
|
||||
|
||||
for role in [Timestamp.type, Snapshot.type, Targets.type]:
|
||||
with open(os.path.join(dest_dir, f"{role}.json"), "wb") as f:
|
||||
f.write(self._fetch_metadata(role))
|
||||
f.write(self.fetch_metadata(role))
|
||||
|
||||
for role in self.md_delegates:
|
||||
with open(os.path.join(dest_dir, f"{role}.json"), "wb") as f:
|
||||
f.write(self._fetch_metadata(role))
|
||||
f.write(self.fetch_metadata(role))
|
||||
|
|
|
|||
|
|
@ -268,7 +268,7 @@ def test_non_root_rotations(self, md_version: MdVersion) -> None:
|
|||
self._run_refresh()
|
||||
|
||||
# Call fetch_metadata to sign metadata with new keys
|
||||
expected_local_md: bytes = self.sim._fetch_metadata(role)
|
||||
expected_local_md: bytes = self.sim.fetch_metadata(role)
|
||||
# assert local metadata role is on disk as expected
|
||||
md_path = os.path.join(self.metadata_dir, f"{role}.json")
|
||||
with open(md_path, "rb") as f:
|
||||
|
|
|
|||
|
|
@ -90,8 +90,7 @@ def _assert_content_equals(
|
|||
self, role: str, version: Optional[int] = None
|
||||
) -> None:
|
||||
"""Assert that local file content is the expected"""
|
||||
# pylint: disable=protected-access
|
||||
expected_content = self.sim._fetch_metadata(role, version)
|
||||
expected_content = self.sim.fetch_metadata(role, version)
|
||||
with open(os.path.join(self.metadata_dir, f"{role}.json"), "rb") as f:
|
||||
self.assertEqual(f.read(), expected_content)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue