Skip to content

Commit

Permalink
Add artifact as a new manifest type
Browse files Browse the repository at this point in the history
[noissue]
  • Loading branch information
git-hyagi authored and lubosmj committed Nov 1, 2024
1 parent 23bf3a3 commit 5737c0b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
25 changes: 24 additions & 1 deletion pulp_container/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ class Manifest(Content):
through_fields=("image_manifest", "manifest_list"),
)

def __init__(self, *args, **kwargs):
self._json_manifest = None
super().__init__(*args, **kwargs)

def init_metadata(self, manifest_data=None):
has_annotations = self.init_annotations(manifest_data)
has_labels = self.init_labels()
Expand Down Expand Up @@ -199,6 +203,9 @@ def init_manifest_nature(self):
elif media_type := self.is_cosign():
self.type = self.get_cosign_type(media_type)
return True
elif self.is_artifact():
self.type = MANIFEST_TYPE.ARTIFACT
return True
elif self.is_manifest_image():
self.type = MANIFEST_TYPE.IMAGE
return True
Expand All @@ -219,7 +226,9 @@ def is_manifest_image(self):

@property
def json_manifest(self):
return json.loads(self.data)
if not self._json_manifest:
self._json_manifest = json.loads(self.data)
return self._json_manifest

def is_cosign(self):
try:
Expand All @@ -244,6 +253,20 @@ def is_helm_chart(self):
except KeyError:
return False

def is_artifact(self):
# artifact is valid only for OCI spec
if self.media_type != MEDIA_TYPE.MANIFEST_OCI:
return False

if self.json_manifest.get("artifactType", None):
return True

manifest_config_media_type = self.json_manifest["config"]["mediaType"]
return (
manifest_config_media_type == MEDIA_TYPE.OCI_EMPTY_JSON
or manifest_config_media_type not in vars(MEDIA_TYPE).values()
)

class Meta:
default_related_name = "%(app_label)s_%(model_name)s"
unique_together = ("digest",)
Expand Down
9 changes: 5 additions & 4 deletions pulp_container/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,15 @@
SIGNATURE_API_EXTENSION_VERSION = 2

MANIFEST_TYPE = SimpleNamespace(
IMAGE="image",
ARTIFACT="artifact",
BOOTABLE="bootable",
FLATPAK="flatpak",
HELM="helm",
COSIGN_SIGNATURE="cosign_signature",
COSIGN_ATTESTATION="cosign_attestation",
COSIGN_ATTESTATION_BUNDLE="cosign_attestation_bundle",
COSIGN_SBOM="cosign_sbom",
COSIGN_SIGNATURE="cosign_signature",
FLATPAK="flatpak",
HELM="helm",
IMAGE="image",
INDEX="index",
UNKNOWN="unknown",
)
Expand Down

0 comments on commit 5737c0b

Please sign in to comment.