Skip to content

Commit

Permalink
Dynamic Credential Type
Browse files Browse the repository at this point in the history
  • Loading branch information
dgaloop committed Mar 15, 2024
1 parent 7816413 commit c89fc34
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions deeplake/client/auth/azure.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
from datetime import datetime, timedelta
from azure.identity import DefaultAzureCredential
from azure.identity import DefaultAzureCredential, ManagedIdentityCredential
from azure.core.exceptions import ClientAuthenticationError

from deeplake.client.auth.auth_context import AuthContext, AuthProviderType
Expand All @@ -10,10 +11,20 @@

class AzureAuthContext(AuthContext):
def __init__(self):
self.credential = DefaultAzureCredential()
self.credential = self._get_azure_credential()
self.token = None
self._last_auth_time = None

def _get_azure_credential(self):
azure_keys = [i for i in os.environ if i.startswith("AZURE_")]
if "AZURE_CLIENT_ID" in azure_keys and len(azure_keys) == 1:
# Explicitly set client_id, to avoid any warnings coming from DefaultAzureCredential
return ManagedIdentityCredential(
client_id=os.environ.get("AZURE_CLIENT_ID")
)

return DefaultAzureCredential()

def get_token(self) -> str:
self.authenticate()

Expand Down

0 comments on commit c89fc34

Please sign in to comment.