diff --git a/PKG-INFO b/PKG-INFO index 64ed44f8f32dc0cb9953114500fccbd427a067c6..7c77283b7fbcb7c15e704088f47e15501cd9c1c6 100644 --- a/PKG-INFO +++ b/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: swh.deposit -Version: 1.4.3 +Version: 1.4.4 Summary: Software Heritage Deposit Server Home-page: https://forge.softwareheritage.org/source/swh-deposit/ Author: Software Heritage developers diff --git a/mypy.ini b/mypy.ini index cbe939b3c1e65a52795d004f6e99edbe6c9d0b68..360983431d8c48c127ac7d56efbb017a7a60fedf 100644 --- a/mypy.ini +++ b/mypy.ini @@ -44,3 +44,9 @@ ignore_missing_imports = True [mypy-swh.storage.*] ignore_missing_imports = True + +[mypy-storages.*] +ignore_missing_imports = True + +[mypy-azure.*] +ignore_missing_imports = True diff --git a/swh.deposit.egg-info/PKG-INFO b/swh.deposit.egg-info/PKG-INFO index 64ed44f8f32dc0cb9953114500fccbd427a067c6..7c77283b7fbcb7c15e704088f47e15501cd9c1c6 100644 --- a/swh.deposit.egg-info/PKG-INFO +++ b/swh.deposit.egg-info/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: swh.deposit -Version: 1.4.3 +Version: 1.4.4 Summary: Software Heritage Deposit Server Home-page: https://forge.softwareheritage.org/source/swh-deposit/ Author: Software Heritage developers diff --git a/swh/deposit/api/private/deposit_check.py b/swh/deposit/api/private/deposit_check.py index d803173e79a4838a9151fbfd72ff67b16654fc58..e24310aa070ff9bfade754dd952549aaab5dba38 100644 --- a/swh/deposit/api/private/deposit_check.py +++ b/swh/deposit/api/private/deposit_check.py @@ -125,6 +125,11 @@ class APIChecks(APIPrivateView, APIGet, DepositReadMixin): # Use python's File api which is consistent across different types of # storage backends (e.g. file, azure, ...) + # I did not find any other) workaround for azure blobstorage use, noop + # otherwise + reset_content_settings_if_needed(archive) + # FIXME: ^ Implement a better way (after digging into django-storages[azure] + with archive.open("rb") as archive_fp: try: with zipfile.ZipFile(archive_fp) as zip_fp: @@ -214,3 +219,35 @@ class APIChecks(APIPrivateView, APIGet, DepositReadMixin): deposit.save() return status.HTTP_200_OK, response, "application/json" + + +def reset_content_settings_if_needed(archive) -> None: + """This resets the content_settings on the associated blob stored in an azure + blobstorage. This prevents the correct reading of the file and failing the checks + for no good reason. + + """ + try: + from storages.backends.azure_storage import AzureStorage + except ImportError: + return None + + if not isinstance(archive.storage, AzureStorage): + return None + + from azure.storage.blob import ContentSettings + + blob_client = archive.storage.client.get_blob_client(archive.name) + + # Get the existing blob properties + properties = blob_client.get_blob_properties() + + # reset content encoding in the settings + content_settings = dict(properties.content_settings) + content_settings["content_encoding"] = "" + + # Set the content_type and content_language headers, and populate the remaining + # headers from the existing properties + blob_headers = ContentSettings(**content_settings) + + blob_client.set_http_headers(blob_headers)