Skip to content

Commit 37de690

Browse files
committed
Change "update()" argument types
Currently, when we call Targets/Snapshot/Timestamp.update() we are passing all of the necessary values to create MetaFile/Targets File respectively. This is not needed, given that one of the reasons we have created MetaFile and TargetFile is to make the API easier to use. Signed-off-by: Martin Vrachev <[email protected]>
1 parent aaa5bb4 commit 37de690

File tree

2 files changed

+11
-22
lines changed

2 files changed

+11
-22
lines changed

tests/test_api.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,14 +301,14 @@ def test_metadata_snapshot(self):
301301
self.assertNotEqual(
302302
snapshot.signed.meta['role1.json'].to_dict(), fileinfo.to_dict()
303303
)
304-
snapshot.signed.update('role1', 2, 123, hashes)
304+
snapshot.signed.update('role1', fileinfo)
305305
self.assertEqual(
306306
snapshot.signed.meta['role1.json'].to_dict(), fileinfo.to_dict()
307307
)
308308

309309
# Update only version. Length and hashes are optional.
310-
snapshot.signed.update('role2', 3)
311310
fileinfo = MetaFile(3)
311+
snapshot.signed.update('role2', fileinfo)
312312
self.assertEqual(
313313
snapshot.signed.meta['role2.json'].to_dict(), fileinfo.to_dict()
314314
)
@@ -353,7 +353,7 @@ def test_metadata_timestamp(self):
353353
self.assertNotEqual(
354354
timestamp.signed.meta['snapshot.json'].to_dict(), fileinfo.to_dict()
355355
)
356-
timestamp.signed.update(2, 520, hashes)
356+
timestamp.signed.update(fileinfo)
357357
self.assertEqual(
358358
timestamp.signed.meta['snapshot.json'].to_dict(), fileinfo.to_dict()
359359
)
@@ -367,8 +367,8 @@ def test_metadata_timestamp(self):
367367
self.assertEqual(timestamp_dict['signed'], timestamp_test.to_dict())
368368

369369
# Update only version. Length and hashes are optional.
370-
timestamp.signed.update(3)
371370
fileinfo = MetaFile(version=3)
371+
timestamp.signed.update(fileinfo)
372372
self.assertEqual(
373373
timestamp.signed.meta['snapshot.json'].to_dict(), fileinfo.to_dict()
374374
)
@@ -593,7 +593,7 @@ def test_metadata_targets(self):
593593
targets.signed.targets[filename].to_dict(), fileinfo.to_dict()
594594
)
595595
# Update an already existing fileinfo
596-
targets.signed.update(filename, fileinfo.to_dict())
596+
targets.signed.update(filename, fileinfo)
597597
# Verify that data is updated
598598
self.assertEqual(
599599
targets.signed.targets[filename].to_dict(), fileinfo.to_dict()

tuf/api/metadata.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -700,14 +700,9 @@ def to_dict(self) -> Dict[str, Any]:
700700
return res_dict
701701

702702
# Modification.
703-
def update(
704-
self,
705-
version: int,
706-
length: Optional[int] = None,
707-
hashes: Optional[Dict[str, Any]] = None,
708-
) -> None:
703+
def update(self, snapshot_meta: MetaFile) -> None:
709704
"""Assigns passed info about snapshot metadata to meta dict."""
710-
self.meta["snapshot.json"] = MetaFile(version, length, hashes)
705+
self.meta["snapshot.json"] = snapshot_meta
711706

712707

713708
class Snapshot(Signed):
@@ -759,16 +754,10 @@ def to_dict(self) -> Dict[str, Any]:
759754
return snapshot_dict
760755

761756
# Modification.
762-
def update(
763-
self,
764-
rolename: str,
765-
version: int,
766-
length: Optional[int] = None,
767-
hashes: Optional[Dict[str, Any]] = None,
768-
) -> None:
757+
def update(self, rolename: str, role_info: MetaFile) -> None:
769758
"""Assigns passed (delegated) targets role info to meta dict."""
770759
metadata_fn = f"{rolename}.json"
771-
self.meta[metadata_fn] = MetaFile(version, length, hashes)
760+
self.meta[metadata_fn] = role_info
772761

773762

774763
class DelegatedRole(Role):
@@ -1010,6 +999,6 @@ def to_dict(self) -> Dict[str, Any]:
1010999
return targets_dict
10111000

10121001
# Modification.
1013-
def update(self, filename: str, fileinfo: Dict[str, Any]) -> None:
1002+
def update(self, filename: str, fileinfo: TargetFile) -> None:
10141003
"""Assigns passed target file info to meta dict."""
1015-
self.targets[filename] = TargetFile.from_dict(fileinfo)
1004+
self.targets[filename] = fileinfo

0 commit comments

Comments
 (0)