Skip to content

Commit c04f712

Browse files
committed
Metadata API: snapshot_meta property in Timestamp
In Timestamp, the only valid "meta" value is the dictionary representing meta information for the snapshot file. That's why we want to provide an access to it without changing the timestamp representation through the Timestamp class. Signed-off-by: Martin Vrachev <[email protected]>
1 parent bd5912b commit c04f712

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

tests/test_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,11 +326,11 @@ def test_metadata_timestamp(self):
326326
fileinfo = MetaFile(2, 520, hashes)
327327

328328
self.assertNotEqual(
329-
timestamp.signed.meta['snapshot.json'].to_dict(), fileinfo.to_dict()
329+
timestamp.signed.snapshot_meta.to_dict(), fileinfo.to_dict()
330330
)
331331
timestamp.signed.update(fileinfo)
332332
self.assertEqual(
333-
timestamp.signed.meta['snapshot.json'].to_dict(), fileinfo.to_dict()
333+
timestamp.signed.snapshot_meta.to_dict(), fileinfo.to_dict()
334334
)
335335

336336

tuf/api/metadata.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,14 @@ class Timestamp(Signed):
855855

856856
_signed_type = "timestamp"
857857

858+
@property
859+
def snapshot_meta(self):
860+
return self.meta["snapshot.json"]
861+
862+
@snapshot_meta.setter
863+
def snapshot_meta(self, value):
864+
self.meta["snapshot.json"] = value
865+
858866
def __init__(
859867
self,
860868
version: int,
@@ -878,15 +886,13 @@ def from_dict(cls, signed_dict: Dict[str, Any]) -> "Timestamp":
878886
def to_dict(self) -> Dict[str, Any]:
879887
"""Returns the dict representation of self."""
880888
res_dict = self._common_fields_to_dict()
881-
res_dict["meta"] = {
882-
"snapshot.json": self.meta["snapshot.json"].to_dict()
883-
}
889+
res_dict["meta"] = {"snapshot.json": self.snapshot_meta.to_dict()}
884890
return res_dict
885891

886892
# Modification.
887893
def update(self, snapshot_meta: MetaFile) -> None:
888894
"""Assigns passed info about snapshot metadata to meta dict."""
889-
self.meta["snapshot.json"] = snapshot_meta
895+
self.snapshot_meta = snapshot_meta
890896

891897

892898
class Snapshot(Signed):

0 commit comments

Comments
 (0)