Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the manifest helper #1115

Merged
merged 1 commit into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions tests/payload/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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",
Expand Down Expand Up @@ -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],
Expand All @@ -289,7 +289,7 @@ async def test_manifest_generate(mocked_datetime):
},
},
],
"version": "",
"version": "0.0.0",
}


Expand Down
9 changes: 6 additions & 3 deletions yapapi/payload/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down