From 982a8c7fd5bf7420edb09053b86a967eac3d2e5f Mon Sep 17 00:00:00 2001 From: shadeofblue Date: Thu, 30 Mar 2023 09:39:17 +0200 Subject: [PATCH] fix the manifest helper --- tests/payload/test_manifest.py | 12 ++++++------ yapapi/payload/manifest.py | 9 ++++++--- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/tests/payload/test_manifest.py b/tests/payload/test_manifest.py index ffee97693..6b5d7b21b 100644 --- a/tests/payload/test_manifest.py +++ b/tests/payload/test_manifest.py @@ -180,7 +180,7 @@ def test_manifest_parse_obj(manifest_obj, manifest_dict): @mock.patch( - "yapapi.payload.manifest.datetime", **{"utcnow.return_value": datetime(2020, 1, 1, tzinfo=UTC)} + "yapapi.payload.manifest.datetime", **{"now.return_value": datetime(2020, 1, 1, tzinfo=UTC)} ) def test_manifest_with_minimal_data(mocked_datetime): payload_hash = "asd" @@ -206,13 +206,13 @@ def test_manifest_with_minimal_data(mocked_datetime): }, }, ], - "version": "", + "version": "0.0.0", } @pytest.mark.asyncio @mock.patch( - "yapapi.payload.manifest.datetime", **{"utcnow.return_value": datetime(2020, 1, 1, tzinfo=UTC)} + "yapapi.payload.manifest.datetime", **{"now.return_value": datetime(2020, 1, 1, tzinfo=UTC)} ) @mock.patch( "yapapi.payload.vm.repo", @@ -270,13 +270,13 @@ async def test_manifest_generate(mocked_datetime): }, }, }, - "version": "", + "version": "0.0.0", }, "created_at": "2020-01-01T00:00:00+00:00", "expires_at": "2100-01-01T00:00:00+00:00", "payload": [ { - "hash": payload_hash, + "hash": f"sha3:{payload_hash}", "urls": [ payload_urls[0], payload_urls[1], @@ -289,7 +289,7 @@ async def test_manifest_generate(mocked_datetime): }, }, ], - "version": "", + "version": "0.0.0", } diff --git a/yapapi/payload/manifest.py b/yapapi/payload/manifest.py index 426770c3c..915ed2828 100644 --- a/yapapi/payload/manifest.py +++ b/yapapi/payload/manifest.py @@ -101,6 +101,9 @@ def parse_obj(cls, obj: Dict) -> "ManifestPayload": async def resolve_urls_from_hash(self) -> None: package = await vm.repo(image_hash=self.hash) + if ":" not in self.hash: + self.hash = f"sha3:{self.hash}" + full_url = await package.resolve_url() image_url = full_url.split(":", 3)[3] @@ -206,7 +209,7 @@ def parse_obj(cls, obj: Dict) -> "CompManifestNet": @dataclass class CompManifest: - version: str = "" + version: str = "0.0.0" script: Optional[CompManifestScript] = None net: Optional[CompManifestNet] = None @@ -239,10 +242,10 @@ def parse_obj(cls, obj: Dict) -> "CompManifest": @dataclass class Manifest: payload: List[ManifestPayload] - version: str = "" + version: str = "0.0.0" comp_manifest: Optional[CompManifest] = None # Using lambda helps with mocking in tests - created_at: datetime = field(default_factory=lambda: datetime.utcnow()) + created_at: datetime = field(default_factory=lambda: datetime.now(UTC)) expires_at: datetime = datetime(2100, 1, 1, tzinfo=UTC) metadata: Optional[ManifestMetadata] = None