Skip to content

Commit f7239e7

Browse files
committed
refactor: Update AI configuration references and improve authentication handling
- Renamed Azure OpenAI configuration to AI Endpoint in README and related files. - Updated ai-config.env.example and README for clearer AI credential setup instructions. - Enhanced load-config.sh to support optional API key for Azure AD authentication. - Modified McpServer and RunMcpServerProcess to handle API key and Azure AD credentials. - Removed outdated ai-config.local.env.template file. - Adjusted demo.sh to ensure compatibility with .NET 9 and improved navigation.
1 parent b67a3c1 commit f7239e7

File tree

11 files changed

+245
-217
lines changed

11 files changed

+245
-217
lines changed

.devcontainer/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ This checks:
8080
- ✅ Database status
8181
- ✅ Configuration files
8282

83-
### 4. Configure Azure OpenAI (Required)
83+
### 4. Configure AI Endpoint (Required)
8484

8585
```bash
8686
# Copy the template
@@ -91,9 +91,9 @@ nano Config/ai-config.local.env
9191
```
9292

9393
Required values:
94-
- `AZURE_OPENAI_ENDPOINT` - Your Azure OpenAI endpoint URL
95-
- `AZURE_OPENAI_API_KEY` - Your API key
94+
- `AZURE_OPENAI_ENDPOINT` - Your AI endpoint URL
9695
- `AZURE_OPENAI_DEPLOYMENT_NAME` - Your deployment name (e.g., "gpt-5-mini-2" or "gpt-4o")
96+
- `AZURE_OPENAI_API_KEY` - Your API key (optional if using `az login`)
9797

9898
### 5. Run Demo
9999

CobolToQuarkusMigration.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11+
<PackageReference Include="Azure.Identity" Version="1.13.2" />
1112
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
1213
<PackageReference Include="Microsoft.SemanticKernel" Version="1.22.0" />
1314
<PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.8" />

Config/ai-config.env.example

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# =============================================================================
2-
# Azure OpenAI Configuration
2+
# AI Configuration
33
# =============================================================================
44
# This file contains all AI-related configuration settings.
5-
# Add your actual Azure OpenAI credentials below.
5+
# Add your actual AI credentials below.
66
# Add this file to .gitignore if you want to keep credentials private.
77
# =============================================================================
88

9-
# Azure OpenAI Service Configuration
10-
# TODO: Replace with your actual Azure OpenAI endpoint and API key
9+
# AI Service Configuration
10+
# TODO: Replace with your actual AI endpoint and API key
1111
AZURE_OPENAI_ENDPOINT="https://your-resource-name.openai.azure.com/"
1212
AZURE_OPENAI_API_KEY="REPLACE_WITH_YOUR_API_KEY"
1313

Config/ai-config.local.env.template

Lines changed: 0 additions & 47 deletions
This file was deleted.

