Skip to content

Commit ec8d7a0

Browse files
Resolve CodeQL issues
1 parent fea3ac8 commit ec8d7a0

6 files changed

Lines changed: 27 additions & 7 deletions

File tree

src/ContentProcessor/src/libs/utils/azure_credential_utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,11 @@ def get_azure_credential():
130130
logging.info(
131131
"[AUTH] All CLI credentials failed - falling back to DefaultAzureCredential"
132132
)
133-
return DefaultAzureCredential()
133+
raise RuntimeError(
134+
"No Azure authentication available. "
135+
"Use Managed Identity in Azure or run "
136+
"'az login' / 'azd auth login' locally."
137+
)
134138

135139

136140
def get_async_azure_credential():

src/ContentProcessor/src/libs/utils/credential_util.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,11 @@ def get_azure_credential():
130130
logging.info(
131131
"[AUTH] All CLI credentials failed - falling back to DefaultAzureCredential"
132132
)
133-
return DefaultAzureCredential()
133+
raise RuntimeError(
134+
"No Azure authentication available. "
135+
"Use Managed Identity in Azure or run "
136+
"'az login' / 'azd auth login' locally."
137+
)
134138

135139

136140
def get_async_azure_credential():

src/ContentProcessorAPI/app/libs/base/application_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import os
1616
from abc import ABC, abstractmethod
1717

18-
from azure.identity import DefaultAzureCredential
18+
from app.utils.azure_credential_utils import get_azure_credential
1919
from dotenv import load_dotenv
2020

2121
from app.libs.application.application_configuration import (
@@ -72,7 +72,7 @@ def __init__(self, env_file_path: str | None = None, **data):
7272
self._load_env(env_file_path=env_file_path)
7373

7474
self.application_context = AppContext()
75-
self.application_context.set_credential(DefaultAzureCredential())
75+
self.application_context.set_credential(get_azure_credential())
7676

7777
app_config_endpoint: str | None = EnvConfiguration().app_config_endpoint
7878
if app_config_endpoint != "" and app_config_endpoint is not None:

src/ContentProcessorWorkflow/src/libs/azure/app_configuration.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,13 @@ def __init__(
9191
ValueError: If *app_configuration_url* is ``None`` or the
9292
credential is missing after defaulting.
9393
"""
94-
self.credential = credential or DefaultAzureCredential()
94+
if credential is None:
95+
raise ValueError(
96+
"Azure credential is required. "
97+
"Use Managed Identity, AzureCliCredential, or AzureDeveloperCliCredential."
98+
)
99+
100+
self.credential = credential
95101
self.app_config_endpoint = app_configuration_url
96102
self._initialize_client()
97103

src/ContentProcessorWorkflow/src/libs/base/application_base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def run(self):
3636
from abc import ABC, abstractmethod
3737

3838
from azure.identity import DefaultAzureCredential
39+
from src.utils.credential_util import get_azure_credential
3940
from dotenv import load_dotenv
4041

4142
from libs.agent_framework.agent_framework_settings import AgentFrameworkSettings
@@ -117,7 +118,7 @@ def __init__(self, env_file_path: str | None = None, **data):
117118
self._load_env(env_file_path=env_file_path)
118119

119120
self.application_context = AppContext()
120-
self.application_context.set_credential(DefaultAzureCredential())
121+
self.application_context.set_credential(get_azure_credential())
121122

122123
app_config_url: str | None = _envConfiguration().app_config_endpoint
123124
if app_config_url != "" and app_config_url is not None:

src/ContentProcessorWorkflow/src/utils/credential_util.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,12 @@ def get_azure_credential():
126126
logging.info(
127127
"[AUTH] All CLI credentials failed - falling back to DefaultAzureCredential"
128128
)
129-
return DefaultAzureCredential()
129+
130+
raise RuntimeError(
131+
"No Azure authentication available. "
132+
"Use Managed Identity in Azure or run "
133+
"'az login' / 'azd auth login' locally."
134+
)
130135

131136

132137
def get_async_azure_credential():

0 commit comments

Comments
 (0)