Skip to content

Commit d4cbe37

Browse files
added credential_utils file in script folder and changed the import paths
1 parent f924ce6 commit d4cbe37

File tree

4 files changed

+55
-7
lines changed

4 files changed

+55
-7
lines changed

infra/app/function.bicep

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ module function '../core/host/functions.bicep' = {
131131
}
132132
}
133133

134-
resource functionNameDefaultClientKey 'Microsoft.Web/sites/host/functionKeys@2024-11-01' = {
134+
resource functionNameDefaultClientKey 'Microsoft.Web/sites/host/functionKeys@2018-11-01' = {
135135
name: '${name}/default/clientKey'
136136
properties: {
137137
name: 'ClientKey'

infra/main.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"_generator": {
66
"name": "bicep",
77
"version": "0.36.177.2456",
8-
"templateHash": "10039984803618451944"
8+
"templateHash": "16352542150707902119"
99
}
1010
},
1111
"parameters": {
@@ -8490,7 +8490,7 @@
84908490
"_generator": {
84918491
"name": "bicep",
84928492
"version": "0.36.177.2456",
8493-
"templateHash": "13598371285445269439"
8493+
"templateHash": "4396932483281426377"
84948494
}
84958495
},
84968496
"parameters": {
@@ -8604,7 +8604,7 @@
86048604
"resources": [
86058605
{
86068606
"type": "Microsoft.Web/sites/host/functionKeys",
8607-
"apiVersion": "2024-11-01",
8607+
"apiVersion": "2018-11-01",
86088608
"name": "[format('{0}/default/clientKey', parameters('name'))]",
86098609
"properties": {
86108610
"name": "ClientKey",
@@ -9794,7 +9794,7 @@
97949794
"_generator": {
97959795
"name": "bicep",
97969796
"version": "0.36.177.2456",
9797-
"templateHash": "13598371285445269439"
9797+
"templateHash": "4396932483281426377"
97989798
}
97999799
},
98009800
"parameters": {
@@ -9908,7 +9908,7 @@
99089908
"resources": [
99099909
{
99109910
"type": "Microsoft.Web/sites/host/functionKeys",
9911-
"apiVersion": "2024-11-01",
9911+
"apiVersion": "2018-11-01",
99129912
"name": "[format('{0}/default/clientKey', parameters('name'))]",
99139913
"properties": {
99149914
"name": "ClientKey",
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import os
2+
from azure.identity import ManagedIdentityCredential, DefaultAzureCredential
3+
from azure.identity.aio import (
4+
ManagedIdentityCredential as AioManagedIdentityCredential,
5+
DefaultAzureCredential as AioDefaultAzureCredential,
6+
)
7+
8+
9+
async def get_azure_credential_async(client_id=None):
10+
"""
11+
Returns an Azure credential asynchronously based on the application environment.
12+
13+
If the environment is 'dev', it uses AioDefaultAzureCredential.
14+
Otherwise, it uses AioManagedIdentityCredential.
15+
16+
Args:
17+
client_id (str, optional): The client ID for the Managed Identity Credential.
18+
19+
Returns:
20+
Credential object: Either AioDefaultAzureCredential or AioManagedIdentityCredential.
21+
"""
22+
if os.getenv("APP_ENV", "prod").lower() == "dev":
23+
return (
24+
AioDefaultAzureCredential()
25+
) # CodeQL [SM05139] Okay use of DefaultAzureCredential as it is only used in development
26+
else:
27+
return AioManagedIdentityCredential(client_id=client_id)
28+
29+
30+
def get_azure_credential(client_id=None):
31+
"""
32+
Returns an Azure credential based on the application environment.
33+
34+
If the environment is 'dev', it uses DefaultAzureCredential.
35+
Otherwise, it uses ManagedIdentityCredential.
36+
37+
Args:
38+
client_id (str, optional): The client ID for the Managed Identity Credential.
39+
40+
Returns:
41+
Credential object: Either DefaultAzureCredential or ManagedIdentityCredential.
42+
"""
43+
if os.getenv("APP_ENV", "prod").lower() == "dev":
44+
return (
45+
DefaultAzureCredential()
46+
) # CodeQL [SM05139] Okay use of DefaultAzureCredential as it is only used in development
47+
else:
48+
return ManagedIdentityCredential(client_id=client_id)

scripts/data_scripts/create_postgres_tables.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from ..helpers.azure_credential_utils import get_azure_credential
1+
from azure_credential_utils import get_azure_credential
22
import psycopg2
33
from psycopg2 import sql
44

0 commit comments

Comments
 (0)