Config/load-config.sh

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,9 @@ validate_config() {
8787

8888
log_info "Validating configuration..."
8989

90-
# Required variables
90+
# Required variables (API key is optional - Azure AD auth is supported)
9191
local required_vars=(
9292
"AZURE_OPENAI_ENDPOINT"
93-
"AZURE_OPENAI_API_KEY"
9493
"AZURE_OPENAI_DEPLOYMENT_NAME"
9594
"AZURE_OPENAI_MODEL_ID"
9695
)
@@ -107,6 +106,19 @@ validate_config() {
107106
fi
108107
done
109108

109+
# API key is optional - check separately with warning instead of error
110+
# Empty or placeholder values mean Azure AD auth will be used
111+
if [ -z "${AZURE_OPENAI_API_KEY}" ] || [[ "${AZURE_OPENAI_API_KEY}" == *"your-"* ]] || [[ "${AZURE_OPENAI_API_KEY}" == *"placeholder"* ]]; then
112+
log_warning "⚠️ AZURE_OPENAI_API_KEY is not set or contains placeholder - will use Azure AD (DefaultAzureCredential)"
113+
log_warning " Make sure you've run 'az login' before starting the migration"
114+
# Clear placeholder to ensure Azure AD is used
115+
if [[ "${AZURE_OPENAI_API_KEY}" == *"your-"* ]] || [[ "${AZURE_OPENAI_API_KEY}" == *"placeholder"* ]]; then
116+
export AZURE_OPENAI_API_KEY=""
117+
fi
118+
else
119+
log_success "✓ AZURE_OPENAI_API_KEY is configured"
120+
fi
121+
110122
return $errors
111123
}
112124

@@ -116,7 +128,13 @@ show_config_summary() {
116128
echo " Endpoint: ${AZURE_OPENAI_ENDPOINT:-'NOT SET'}"
117129
echo " Model ID: ${AZURE_OPENAI_MODEL_ID:-'NOT SET'}"
118130
echo " Deployment: ${AZURE_OPENAI_DEPLOYMENT_NAME:-'NOT SET'}"
119-
echo " API Key: ${AZURE_OPENAI_API_KEY:0:10}... (${#AZURE_OPENAI_API_KEY} chars)"
131+
if [ -n "${AZURE_OPENAI_API_KEY}" ] && [[ "${AZURE_OPENAI_API_KEY}" != *"your-"* ]] && [[ "${AZURE_OPENAI_API_KEY}" != *"placeholder"* ]]; then
132+
echo " API Key: ${AZURE_OPENAI_API_KEY:0:10}... (${#AZURE_OPENAI_API_KEY} chars)"
133+
echo " Auth Method: API Key"
134+
else
135+
echo " API Key: (not set or placeholder)"
136+
echo " Auth Method: Azure AD (DefaultAzureCredential)"
137+
fi
120138
echo " Source Folder: ${COBOL_SOURCE_FOLDER:-'SampleCobol'}"
121139
echo " Output Folder: ${JAVA_OUTPUT_FOLDER:-'JavaOutput'}"
122140
}

Mcp/McpServer.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Text;
33
using System.Text.Json;
44
using System.Text.Json.Nodes;
5+
using Azure.Identity;
56
using Microsoft.Extensions.Logging;
67
using Microsoft.SemanticKernel;
78
using Microsoft.SemanticKernel.ChatCompletion;
@@ -40,7 +41,7 @@ public McpServer(IMigrationRepository repository, int runId, ILogger<McpServer>
4041
_logger = logger;
4142
_aiSettings = aiSettings;
4243

43-
if (_aiSettings != null && !string.IsNullOrEmpty(_aiSettings.Endpoint) && !string.IsNullOrEmpty(_aiSettings.ApiKey))
44+
if (_aiSettings != null && !string.IsNullOrEmpty(_aiSettings.Endpoint))
4445
{
4546
try
4647
{
@@ -51,10 +52,20 @@ public McpServer(IMigrationRepository repository, int runId, ILogger<McpServer>
5152
deploymentName = _aiSettings.ModelId;
5253
}
5354

54-
kernelBuilder.AddAzureOpenAIChatCompletion(
55-
deploymentName: deploymentName!,
56-
endpoint: _aiSettings.Endpoint,
57-
apiKey: _aiSettings.ApiKey);
55+
if (!string.IsNullOrEmpty(_aiSettings.ApiKey))
56+
{
57+
kernelBuilder.AddAzureOpenAIChatCompletion(
58+
deploymentName: deploymentName!,
59+
endpoint: _aiSettings.Endpoint,
60+
apiKey: _aiSettings.ApiKey);
61+
}
62+
else
63+
{
64+
kernelBuilder.AddAzureOpenAIChatCompletion(
65+
deploymentName: deploymentName!,
66+
endpoint: _aiSettings.Endpoint,
67+
credentials: new DefaultAzureCredential());
68+
}
5869

5970
_kernel = kernelBuilder.Build();
6071
_modelId = deploymentName;

Processes/RunMcpServerProcess.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Text;
33
using System.Text.Json;
44
using System.Text.Json.Nodes;
5+
using Azure.Identity;
56
using Microsoft.Extensions.Logging;
67
using Microsoft.SemanticKernel;
78
using Microsoft.SemanticKernel.ChatCompletion;
@@ -40,7 +41,7 @@ public RunMcpServerProcess(IMigrationRepository repository, int runId, ILogger<R
4041
_logger = logger;
4142
_aiSettings = aiSettings;
4243

43-
if (_aiSettings != null && !string.IsNullOrEmpty(_aiSettings.Endpoint) && !string.IsNullOrEmpty(_aiSettings.ApiKey))
44+
if (_aiSettings != null && !string.IsNullOrEmpty(_aiSettings.Endpoint))
4445
{
4546
try
4647
{
@@ -51,10 +52,20 @@ public RunMcpServerProcess(IMigrationRepository repository, int runId, ILogger<R
5152
deploymentName = _aiSettings.ModelId;
5253
}
5354

54-
kernelBuilder.AddAzureOpenAIChatCompletion(
55-
deploymentName: deploymentName!,
56-
endpoint: _aiSettings.Endpoint,
57-
apiKey: _aiSettings.ApiKey);
55+
if (!string.IsNullOrEmpty(_aiSettings.ApiKey))
56+
{
57+
kernelBuilder.AddAzureOpenAIChatCompletion(
58+
deploymentName: deploymentName!,
59+
endpoint: _aiSettings.Endpoint,
60+
apiKey: _aiSettings.ApiKey);
61+
}
62+
else
63+
{
64+
kernelBuilder.AddAzureOpenAIChatCompletion(
65+
deploymentName: deploymentName!,
66+
endpoint: _aiSettings.Endpoint,
67+
credentials: new DefaultAzureCredential());
68+
}
5869

5970
_kernel = kernelBuilder.Build();
6071
_modelId = deploymentName;

0 commit comments

Comments
 (0)