diff --git a/CHANGES/9523.bugfix b/CHANGES/9523.bugfix new file mode 100644 index 000000000..ed649a500 --- /dev/null +++ b/CHANGES/9523.bugfix @@ -0,0 +1 @@ +Fixed Azure storage backend support (Backported from https://pulp.plan.io/issues/9488). diff --git a/pulp_container/app/redirects.py b/pulp_container/app/redirects.py index 80ce3e1e5..3e3c67f60 100644 --- a/pulp_container/app/redirects.py +++ b/pulp_container/app/redirects.py @@ -90,7 +90,7 @@ def redirect_to_artifact(self, content_name, manifest, manifest_media_type): except ObjectDoesNotExist: raise Http404(f"An artifact for '{content_name}' was not found") - return self.redirect_to_s3_storage(artifact, manifest_media_type) + return self.redirect_to_object_storage(artifact, manifest_media_type) def issue_blob_redirect(self, blob): """ @@ -101,16 +101,34 @@ def issue_blob_redirect(self, blob): except ObjectDoesNotExist: return self.redirect_to_content_app("blobs", blob.digest) - return self.redirect_to_s3_storage(artifact, blob.media_type) + return self.redirect_to_object_storage(artifact, blob.media_type) - def redirect_to_s3_storage(self, artifact, return_media_type): + def redirect_to_object_storage(self, artifact, return_media_type): """ Redirect to the passed artifact's file stored in the S3 storage. """ filename = os.path.basename(artifact.file.name) parameters = { "ResponseContentType": return_media_type, - "ResponseContentDisposition": f"attachment; filename={filename}", + "ResponseContentDisposition": f"attachment;filename={filename}", + } + content_url = artifact.file.storage.url(artifact.file.name, parameters=parameters) + return redirect(content_url) + + +class AzureStorageRedirects(S3StorageRedirects): + """ + A class that implements methods for the direct retrieval of manifest objects. + """ + + def redirect_to_object_storage(self, artifact, return_media_type): + """ + Redirect to the passed artifact's file stored in the Azure storage. + """ + filename = os.path.basename(artifact.file.name) + parameters = { + "content_type": return_media_type, + "content_disposition": f"attachment;filename={filename}", } content_url = artifact.file.storage.url(artifact.file.name, parameters=parameters) return redirect(content_url) diff --git a/pulp_container/app/registry_api.py b/pulp_container/app/registry_api.py index 6bde0ddbd..33cbfc049 100644 --- a/pulp_container/app/registry_api.py +++ b/pulp_container/app/registry_api.py @@ -48,7 +48,11 @@ from pulp_container.app import models, serializers from pulp_container.app.access_policy import RegistryAccessPolicy from pulp_container.app.authorization import AuthorizationService -from pulp_container.app.redirects import FileStorageRedirects, S3StorageRedirects +from pulp_container.app.redirects import ( + FileStorageRedirects, + S3StorageRedirects, + AzureStorageRedirects, +) from pulp_container.app.token_verification import ( RegistryAuthentication, TokenAuthentication, @@ -737,6 +741,8 @@ def __init__(self, *args, **kwargs): self.redirects_class = FileStorageRedirects elif settings.DEFAULT_FILE_STORAGE == "storages.backends.s3boto3.S3Boto3Storage": self.redirects_class = S3StorageRedirects + elif settings.DEFAULT_FILE_STORAGE == "storages.backends.azure_storage.AzureStorage": + self.redirects_class = AzureStorageRedirects else: raise NotImplementedError()