data.oci_model: sloppily rewrite digest format
We expect digests to be in the form 'sha256:digest'
This commit is contained in:
parent
2c8930c912
commit
9c0cbbf57c
5 changed files with 41 additions and 10 deletions
|
@ -306,7 +306,8 @@ class OCIAppModel(AppRegistryDataInterface):
|
|||
tag, manifest, blob = oci_model.release.get_app_release(repo, release, media_type)
|
||||
created_at = _timestamp_to_iso(tag.lifetime_start)
|
||||
|
||||
blob_descriptor = BlobDescriptor(digest=blob.digest, mediaType=blob.media_type.name,
|
||||
blob_descriptor = BlobDescriptor(digest=_strip_sha256_header(blob.digest),
|
||||
mediaType=blob.media_type.name,
|
||||
size=blob.size, urls=[])
|
||||
|
||||
app_manifest = ApplicationManifest(digest=manifest.digest, mediaType=manifest.media_type.name,
|
||||
|
@ -333,7 +334,9 @@ class OCIAppModel(AppRegistryDataInterface):
|
|||
cnrblob.size,
|
||||
content_media_type,
|
||||
locations)
|
||||
return BlobDescriptor(mediaType=content_media_type, digest=db_blob.digest, size=db_blob.size,
|
||||
return BlobDescriptor(mediaType=content_media_type,
|
||||
digest=_strip_sha256_header(db_blob.digest),
|
||||
size=db_blob.size,
|
||||
urls=[])
|
||||
|
||||
def create_release(self, package, user, visibility, force=False):
|
||||
|
@ -425,4 +428,7 @@ class OCIAppModel(AppRegistryDataInterface):
|
|||
name=channel.name)
|
||||
|
||||
|
||||
def _strip_sha256_header(digest):
|
||||
return digest.lstrip('sha256:')
|
||||
|
||||
oci_app_model = OCIAppModel()
|
||||
|
|
|
@ -4,9 +4,15 @@ from data.model import db_transaction
|
|||
from data.database import Blob, BlobPlacementLocation, BlobPlacement
|
||||
|
||||
|
||||
def _ensure_sha256_header(digest):
|
||||
if digest.startswith('sha256:'):
|
||||
return digest
|
||||
return 'sha256:' + digest
|
||||
|
||||
|
||||
def get_blob(digest):
|
||||
""" Find a blob by its digest. """
|
||||
return Blob.select().where(Blob.digest == digest).get()
|
||||
return Blob.select().where(Blob.digest == _ensure_sha256_header(digest)).get()
|
||||
|
||||
|
||||
def get_or_create_blob(digest, size, media_type_name, locations):
|
||||
|
@ -15,7 +21,7 @@ def get_or_create_blob(digest, size, media_type_name, locations):
|
|||
try:
|
||||
blob = get_blob(digest)
|
||||
except Blob.DoesNotExist:
|
||||
blob = Blob.create(digest=digest,
|
||||
blob = Blob.create(digest=_ensure_sha256_header(digest),
|
||||
media_type_id=Blob.media_type.get_id(media_type_name),
|
||||
size=size)
|
||||
for location_name in locations:
|
||||
|
@ -35,7 +41,7 @@ def get_blob_locations(digest):
|
|||
.select()
|
||||
.join(BlobPlacement)
|
||||
.join(Blob)
|
||||
.where(Blob.digest == digest)]
|
||||
.where(Blob.digest == _ensure_sha256_header(digest))]
|
||||
|
||||
|
||||
def ensure_blob_locations(*names):
|
||||
|
|
|
@ -11,12 +11,18 @@ from data.oci_model import tag as tag_model
|
|||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _ensure_sha256_header(digest):
|
||||
if digest.startswith('sha256:'):
|
||||
return digest
|
||||
return 'sha256:' + digest
|
||||
|
||||
|
||||
def _digest(manifestjson):
|
||||
return hashlib.sha256(json.dumps(manifestjson, sort_keys=True)).hexdigest()
|
||||
return _ensure_sha256_header(hashlib.sha256(json.dumps(manifestjson, sort_keys=True)).hexdigest())
|
||||
|
||||
|
||||
def get_manifest_query(digest, media_type):
|
||||
return Manifest.select().where(Manifest.digest == digest,
|
||||
return Manifest.select().where(Manifest.digest == _ensure_sha256_header(digest),
|
||||
Manifest.media_type == Manifest.media_type.get_id(media_type))
|
||||
|
||||
|
||||
|
|
|
@ -8,12 +8,18 @@ from data.database import ManifestList, ManifestListManifest, db_transaction
|
|||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _ensure_sha256_header(digest):
|
||||
if digest.startswith('sha256:'):
|
||||
return digest
|
||||
return 'sha256:' + digest
|
||||
|
||||
|
||||
def _digest(manifestjson):
|
||||
return hashlib.sha256(json.dumps(manifestjson, sort_keys=True)).hexdigest()
|
||||
return _ensure_sha256_header(hashlib.sha256(json.dumps(manifestjson, sort_keys=True)).hexdigest())
|
||||
|
||||
|
||||
def get_manifest_list(digest):
|
||||
return ManifestList.select().where(ManifestList.digest == digest).get()
|
||||
return ManifestList.select().where(ManifestList.digest == _ensure_sha256_header(digest)).get()
|
||||
|
||||
|
||||
def get_or_create_manifest_list(manifest_list_json, media_type_name, schema_version):
|
||||
|
|
|
@ -14,6 +14,12 @@ LIST_MEDIA_TYPE = 'application/vnd.cnr.manifest.list.v0.json'
|
|||
SCHEMA_VERSION = 'v0'
|
||||
|
||||
|
||||
def _ensure_sha256_header(digest):
|
||||
if digest.startswith('sha256:'):
|
||||
return digest
|
||||
return 'sha256:' + digest
|
||||
|
||||
|
||||
def get_app_release(repo, tag_name, media_type):
|
||||
""" Returns (tag, manifest, blob) given a repo object, tag_name, and media_type). """
|
||||
tag = tag_model.get_tag(repo, tag_name, tag_kind='release')
|
||||
|
@ -67,7 +73,8 @@ def create_app_release(repo, tag_name, manifest, digest):
|
|||
(ManifestBlob
|
||||
.select()
|
||||
.join(Blob)
|
||||
.where(ManifestBlob.manifest == manifest, Blob.digest == blob_digest).get())
|
||||
.where(ManifestBlob.manifest == manifest,
|
||||
Blob.digest == _ensure_sha256_header(blob_digest)).get())
|
||||
except ManifestBlob.DoesNotExist:
|
||||
blob = blob_model.get_blob(blob_digest)
|
||||
ManifestBlob.create(manifest=manifest, blob=blob)
|
||||
|
|
Reference in a new issue