Skip to content

Commit

Permalink
Added Azure storage backend support.
Browse files Browse the repository at this point in the history
backports #9488
closes #9523

(cherry picked from commit fa6a339)
  • Loading branch information
ipanova committed Nov 23, 2021
1 parent b660bfc commit 40734fd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES/9523.bugfix
@@ -0,0 +1 @@
Fixed Azure storage backend support (Backported from https://pulp.plan.io/issues/9488).
26 changes: 22 additions & 4 deletions pulp_container/app/redirects.py
Expand Up @@ -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):
"""
Expand All @@ -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)
8 changes: 7 additions & 1 deletion pulp_container/app/registry_api.py
Expand Up @@ -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,
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit 40734fd

Please sign in to comment.