Skip to content

Commit

Permalink
feat: update storage account creds
Browse files Browse the repository at this point in the history
  • Loading branch information
SHARANTANGEDA committed Sep 26, 2024
1 parent d93580b commit 4001763
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
long_description = readme.read()
setup(
name='vishwa-fastapi-utils',
version="0.0.4",
version="0.0.5",
author="Sai Sharan Tangeda",
author_email="saisarantangeda@gmail.com",
description="Base SDK for FastAPI Utils",
Expand Down
26 changes: 19 additions & 7 deletions vishwa_labs_fastapi_utils/cloud/az_blob.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from azure.identity import ClientSecretCredential
from azure.identity import ClientSecretCredential, DefaultAzureCredential
from azure.storage.blob import BlobServiceClient
from pathlib import Path

Expand All @@ -11,13 +11,25 @@ def __init__(self):

def get_blob_service_client(self):
"""Authenticate using Service Principal and return the BlobServiceClient."""
credential = ClientSecretCredential(
tenant_id=os.getenv("AZURE_TENANT_ID"),
client_id=os.getenv("AZURE_CLIENT_ID"),
client_secret=os.getenv("AZURE_CLIENT_SECRET"))
tenant_id = os.getenv("AZURE_TENANT_ID")
client_id = os.getenv("AZURE_CLIENT_ID")
client_secret = os.getenv("AZURE_CLIENT_SECRET")
storage_account_url = os.getenv("AZURE_STORAGE_ACCOUNT_URL")

blob_service_client = BlobServiceClient(account_url=os.getenv("AZURE_STORAGE_ACCOUNT_URL"),
credential=credential)
# Check if service principal credentials are available in the environment
if tenant_id and client_id and client_secret:
print("Using Service Principal credentials from environment variables.")
credential = ClientSecretCredential(
tenant_id=tenant_id,
client_id=client_id,
client_secret=client_secret
)
else:
print("Service Principal credentials not found. Falling back to DefaultAzureCredential.")
credential = DefaultAzureCredential()

# Create BlobServiceClient using the determined credentials
blob_service_client = BlobServiceClient(account_url=storage_account_url, credential=credential)

return blob_service_client

Expand Down

0 comments on commit 4001763

Please sign in to comment.