-
Notifications
You must be signed in to change notification settings - Fork 627
Expand file tree
/
Copy pathazure_credential_utils.py
More file actions
48 lines (38 loc) · 1.69 KB
/
azure_credential_utils.py
File metadata and controls
48 lines (38 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import os
from azure.identity import ManagedIdentityCredential, DefaultAzureCredential
from azure.identity.aio import (
ManagedIdentityCredential as AioManagedIdentityCredential,
DefaultAzureCredential as AioDefaultAzureCredential,
)
async def get_azure_credential_async(client_id=None):
"""
Returns an Azure credential asynchronously based on the application environment.
If the environment is 'dev', it uses AioDefaultAzureCredential.
Otherwise, it uses AioManagedIdentityCredential.
Args:
client_id (str, optional): The client ID for the Managed Identity Credential.
Returns:
Credential object: Either AioDefaultAzureCredential or AioManagedIdentityCredential.
"""
if os.getenv("APP_ENV", "prod").lower() == "dev":
return (
AioDefaultAzureCredential()
) # CodeQL [SM05139] Okay use of DefaultAzureCredential as it is only used in development
else:
return AioManagedIdentityCredential(client_id=client_id)
def get_azure_credential(client_id=None):
"""
Returns an Azure credential based on the application environment.
If the environment is 'dev', it uses DefaultAzureCredential.
Otherwise, it uses ManagedIdentityCredential.
Args:
client_id (str, optional): The client ID for the Managed Identity Credential.
Returns:
Credential object: Either DefaultAzureCredential or ManagedIdentityCredential.
"""
if os.getenv("APP_ENV", "prod").lower() == "dev":
return (
DefaultAzureCredential()
) # CodeQL [SM05139] Okay use of DefaultAzureCredential as it is only used in development
else:
return ManagedIdentityCredential(client_id=client_id)