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 18, 2021
1 parent 6e7d985 commit e63976a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 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.
24 changes: 21 additions & 3 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,9 +101,9 @@ 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.
"""
Expand All @@ -114,3 +114,21 @@ def redirect_to_s3_storage(self, artifact, return_media_type):
}
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 @@ -741,6 +745,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 e63976a

Please sign in to comment.