Skip to content

Commit

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

Required PR: pulp/pulpcore#1691
  • Loading branch information
ipanova committed Oct 19, 2021
1 parent ead74c4 commit fa6a339
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES/9488.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Enabled Azure storage backend support.
26 changes: 22 additions & 4 deletions pulp_container/app/redirects.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 @@ -738,6 +742,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 fa6a339

Please sign in to comment.