Skip to content

Commit acfe52b

Browse files
Remove dead AI API-key auth residue
- Remove AIOptions.ApiKey property (was never read at runtime) - Remove [Obsolete] AddAzureOpenAIServicesWithApiKey method (zero callers) - Remove ApiKey from appsettings.json defaults - Remove ai-apikey KV secret ref and AIOptions__ApiKey env var from both staging and production deploy blocks All active paths already use DefaultAzureCredential.
1 parent 329613e commit acfe52b

4 files changed

Lines changed: 5 additions & 81 deletions

File tree

.github/workflows/Build-Test-And-Deploy.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ jobs:
152152
emailsender-email=keyvaultref:$KEYVAULTURI/secrets/authmessagesender-sendfromemail,identityref:$MANAGEDIDENTITYID connectionstring=keyvaultref:$KEYVAULTURI/secrets/connectionstrings-essentialcsharpwebcontextconnection,identityref:$MANAGEDIDENTITYID \
153153
captcha-sitekey=keyvaultref:$KEYVAULTURI/secrets/captcha-sitekey,identityref:$MANAGEDIDENTITYID captcha-secretkey=keyvaultref:$KEYVAULTURI/secrets/captcha-secretkey,identityref:$MANAGEDIDENTITYID \
154154
appinsights-connectionstring=keyvaultref:$KEYVAULTURI/secrets/applicationinsights-connectionstring,identityref:$MANAGEDIDENTITYID \
155-
ai-endpoint=keyvaultref:$KEYVAULTURI/secrets/AIOptions--Endpoint,identityref:$MANAGEDIDENTITYID ai-apikey=keyvaultref:$KEYVAULTURI/secrets/AIOptions--ApiKey,identityref:$MANAGEDIDENTITYID \
155+
ai-endpoint=keyvaultref:$KEYVAULTURI/secrets/AIOptions--Endpoint,identityref:$MANAGEDIDENTITYID \
156156
ai-vectordeployment=keyvaultref:$KEYVAULTURI/secrets/AIOptions--VectorGenerationDeploymentName,identityref:$MANAGEDIDENTITYID ai-chatdeployment=keyvaultref:$KEYVAULTURI/secrets/AIOptions--ChatDeploymentName,identityref:$MANAGEDIDENTITYID \
157157
ai-systemprompt=keyvaultref:$KEYVAULTURI/secrets/AIOptions--SystemPrompt,identityref:$MANAGEDIDENTITYID \
158158
postgres-vectorstore-connectionstring=keyvaultref:$KEYVAULTURI/secrets/ConnectionStrings--PostgresVectorStore,identityref:$MANAGEDIDENTITYID
@@ -162,10 +162,9 @@ jobs:
162162
Authentication__microsoft__clientId=secretref:msft-clientid Authentication__microsoft__clientSecret=secretref:msft-clientsecret AuthMessageSender__ApiKey=secretref:emailsender-apikey AuthMessageSender__SecretKey=secretref:emailsender-secret \
163163
AuthMessageSender__SendFromName=secretref:emailsender-name AuthMessageSender__SendFromEmail=secretref:emailsender-email ConnectionStrings__EssentialCSharpWebContextConnection=secretref:connectionstring ASPNETCORE_ENVIRONMENT=Staging \
164164
AZURE_CLIENT_ID=$AZURECLIENTID HCaptcha__SiteKey=secretref:captcha-sitekey HCaptcha__SecretKey=secretref:captcha-secretkey APPLICATIONINSIGHTS_CONNECTION_STRING=secretref:appinsights-connectionstring \
165-
AIOptions__Endpoint=secretref:ai-endpoint AIOptions__ApiKey=secretref:ai-apikey AIOptions__VectorGenerationDeploymentName=secretref:ai-vectordeployment AIOptions__ChatDeploymentName=secretref:ai-chatdeployment \
165+
AIOptions__Endpoint=secretref:ai-endpoint AIOptions__VectorGenerationDeploymentName=secretref:ai-vectordeployment AIOptions__ChatDeploymentName=secretref:ai-chatdeployment \
166166
AIOptions__SystemPrompt=secretref:ai-systemprompt ConnectionStrings__PostgresVectorStore=secretref:postgres-vectorstore-connectionstring \
167167
TryDotNet__Origin=$TRYDOTNET_ORIGIN DataProtection__AzureKeyVaultKeyUri=$KEYVAULTURI/keys/dataprotection
168-
169168
- name: Logout of Azure CLI
170169
if: always()
171170
uses: azure/CLI@v3
@@ -244,7 +243,7 @@ jobs:
244243
emailsender-email=keyvaultref:$KEYVAULTURI/secrets/authmessagesender-sendfromemail,identityref:$MANAGEDIDENTITYID connectionstring=keyvaultref:$KEYVAULTURI/secrets/connectionstrings-essentialcsharpwebcontextconnection,identityref:$MANAGEDIDENTITYID \
245244
captcha-sitekey=keyvaultref:$KEYVAULTURI/secrets/captcha-sitekey,identityref:$MANAGEDIDENTITYID captcha-secretkey=keyvaultref:$KEYVAULTURI/secrets/captcha-secretkey,identityref:$MANAGEDIDENTITYID \
246245
appinsights-connectionstring=keyvaultref:$KEYVAULTURI/secrets/applicationinsights-connectionstring,identityref:$MANAGEDIDENTITYID \
247-
ai-endpoint=keyvaultref:$KEYVAULTURI/secrets/AIOptions--Endpoint,identityref:$MANAGEDIDENTITYID ai-apikey=keyvaultref:$KEYVAULTURI/secrets/AIOptions--ApiKey,identityref:$MANAGEDIDENTITYID \
246+
ai-endpoint=keyvaultref:$KEYVAULTURI/secrets/AIOptions--Endpoint,identityref:$MANAGEDIDENTITYID \
248247
ai-vectordeployment=keyvaultref:$KEYVAULTURI/secrets/AIOptions--VectorGenerationDeploymentName,identityref:$MANAGEDIDENTITYID ai-chatdeployment=keyvaultref:$KEYVAULTURI/secrets/AIOptions--ChatDeploymentName,identityref:$MANAGEDIDENTITYID \
249248
ai-systemprompt=keyvaultref:$KEYVAULTURI/secrets/AIOptions--SystemPrompt,identityref:$MANAGEDIDENTITYID \
250249
postgres-vectorstore-connectionstring=keyvaultref:$KEYVAULTURI/secrets/ConnectionStrings--PostgresVectorStore,identityref:$MANAGEDIDENTITYID
@@ -254,7 +253,7 @@ jobs:
254253
Authentication__microsoft__clientId=secretref:msft-clientid Authentication__microsoft__clientSecret=secretref:msft-clientsecret AuthMessageSender__ApiKey=secretref:emailsender-apikey AuthMessageSender__SecretKey=secretref:emailsender-secret \
255254
AuthMessageSender__SendFromName=secretref:emailsender-name AuthMessageSender__SendFromEmail=secretref:emailsender-email ConnectionStrings__EssentialCSharpWebContextConnection=secretref:connectionstring ASPNETCORE_ENVIRONMENT=Production \
256255
AZURE_CLIENT_ID=$AZURECLIENTID HCaptcha__SiteKey=secretref:captcha-sitekey HCaptcha__SecretKey=secretref:captcha-secretkey APPLICATIONINSIGHTS_CONNECTION_STRING=secretref:appinsights-connectionstring \
257-
AIOptions__Endpoint=secretref:ai-endpoint AIOptions__ApiKey=secretref:ai-apikey AIOptions__VectorGenerationDeploymentName=secretref:ai-vectordeployment AIOptions__ChatDeploymentName=secretref:ai-chatdeployment \
256+
AIOptions__Endpoint=secretref:ai-endpoint AIOptions__VectorGenerationDeploymentName=secretref:ai-vectordeployment AIOptions__ChatDeploymentName=secretref:ai-chatdeployment \
258257
AIOptions__SystemPrompt=secretref:ai-systemprompt ConnectionStrings__PostgresVectorStore=secretref:postgres-vectorstore-connectionstring \
259258
TryDotNet__Origin=$TRYDOTNET_ORIGIN DataProtection__AzureKeyVaultKeyUri=$KEYVAULTURI/keys/dataprotection
260259

