From 978629df7151183260a69dc3b9af580624258603 Mon Sep 17 00:00:00 2001 From: Fabricio Aguiar Date: Fri, 28 Oct 2022 14:42:05 +0100 Subject: [PATCH] Adding GCP support https://github.com/jschneier/django-storages/pull/1193 Required PR: https://github.com/pulp/pulpcore/pull/3367 [noissue] --- pulp_container/app/redirects.py | 18 ++++++++++++++++++ pulp_container/app/registry_api.py | 3 +++ 2 files changed, 21 insertions(+) diff --git a/pulp_container/app/redirects.py b/pulp_container/app/redirects.py index e50d6a469..ed2275c26 100644 --- a/pulp_container/app/redirects.py +++ b/pulp_container/app/redirects.py @@ -132,3 +132,21 @@ def redirect_to_object_storage(self, artifact, return_media_type): } content_url = artifact.file.storage.url(artifact.file.name, parameters=parameters) return redirect(content_url) + + +class GCloudStorageRedirects(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 = f"sha256:{artifact.sha256}" + parameters = { + "content_type": return_media_type, + "response_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 0663763a1..fce1fdfd7 100644 --- a/pulp_container/app/registry_api.py +++ b/pulp_container/app/registry_api.py @@ -65,6 +65,7 @@ FileStorageRedirects, S3StorageRedirects, AzureStorageRedirects, + GCloudStorageRedirects, ) from pulp_container.app.token_verification import ( RegistryAuthentication, @@ -794,6 +795,8 @@ def __init__(self, *args, **kwargs): self.redirects_class = S3StorageRedirects elif settings.DEFAULT_FILE_STORAGE == "storages.backends.azure_storage.AzureStorage": self.redirects_class = AzureStorageRedirects + elif settings.DEFAULT_FILE_STORAGE == "storages.backends.gcloud.GoogleCloudStorage": + self.redirects_class = GCloudStorageRedirects else: raise NotImplementedError()