Skip to content

Commit 0657cbb

Browse files
committed
Remove backward compatibility for manifest with artifact
This commit removes support for manifests storing their data inside an artifact instead of using the recently introduced Manifest.data text field. closes pulp#1621
1 parent 2c7a4da commit 0657cbb

File tree

6 files changed

+11
-141
lines changed

6 files changed

+11
-141
lines changed

CHANGES/1621.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Removed backward compatibility support for manifests which store their data inside an artifact.

pulp_container/app/redirects.py

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from django.conf import settings
22
from django.core.exceptions import ObjectDoesNotExist
33
from django.shortcuts import redirect
4-
from django.http import Http404
54

65
from pulp_container.app.exceptions import ManifestNotFound
76
from pulp_container.app.utils import get_accepted_media_types
@@ -91,47 +90,6 @@ def redirect_to_object_storage(self, artifact, return_media_type):
9190
)
9291
return redirect(content_url)
9392

94-
# TODO: BACKWARD COMPATIBILITY - remove after fully migrating to artifactless manifests
95-
def redirect_to_artifact(self, content_name, manifest, manifest_media_type):
96-
"""
97-
Search for the passed manifest's artifact and issue a redirect.
98-
"""
99-
try:
100-
artifact = manifest._artifacts.get()
101-
except ObjectDoesNotExist:
102-
raise Http404(f"An artifact for '{content_name}' was not found")
103-
104-
return self.redirect_to_object_storage(artifact, manifest_media_type)
105-
106-
def issue_tag_redirect(self, tag):
107-
"""
108-
Issue a redirect if an accepted media type requires it or return not found if manifest
109-
version is not supported.
110-
"""
111-
if tag.tagged_manifest.data:
112-
return super().issue_tag_redirect(tag)
113-
114-
manifest_media_type = tag.tagged_manifest.media_type
115-
if manifest_media_type == MEDIA_TYPE.MANIFEST_V1:
116-
return self.redirect_to_artifact(
117-
tag.name, tag.tagged_manifest, MEDIA_TYPE.MANIFEST_V1_SIGNED
118-
)
119-
elif manifest_media_type in get_accepted_media_types(self.request.headers):
120-
return self.redirect_to_artifact(tag.name, tag.tagged_manifest, manifest_media_type)
121-
else:
122-
raise ManifestNotFound(reference=tag.name)
123-
124-
def issue_manifest_redirect(self, manifest):
125-
"""
126-
Directly redirect to an associated manifest's artifact.
127-
"""
128-
if manifest.data:
129-
return super().issue_manifest_redirect(manifest)
130-
131-
return self.redirect_to_artifact(manifest.digest, manifest, manifest.media_type)
132-
133-
# END OF BACKWARD COMPATIBILITY
134-
13593

13694
class AzureStorageRedirects(S3StorageRedirects):
13795
"""

pulp_container/app/registry.py

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,6 @@ async def get_tag(self, request):
201201
"Content-Type": return_media_type,
202202
"Docker-Content-Digest": tag.tagged_manifest.digest,
203203
}
204-
# TODO: BACKWARD COMPATIBILITY - remove after fully migrating to artifactless manifest
205-
if not tag.tagged_manifest.data:
206-
return await self.dispatch_tag(request, tag, response_headers)
207-
# END OF BACKWARD COMPATIBILITY
208204
return web.Response(text=tag.tagged_manifest.data, headers=response_headers)
209205

210206
# return what was found in case media_type is accepted header (docker, oci)
@@ -214,41 +210,11 @@ async def get_tag(self, request):
214210
"Content-Type": return_media_type,
215211
"Docker-Content-Digest": tag.tagged_manifest.digest,
216212
}
217-
# TODO: BACKWARD COMPATIBILITY - remove after fully migrating to artifactless manifest
218-
if not tag.tagged_manifest.data:
219-
return await self.dispatch_tag(request, tag, response_headers)
220-
# END OF BACKWARD COMPATIBILITY
221213
return web.Response(text=tag.tagged_manifest.data, headers=response_headers)
222214

223215
# return 404 in case the client is requesting docker manifest v2 schema 1
224216
raise PathNotResolved(tag_name)
225217

226-
# TODO: BACKWARD COMPATIBILITY - remove after fully migrating to artifactless manifest
227-
async def dispatch_tag(self, request, tag, response_headers):
228-
"""
229-
Finds an artifact associated with a Tag and sends it to the client, otherwise tries
230-
to stream it.
231-
232-
Args:
233-
request(:class:`~aiohttp.web.Request`): The request to prepare a response for.
234-
tag: Tag
235-
response_headers (dict): dictionary that contains the 'Content-Type' header to send
236-
with the response
237-
238-
Returns:
239-
:class:`aiohttp.web.StreamResponse` or :class:`aiohttp.web.FileResponse`: The response
240-
streamed back to the client.
241-
242-
"""
243-
try:
244-
artifact = await tag.tagged_manifest._artifacts.aget()
245-
except ObjectDoesNotExist:
246-
ca = await sync_to_async(lambda x: x[0])(tag.tagged_manifest.contentartifact_set.all())
247-
return await self._stream_content_artifact(request, web.StreamResponse(), ca)
248-
else:
249-
return await Registry._dispatch(artifact, response_headers)
250-
# END OF BACKWARD COMPATIBILITY
251-
252218
@RegistryContentCache(
253219
base_key=lambda req, cac: Registry.find_base_path_cached(req, cac),
254220
auth=lambda req, cac, bk: Registry.auth_cached(req, cac, bk),
@@ -284,16 +250,6 @@ async def get_by_digest(self, request):
284250
"Content-Type": manifest.media_type,
285251
"Docker-Content-Digest": manifest.digest,
286252
}
287-
# TODO: BACKWARD COMPATIBILITY - remove after migrating to artifactless manifest
288-
if not manifest.data:
289-
if saved_artifact := await manifest._artifacts.afirst():
290-
return await Registry._dispatch(saved_artifact, headers)
291-
else:
292-
ca = await sync_to_async(lambda x: x[0])(manifest.contentartifact_set.all())
293-
return await self._stream_content_artifact(
294-
request, web.StreamResponse(), ca
295-
)
296-
# END OF BACKWARD COMPATIBILITY
297253
return web.Response(text=manifest.data, headers=headers)
298254
elif content_type == "blobs":
299255
ca = await ContentArtifact.objects.select_related("artifact", "content").aget(

pulp_container/app/registry_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ def handle_safe_method(self, request, path, pk):
10841084
else:
10851085
raise ManifestNotFound(reference=pk)
10861086

1087-
return redirects.issue_manifest_redirect(manifest)
1087+
return Response(manifest.data)
10881088

10891089
def get_content_units_to_add(self, manifest, tag):
10901090
add_content_units = [str(tag.pk), str(manifest.pk)]

pulp_container/app/tasks/sign.py

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import hashlib
44

55
from aiofiles import tempfile
6-
from asgiref.sync import sync_to_async
76
from django.conf import settings
87

98
from pulpcore.plugin.models import Repository
@@ -99,23 +98,10 @@ async def create_signature(manifest, reference, signing_service):
9998
"""
10099
async with semaphore:
101100
# download and write file for object storage
102-
if not manifest.data:
103-
# TODO: BACKWARD COMPATIBILITY - remove after fully migrating to artifactless manifest
104-
artifact = await manifest._artifacts.aget()
105-
if settings.DEFAULT_FILE_STORAGE != "pulpcore.app.models.storage.FileSystem":
106-
async with tempfile.NamedTemporaryFile(dir=".", mode="wb", delete=False) as tf:
107-
await tf.write(await sync_to_async(artifact.file.read)())
108-
await tf.flush()
109-
artifact.file.close()
110-
manifest_path = tf.name
111-
else:
112-
manifest_path = artifact.file.path
113-
# END OF BACKWARD COMPATIBILITY
114-
else:
115-
async with tempfile.NamedTemporaryFile(dir=".", mode="wb", delete=False) as tf:
116-
await tf.write(manifest.data.encode("utf-8"))
117-
await tf.flush()
118-
manifest_path = tf.name
101+
async with tempfile.NamedTemporaryFile(dir=".", mode="wb", delete=False) as tf:
102+
await tf.write(manifest.data.encode("utf-8"))
103+
await tf.flush()
104+
manifest_path = tf.name
119105