EssentialCSharp.Chat.Shared/Extensions/ServiceCollectionExtensions.cs

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -176,74 +176,4 @@ private static IServiceCollection AddPostgresVectorStoreWithManagedIdentity(
176176
return services;
177177
}
178178

179-
/// <summary>
180-
/// Adds Azure OpenAI and related AI services to the service collection using API key authentication (legacy)
181-
/// </summary>
182-
/// <param name="services">The service collection to add services to</param>
183-
/// <param name="aiOptions">The AI configuration options</param>
184-
/// <param name="postgresConnectionString">The PostgreSQL connection string for the vector store</param>
185-
/// <param name="apiKey">The API key for Azure OpenAI authentication</param>
186-
/// <returns>The service collection for chaining</returns>
187-
[Obsolete("API key authentication is not recommended for production. Use AddAzureOpenAIServices with Managed Identity instead.")]
188-
public static IServiceCollection AddAzureOpenAIServicesWithApiKey(
189-
this IServiceCollection services,
190-
AIOptions aiOptions,
191-
string postgresConnectionString,
192-
string apiKey)
193-
{
194-
if (string.IsNullOrEmpty(apiKey))
195-
{
196-
throw new ArgumentException("API key cannot be null or empty.", nameof(apiKey));
197-
}
198-
199-
if (string.IsNullOrEmpty(aiOptions.Endpoint))
200-
{
201-
throw new InvalidOperationException("AIOptions.Endpoint is required.");
202-
}
203-
204-
var endpoint = new Uri(aiOptions.Endpoint);
205-
206-
// Register Azure OpenAI services with API key authentication
207-
#pragma warning disable SKEXP0010 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
208-
services.AddAzureOpenAIChatClient(
209-
aiOptions.ChatDeploymentName,
210-
aiOptions.Endpoint,
211-
apiKey);
212-
213-
services.AddSingleton(provider =>
214-
new AzureOpenAIClient(endpoint, new Azure.AzureKeyCredential(apiKey)));
215-
216-
services.AddAzureOpenAIChatCompletion(
217-
aiOptions.ChatDeploymentName,
218-
aiOptions.Endpoint,
219-
apiKey);
220-
221-
// Register NpgsqlDataSource with UseVector() enabled for API key scenario as well
222-
services.AddSingleton<NpgsqlDataSource>(sp =>
223-
{
224-
var dataSourceBuilder = new NpgsqlDataSourceBuilder(postgresConnectionString);
225-
// IMPORTANT: UseVector() must be called to enable pgvector support
226-
dataSourceBuilder.UseVector();
227-
return dataSourceBuilder.Build();
228-
});
229-
230-
// Add PostgreSQL vector store using the NpgsqlDataSource from DI
231-
services.AddPostgresVectorStore();
232-
233-
services.AddEmbeddingGenerator(sp =>
234-
sp.GetRequiredService<AzureOpenAIClient>()
235-
.GetEmbeddingClient(aiOptions.VectorGenerationDeploymentName)
236-
.AsIEmbeddingGenerator())
237-
.UseLogging()
238-
.UseOpenTelemetry();
239-
#pragma warning restore SKEXP0010
240-
241-
// Register shared AI services
242-
services.AddSingleton<EmbeddingService>();
243-
services.AddSingleton<AISearchService>();
244-
services.AddSingleton<AIChatService>();
245-
services.AddSingleton<MarkdownChunkingService>();
246-
247-
return services;
248-
}
249179
}

EssentialCSharp.Chat.Shared/Models/AIOptions.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,4 @@ public class AIOptions
2222
/// </summary>
2323
public string Endpoint { get; set; } = string.Empty;
2424

25-
/// <summary>
26-
/// The API key for accessing Azure OpenAI services.
27-
/// </summary>
28-
public string ApiKey { get; set; } = string.Empty;
2925
}

EssentialCSharp.Web/appsettings.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
"VectorGenerationDeploymentName": "text-embedding-3-large-v1",
2323
"ChatDeploymentName": "gpt-5",
2424
"SystemPrompt": "You are a helpful AI assistant with expertise in C# programming and the Essential C# book content. You can help users understand C# concepts, answer programming questions, and provide guidance based on the Essential C# book materials. Be concise but thorough in your explanations.",
25-
"Endpoint": "",
26-
"ApiKey": ""
25+
"Endpoint": ""
2726
},
2827
"SiteSettings": {
2928
"BaseUrl": "https://essentialcsharp.com"

0 commit comments

Comments
 (0)