Skip to content

Commit

Permalink
Merge pull request #73 from inab/jmfernandez
Browse files Browse the repository at this point in the history
Fixes related to image signatures handling
  • Loading branch information
jmfernandez authored Oct 9, 2023
2 parents 0322f12 + 385e0fb commit 93901ff
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion wfexs_backend/cache_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,8 @@ def fetch(
# Store the metadata
metadata_array.extend(cached_fetched_metadata_array)
licences.extend(the_licences)
final_fingerprint = metaStructure["fingerprint"]
if "fingerprint" in metaStructure:
final_fingerprint = metaStructure["fingerprint"]
elif offline:
# As this is a handler for online resources, comply with offline mode
raise CacheOfflineException(
Expand Down
2 changes: 2 additions & 0 deletions wfexs_backend/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class Container(ContainerTaggedName):
metadataLocalPath: The full local path to the container metadata file (it can be None)
source_type: This one helps to identify transformations. The original source
might be a docker registry, but the materialized one is a singularity image.
image_signature: The signature of the image
"""

taggedName: "URIType" = cast("URIType", "")
Expand All @@ -121,6 +122,7 @@ class Container(ContainerTaggedName):
fingerprint: "Optional[Fingerprint]" = None
metadataLocalPath: "Optional[AbsPath]" = None
source_type: "Optional[ContainerType]" = None
image_signature: "Optional[Fingerprint]" = None

def _value_defaults_fixes(self) -> None:
# This code is needed for old working directories
Expand Down
1 change: 1 addition & 0 deletions wfexs_backend/docker_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ def materializeSingleContainer(
registries=tag.registries,
metadataLocalPath=containerPathMeta,
source_type=tag.type,
image_signature=imageSignature,
)

def deploySingleContainer(
Expand Down
1 change: 1 addition & 0 deletions wfexs_backend/podman_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ def materializeSingleContainer(
registries=tag.registries,
metadataLocalPath=containerPathMeta,
source_type=tag.type,
image_signature=imageSignature,
)

def deploySingleContainer(
Expand Down
7 changes: 4 additions & 3 deletions wfexs_backend/ro_crate.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ class ContainerImageAdditionalType(enum.Enum):
ContainerType2AdditionalType: "Mapping[ContainerType, ContainerImageAdditionalType]" = {
ContainerType.Docker: ContainerImageAdditionalType.Docker,
ContainerType.Singularity: ContainerImageAdditionalType.Singularity,
ContainerType.Podman: ContainerImageAdditionalType.Docker,
}


Expand Down Expand Up @@ -1155,10 +1156,10 @@ def _add_containers(
)
if do_attach and container.localPath is not None:
the_size = os.stat(container.localPath).st_size
assert container.signature is not None
digest, algo = extract_digest(container.signature)
assert container.image_signature is not None
digest, algo = extract_digest(container.image_signature)
if digest is None:
digest, algo = unstringifyDigest(container.signature)
digest, algo = unstringifyDigest(container.image_signature)
assert algo is not None
the_signature = hexDigest(algo, digest)

Expand Down
1 change: 1 addition & 0 deletions wfexs_backend/singularity_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,7 @@ def _materializeSingleContainerSing(
registries=tag.registries,
metadataLocalPath=containerPathMeta,
source_type=tag.type,
image_signature=imageSignature,
)

def materializeContainers(
Expand Down
2 changes: 2 additions & 0 deletions wfexs_backend/utils/digests.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ def stringifyDigest(digestAlgorithm: "str", digest: "bytes") -> "Fingerprint":


def unstringifyDigest(digestion: "Fingerprint") -> "Tuple[bytes, str]":
if "=" not in digestion:
raise ValueError(f"The input string {digestion} is not a stringified digest")
algo, b64digest = digestion.split("=", 1)
return base64.b64decode(b64digest), algo

Expand Down

0 comments on commit 93901ff

Please sign in to comment.