Fix manifest UI display for manifests with empty layers

Also fixes the command for schema 2 manifests
This commit is contained in:
Joseph Schorr 2018-12-10 17:10:54 -05:00
parent 4106f5ce51
commit 7fa60d5802
2 changed files with 22 additions and 4 deletions

View file

@ -1,5 +1,6 @@
""" Manage the manifests of a repository. """
import json
import logging
from flask import request
@ -20,6 +21,9 @@ BASE_MANIFEST_ROUTE = '/v1/repository/<apirepopath:repository>/manifest/<regex("
MANIFEST_DIGEST_ROUTE = BASE_MANIFEST_ROUTE.format(digest_tools.DIGEST_PATTERN)
ALLOWED_LABEL_MEDIA_TYPES = ['text/plain', 'application/json']
logger = logging.getLogger(__name__)
def _label_dict(label):
return {
'id': label.uuid,
@ -31,10 +35,12 @@ def _label_dict(label):
def _layer_dict(manifest_layer, index):
# NOTE: The `command` in the layer is either a JSON string of an array (schema 1) or
# a single string (schema 2). The block below normalizes it to have the same format.
try:
command = json.loads(manifest_layer.command)
except (TypeError, ValueError):
command = []
command = [manifest_layer.command]
return {
'index': index,
@ -53,6 +59,10 @@ def _manifest_dict(manifest):
image = image_dict(manifest.legacy_image, with_history=True)
layers = registry_model.list_manifest_layers(manifest, storage)
if layers is None and not manifest.is_manifest_list:
logger.debug('Missing layers for manifest `%s`', manifest.digest)
abort(404)
return {
'digest': manifest.digest,
'is_manifest_list': manifest.is_manifest_list,