Skip to content

Commit

Permalink
Merge pull request #21 from bnubald/20_sas_token_support
Browse files Browse the repository at this point in the history
Resolves #20: Uses SAS token if defined, and is prioritised
  • Loading branch information
bnubald authored Nov 3, 2024
2 parents 5e126c3 + f4bd88d commit 4a83154
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions EventGridProcessor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,19 @@ def main(event: func.EventGridEvent):

if event.event_type == "Microsoft.Storage.BlobCreated":
logging.info("Forecast upload event received")
sas_token = os.getenv("AZURE_STORAGE_SAS_TOKEN")

local_file_path = os.path.join(os.sep, "data", os.path.basename(event.subject))
if not os.path.exists(local_file_path):
account_url = urlparser.urlparse(event.get_json()["url"])
account_location = "{}://{}".format(account_url.scheme, account_url.netloc)
logging.debug("Received {}".format(account_url))

blob_service_client = BlobServiceClient(account_location,
credential=DefaultAzureCredential())
if sas_token:
sas_url = f"{account_url.scheme}://{account_url.netloc}?{sas_token}"
blob_service_client = BlobServiceClient(sas_url)
else:
account_location = f"{account_url.scheme}://{account_url.netloc}"
blob_service_client = BlobServiceClient(account_location,
credential=DefaultAzureCredential())
container_client = blob_service_client.get_container_client(container="data")
logging.info("Downloading blob to {}".format(local_file_path))

Expand Down

0 comments on commit 4a83154

Please sign in to comment.