120106
async with tempfile.NamedTemporaryFile(dir=".", prefix="signature") as tf:
121107
sig_path = tf.name

pulp_container/app/tasks/sync_stages.py

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
determine_media_type,
3535
validate_manifest,
3636
calculate_digest,
37-
get_content_data,
3837
)
3938

4039
log = logging.getLogger(__name__)
@@ -77,25 +76,9 @@ async def _check_for_existing_manifest(self, download_tag):
7776

7877
digest = response.headers.get("docker-content-digest")
7978

80-
if (
81-
manifest := await Manifest.objects.prefetch_related("contentartifact_set")
82-
.filter(digest=digest)
83-
.afirst()
84-
):
85-
if raw_text_data := manifest.data:
86-
content_data = json.loads(raw_text_data)
87-
88-
# TODO: BACKWARD COMPATIBILITY - remove after fully migrating to artifactless manifest
89-
elif saved_artifact := await manifest._artifacts.afirst():
90-
content_data, raw_bytes_data = await sync_to_async(get_content_data)(saved_artifact)
91-
raw_text_data = raw_bytes_data.decode("utf-8")
92-
# if artifact is not available (due to reclaim space) we will download it again
93-
else:
94-
content_data, raw_text_data, response = await self._download_manifest_data(
95-
response.url
96-
)
97-
# END OF BACKWARD COMPATIBILITY
98-
79+
if manifest := await Manifest.objects.filter(digest=digest).afirst():
80+
raw_text_data = manifest.data
81+
content_data = json.loads(raw_text_data)
9982
else:
10083
content_data, raw_text_data, response = await self._download_manifest_data(response.url)
10184

@@ -470,22 +453,8 @@ async def create_listed_manifest(self, manifest_data):
470453
)
471454
manifest_url = urljoin(self.remote.url, relative_url)
472455

473-
if (
474-
manifest := await Manifest.objects.prefetch_related("contentartifact_set")
475-
.filter(digest=digest)
476-
.afirst()
477-
):
478-
if manifest.data:
479-
content_data = json.loads(manifest.data)
480-
# TODO: BACKWARD COMPATIBILITY - remove after fully migrating to artifactless manifest
481-
elif saved_artifact := await manifest._artifacts.afirst():
482-
content_data, _ = await sync_to_async(get_content_data)(saved_artifact)
483-
# if artifact is not available (due to reclaim space) we will download it again
484-
else:
485-
content_data, manifest = await self._download_and_instantiate_manifest(
486-
manifest_url, digest
487-
)
488-
# END OF BACKWARD COMPATIBILITY
456+
if manifest := await Manifest.objects.filter(digest=digest).afirst():
457+
content_data = json.loads(manifest.data)
489458
else:
490459
content_data, manifest = await self._download_and_instantiate_manifest(
491460
manifest_url, digest

0 commit comments

Comments
 (0)