Skip to content

Commit

Permalink
fix: remote-azblob-sasToken-Authorization (#1800)
Browse files Browse the repository at this point in the history
### Description

<!--Add a description of your PR here-->
In case SAS tokens are generated in the level of a container, uploading
the outputs to Azure blob is going to fail on the creation of container.
This fix will pass the authorization exception for such cases. This
fixes #1794

### QC
<!-- Make sure that you can tick the boxes below. -->

- [x] The PR contains a test case for the changes or the changes are
already covered by an existing test case.

* [x] The documentation (`docs/`) is updated to reflect the changes or
this is not necessary (e.g. if the change does neither modify the
language nor the behavior or functionalities of Snakemake).

---------

Co-authored-by: Johannes Köster <johannes.koester@tu-dortmund.de>
Co-authored-by: Johannes Köster <johannes.koester@uni-due.de>
  • Loading branch information
3 people committed Aug 3, 2023
1 parent 9261f7e commit bc854a7
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions snakemake/remote/AzBlob.py
Expand Up @@ -244,10 +244,17 @@ def upload_to_azure_storage(
)

container_client = self.blob_service_client.get_container_client(container_name)

# create container if it doesn't exist.
# for sas token created in the level of container, the exists method will fail with error code 403.
# therefore the exception is passed to cover this type of sas tokens.

try:
container_client.create_container()
except azure.core.exceptions.ResourceExistsError:
pass
if not container_client.exists():
container_client.create_container()
except Exception as e:
if e.status_code == 403:
pass

if not blob_name:
if use_relative_path_for_blob_name:
Expand Down

0 comments on commit bc854a7

Please sign in to comment.