diff --git a/endpoints/api/tag.py b/endpoints/api/tag.py index 8c3516399..7b1f8c8cc 100644 --- a/endpoints/api/tag.py +++ b/endpoints/api/tag.py @@ -160,15 +160,30 @@ class RepositoryTag(RepositoryParamResource): else: raise InvalidRequest('Could not update tag expiration; Tag has probably changed') - if 'image' in request.get_json(): + if 'image' in request.get_json() or 'manifest_digest' in request.get_json(): existing_tag = registry_model.get_repo_tag(repo_ref, tag, include_legacy_image=True) - image_id = request.get_json()['image'] - image = registry_model.get_legacy_image(repo_ref, image_id) - if image is None: + manifest_or_image = None + image_id = None + manifest_digest = None + + if 'image' in request.get_json(): + image_id = request.get_json()['image'] + manifest_or_image = registry_model.get_legacy_image(repo_ref, image_id) + else: + manifest_digest = request.get_json()['manifest_digest'] + manifest_or_image = registry_model.lookup_manifest_by_digest(repo_ref, manifest_digest) + + if manifest_or_image is None: raise NotFound() - if not registry_model.retarget_tag(repo_ref, tag, image, storage): + # TODO(jschorr): Remove this check once fully on V22 + existing_manifest_digest = None + if existing_tag: + existing_manifest = registry_model.get_manifest_for_tag(existing_tag) + existing_manifest_digest = existing_manifest.digest if existing_manifest else None + + if not registry_model.retarget_tag(repo_ref, tag, manifest_or_image, storage): raise InvalidRequest('Could not move tag') username = get_authenticated_user().username @@ -179,7 +194,11 @@ class RepositoryTag(RepositoryParamResource): 'tag': tag, 'namespace': namespace, 'image': image_id, - 'original_image': existing_tag.legacy_image.docker_image_id if existing_tag else None, + 'manifest_digest': manifest_digest, + 'original_image': (existing_tag.legacy_image.docker_image_id + if existing_tag and existing_tag.legacy_image_if_present + else None), + 'original_manifest_digest': existing_manifest_digest, }, repo_name=repository) return 'Updated', 201 diff --git a/static/directives/tag-operations-dialog.html b/static/directives/tag-operations-dialog.html index ba17c3c6f..f9a2562e8 100644 --- a/static/directives/tag-operations-dialog.html +++ b/static/directives/tag-operations-dialog.html @@ -47,9 +47,9 @@