Skip to content

Commit

Permalink
Merge pull request #429 from solliancenet/jdh-app-config-constants
Browse files Browse the repository at this point in the history
Add App Config constants
  • Loading branch information
ciprianjichici authored Jan 10, 2024
2 parents 6aaee7f + ee584fa commit 05f6714
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 81 deletions.
42 changes: 21 additions & 21 deletions src/dotnet/AgentFactoryAPI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,21 @@ public static void Main(string[] args)
builder.Configuration.AddEnvironmentVariables();
builder.Configuration.AddAzureAppConfiguration(options =>
{
options.Connect(builder.Configuration["FoundationaLLM:AppConfig:ConnectionString"]);
options.Connect(builder.Configuration[AppConfigurationKeys.FoundationaLLM_AppConfig_ConnectionString]);
options.ConfigureKeyVault(options =>
{
options.SetCredential(new DefaultAzureCredential());
});
options.Select("FoundationaLLM:APIs:*");
options.Select("FoundationaLLM:AgentFactory:*");
options.Select(AppConfigurationKeyFilters.FoundationaLLM_APIs);
options.Select(AppConfigurationKeyFilters.FoundationaLLM_AgentFactory);
});
if (builder.Environment.IsDevelopment())
builder.Configuration.AddJsonFile("appsettings.development.json", true, true);

// Add services to the container.
builder.Services.AddApplicationInsightsTelemetry(new ApplicationInsightsServiceOptions
{
ConnectionString = builder.Configuration["FoundationaLLM:APIs:AgentFactoryAPI:AppInsightsConnectionString"],
ConnectionString = builder.Configuration[AppConfigurationKeys.FoundationaLLM_APIs_AgentFactoryAPI_AppInsightsConnectionString],
DeveloperMode = builder.Environment.IsDevelopment()
});
//builder.Services.AddServiceProfiler();
Expand All @@ -70,23 +70,23 @@ public static void Main(string[] args)
builder.Services.AddScoped<IUserClaimsProviderService, NoOpUserClaimsProviderService>();
builder.Services.AddScoped<APIKeyAuthenticationFilter>();
builder.Services.AddOptions<APIKeyValidationSettings>()
.Bind(builder.Configuration.GetSection("FoundationaLLM:APIs:AgentFactoryAPI"));
.Bind(builder.Configuration.GetSection(AppConfigurationKeySections.FoundationaLLM_APIs_AgentFactoryAPI));
builder.Services.AddTransient<IAPIKeyValidationService, APIKeyValidationService>();

builder.Services.AddOptions<SemanticKernelServiceSettings>()
.Bind(builder.Configuration.GetSection("FoundationaLLM:APIs:SemanticKernelAPI"));
.Bind(builder.Configuration.GetSection(AppConfigurationKeySections.FoundationaLLM_APIs_SemanticKernelAPI));

builder.Services.AddOptions<LangChainServiceSettings>()
.Bind(builder.Configuration.GetSection("FoundationaLLM:APIs:LangChainAPI"));
.Bind(builder.Configuration.GetSection(AppConfigurationKeySections.FoundationaLLM_APIs_LangChainAPI));

builder.Services.AddOptions<AgentHubSettings>()
.Bind(builder.Configuration.GetSection("FoundationaLLM:APIs:AgentHubAPI"));
.Bind(builder.Configuration.GetSection(AppConfigurationKeySections.FoundationaLLM_APIs_AgentHubAPI));

builder.Services.AddOptions<PromptHubSettings>()
.Bind(builder.Configuration.GetSection("FoundationaLLM:APIs:PromptHubAPI"));
.Bind(builder.Configuration.GetSection(AppConfigurationKeySections.FoundationaLLM_APIs_PromptHubAPI));

builder.Services.AddOptions<AgentFactorySettings>()
.Bind(builder.Configuration.GetSection("FoundationaLLM:AgentFactory"));
.Bind(builder.Configuration.GetSection(AppConfigurationKeySections.FoundationaLLM_AgentFactory));

builder.Services.AddScoped<ILLMOrchestrationService, SemanticKernelService>();
builder.Services.AddScoped<ILLMOrchestrationService, LangChainService>();
Expand Down Expand Up @@ -169,7 +169,7 @@ public static void Main(string[] args)
}
});

bool.TryParse(builder.Configuration[$"FoundationaLLM:APIs:{HttpClients.AgentFactoryAPI}:ForceHttpsRedirection"], out var forceHttpsRedirection);
bool.TryParse(builder.Configuration[AppConfigurationKeys.FoundationaLLM_APIs_AgentFactoryAPI_ForceHttpsRedirection], out var forceHttpsRedirection);
if (forceHttpsRedirection)
{
app.UseHttpsRedirection();
Expand All @@ -195,8 +195,8 @@ private static void RegisterDownstreamServices(WebApplicationBuilder builder)

var agentHubAPISettings = new DownstreamAPIKeySettings
{
APIUrl = builder.Configuration[$"FoundationaLLM:APIs:{HttpClients.AgentHubAPI}:APIUrl"]!,
APIKey = builder.Configuration[$"FoundationaLLM:APIs:{HttpClients.AgentHubAPI}:APIKey"]!
APIUrl = builder.Configuration[AppConfigurationKeys.FoundationaLLM_APIs_AgentHubAPI_APIUrl]!,
APIKey = builder.Configuration[AppConfigurationKeys.FoundationaLLM_APIs_AgentHubAPI_APIKey]!
};
downstreamAPISettings.DownstreamAPIs[HttpClients.AgentHubAPI] = agentHubAPISettings;

Expand All @@ -214,8 +214,8 @@ private static void RegisterDownstreamServices(WebApplicationBuilder builder)

var dataSourceHubAPISettings = new DownstreamAPIKeySettings
{
APIUrl = builder.Configuration[$"FoundationaLLM:APIs:{HttpClients.DataSourceHubAPI}:APIUrl"]!,
APIKey = builder.Configuration[$"FoundationaLLM:APIs:{HttpClients.DataSourceHubAPI}:APIKey"]!
APIUrl = builder.Configuration[AppConfigurationKeys.FoundationaLLM_APIs_DataSourceHubAPI_APIUrl]!,
APIKey = builder.Configuration[AppConfigurationKeys.FoundationaLLM_APIs_DataSourceHubAPI_APIKey]!
};
downstreamAPISettings.DownstreamAPIs[HttpClients.DataSourceHubAPI] = dataSourceHubAPISettings;

Expand All @@ -231,8 +231,8 @@ private static void RegisterDownstreamServices(WebApplicationBuilder builder)

var promptHubAPISettings = new DownstreamAPIKeySettings
{
APIUrl = builder.Configuration[$"FoundationaLLM:APIs:{HttpClients.PromptHubAPI}:APIUrl"]!,
APIKey = builder.Configuration[$"FoundationaLLM:APIs:{HttpClients.PromptHubAPI}:APIKey"]!
APIUrl = builder.Configuration[AppConfigurationKeys.FoundationaLLM_APIs_PromptHubAPI_APIUrl]!,
APIKey = builder.Configuration[AppConfigurationKeys.FoundationaLLM_APIs_PromptHubAPI_APIKey]!
};
downstreamAPISettings.DownstreamAPIs[HttpClients.PromptHubAPI] = promptHubAPISettings;

Expand All @@ -248,8 +248,8 @@ private static void RegisterDownstreamServices(WebApplicationBuilder builder)

var langChainAPISettings = new DownstreamAPIKeySettings
{
APIUrl = builder.Configuration[$"FoundationaLLM:APIs:{HttpClients.LangChainAPI}:APIUrl"]!,
APIKey = builder.Configuration[$"FoundationaLLM:APIs:{HttpClients.LangChainAPI}:APIKey"]!
APIUrl = builder.Configuration[AppConfigurationKeys.FoundationaLLM_APIs_LangChainAPI_APIUrl]!,
APIKey = builder.Configuration[AppConfigurationKeys.FoundationaLLM_APIs_LangChainAPI_APIKey]!
};
downstreamAPISettings.DownstreamAPIs[HttpClients.LangChainAPI] = langChainAPISettings;

Expand All @@ -265,8 +265,8 @@ private static void RegisterDownstreamServices(WebApplicationBuilder builder)

var semanticKernelAPISettings = new DownstreamAPIKeySettings
{
APIUrl = builder.Configuration[$"FoundationaLLM:APIs:{HttpClients.SemanticKernelAPI}:APIUrl"]!,
APIKey = builder.Configuration[$"FoundationaLLM:APIs:{HttpClients.SemanticKernelAPI}:APIKey"]!
APIUrl = builder.Configuration[AppConfigurationKeys.FoundationaLLM_APIs_SemanticKernelAPI_APIUrl]!,
APIKey = builder.Configuration[AppConfigurationKeys.FoundationaLLM_APIs_SemanticKernelAPI_APIKey]!
};
downstreamAPISettings.DownstreamAPIs[HttpClients.SemanticKernelAPI] = semanticKernelAPISettings;

Expand Down
57 changes: 56 additions & 1 deletion src/dotnet/Common/Constants/AppConfigurationKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ public static class AppConfigurationKeys
/// </summary>
public const string FoundationaLLM_APIs_LangChainAPI_AppInsightsConnectionString = "FoundationaLLM:APIs:LangChainAPI:AppInsightsConnectionString";
/// <summary>
/// The key for the FoundationaLLM:APIs:ManagementAPI:APIUrl app configuration setting.
/// </summary>
public const string FoundationaLLM_APIs_ManagementAPI_APIUrl = "FoundationaLLM:APIs:ManagementAPI:APIUrl";
/// <summary>
/// The key for the FoundationaLLM:APIs:ManagementAPI:AppInsightsConnectionString app configuration setting.
/// This is a Key Vault reference.
/// </summary>
public const string FoundationaLLM_APIs_ManagementAPI_AppInsightsConnectionString = "FoundationaLLM:APIs:ManagementAPI:AppInsightsConnectionString";
/// <summary>
/// The key for the FoundationaLLM:APIs:PromptHubAPI:APIKey app configuration setting.
/// This is a Key Vault reference.
/// </summary>
Expand Down Expand Up @@ -488,6 +497,52 @@ public static class AppConfigurationKeys
/// </summary>
public const string FoundationaLLM_LangChainAPI_Key = "FoundationaLLM:LangChainAPI:Key";
/// <summary>
/// The key for the FoundationaLLM:Management:Entra:CallbackPath app configuration setting.
/// </summary>
public const string FoundationaLLM_Management_Entra_CallbackPath = "FoundationaLLM:Management:Entra:CallbackPath";
/// <summary>
/// The key for the FoundationaLLM:Management:Entra:ClientId app configuration setting.
/// </summary>
public const string FoundationaLLM_Management_Entra_ClientId = "FoundationaLLM:Management:Entra:ClientId";
/// <summary>
/// The key for the FoundationaLLM:Management:Entra:ClientSecret app configuration setting.
/// This is a Key Vault reference.
/// </summary>
public const string FoundationaLLM_Management_Entra_ClientSecret = "FoundationaLLM:Management:Entra:ClientSecret";
/// <summary>
/// The key for the FoundationaLLM:Management:Entra:Instance app configuration setting.
/// </summary>
public const string FoundationaLLM_Management_Entra_Instance = "FoundationaLLM:Management:Entra:Instance";
/// <summary>
/// The key for the FoundationaLLM:Management:Entra:Scopes app configuration setting.
/// </summary>
public const string FoundationaLLM_Management_Entra_Scopes = "FoundationaLLM:Management:Entra:Scopes";
/// <summary>
/// The key for the FoundationaLLM:Management:Entra:TenantId app configuration setting.
/// </summary>
public const string FoundationaLLM_Management_Entra_TenantId = "FoundationaLLM:Management:Entra:TenantId";
/// <summary>
/// The key for the FoundationaLLM:ManagementAPI:Entra:ClientId app configuration setting.
/// </summary>
public const string FoundationaLLM_ManagementAPI_Entra_ClientId = "FoundationaLLM:ManagementAPI:Entra:ClientId";
/// <summary>
/// The key for the FoundationaLLM:ManagementAPI:Entra:ClientSecret app configuration setting.
/// This is a Key Vault reference.
/// </summary>
public const string FoundationaLLM_ManagementAPI_Entra_ClientSecret = "FoundationaLLM:ManagementAPI:Entra:ClientSecret";
/// <summary>
/// The key for the FoundationaLLM:ManagementAPI:Entra:Instance app configuration setting.
/// </summary>
public const string FoundationaLLM_ManagementAPI_Entra_Instance = "FoundationaLLM:ManagementAPI:Entra:Instance";
/// <summary>
/// The key for the FoundationaLLM:ManagementAPI:Entra:Scopes app configuration setting.
/// </summary>
public const string FoundationaLLM_ManagementAPI_Entra_Scopes = "FoundationaLLM:ManagementAPI:Entra:Scopes";
/// <summary>
/// The key for the FoundationaLLM:ManagementAPI:Entra:TenantId app configuration setting.
/// </summary>
public const string FoundationaLLM_ManagementAPI_Entra_TenantId = "FoundationaLLM:ManagementAPI:Entra:TenantId";
/// <summary>
/// The key for the FoundationaLLM:OpenAI:API:Endpoint app configuration setting.
/// </summary>
public const string FoundationaLLM_OpenAI_API_Endpoint = "FoundationaLLM:OpenAI:API:Endpoint";
Expand Down Expand Up @@ -723,7 +778,7 @@ public static class AppConfigurationKeySections
/// <summary>
/// The key section for the FoundationaLLM:BlobStorageMemorySource app configuration settings.
/// </summary>
public const string FoundationaLLM_BlobStorageMemorySource = "FoundationaLLM:CoreAPI:BlobStorageMemorySource";
public const string FoundationaLLM_BlobStorageMemorySource = "FoundationaLLM:BlobStorageMemorySource";
/// <summary>
/// The key section for the FoundationaLLM:Vectorization:Queues app configuration settings.
/// </summary>
Expand Down
32 changes: 16 additions & 16 deletions src/dotnet/CoreAPI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ public static void Main(string[] args)
builder.Configuration.AddEnvironmentVariables();
builder.Configuration.AddAzureAppConfiguration(options =>
{
options.Connect(builder.Configuration["FoundationaLLM:AppConfig:ConnectionString"]);
options.Connect(builder.Configuration[AppConfigurationKeys.FoundationaLLM_AppConfig_ConnectionString]);
options.ConfigureKeyVault(options =>
{
options.SetCredential(new DefaultAzureCredential());
});
options.Select("FoundationaLLM:APIs:*");
options.Select("FoundationaLLM:CosmosDB:*");
options.Select("FoundationaLLM:Branding:*");
options.Select("FoundationaLLM:CoreAPI:Entra:*");
options.Select(AppConfigurationKeyFilters.FoundationaLLM_APIs);
options.Select(AppConfigurationKeyFilters.FoundationaLLM_CosmosDB);
options.Select(AppConfigurationKeyFilters.FoundationaLLM_Branding);
options.Select(AppConfigurationKeyFilters.FoundationaLLM_CoreAPI_Entra);
});
if (builder.Environment.IsDevelopment())
builder.Configuration.AddJsonFile("appsettings.development.json", true, true);
Expand All @@ -63,9 +63,9 @@ public static void Main(string[] args)
});

builder.Services.AddOptions<CosmosDbSettings>()
.Bind(builder.Configuration.GetSection("FoundationaLLM:CosmosDB"));
.Bind(builder.Configuration.GetSection(AppConfigurationKeySections.FoundationaLLM_CosmosDB));
builder.Services.AddOptions<ClientBrandingConfiguration>()
.Bind(builder.Configuration.GetSection("FoundationaLLM:Branding"));
.Bind(builder.Configuration.GetSection(AppConfigurationKeySections.FoundationaLLM_Branding));

// Register the downstream services and HTTP clients.
RegisterDownstreamServices(builder);
Expand All @@ -84,7 +84,7 @@ public static void Main(string[] args)

builder.Services.AddApplicationInsightsTelemetry(new ApplicationInsightsServiceOptions
{
ConnectionString = builder.Configuration["FoundationaLLM:APIs:CoreAPI:AppInsightsConnectionString"],
ConnectionString = builder.Configuration[AppConfigurationKeys.FoundationaLLM_APIs_CoreAPI_AppInsightsConnectionString],
DeveloperMode = builder.Environment.IsDevelopment()
});
//builder.Services.AddServiceProfiler();
Expand Down Expand Up @@ -179,8 +179,8 @@ private static void RegisterDownstreamServices(WebApplicationBuilder builder)

var gatekeeperAPISettings = new DownstreamAPIKeySettings
{
APIUrl = builder.Configuration[$"FoundationaLLM:APIs:{HttpClients.GatekeeperAPI}:APIUrl"]!,
APIKey = builder.Configuration[$"FoundationaLLM:APIs:{HttpClients.GatekeeperAPI}:APIKey"]!
APIUrl = builder.Configuration[AppConfigurationKeys.FoundationaLLM_APIs_GatekeeperAPI_APIUrl]!,
APIKey = builder.Configuration[AppConfigurationKeys.FoundationaLLM_APIs_GatekeeperAPI_APIKey]!
};
downstreamAPISettings.DownstreamAPIs[HttpClients.GatekeeperAPI] = gatekeeperAPISettings;

Expand Down Expand Up @@ -210,11 +210,11 @@ public static void RegisterAuthConfiguration(WebApplicationBuilder builder)
},
identityOptions =>
{
identityOptions.ClientSecret = builder.Configuration["FoundationaLLM:CoreAPI:Entra:ClientSecret"];
identityOptions.Instance = builder.Configuration["FoundationaLLM:CoreAPI:Entra:Instance"] ?? "";
identityOptions.TenantId = builder.Configuration["FoundationaLLM:CoreAPI:Entra:TenantId"];
identityOptions.ClientId = builder.Configuration["FoundationaLLM:CoreAPI:Entra:ClientId"];
identityOptions.CallbackPath = builder.Configuration["FoundationaLLM:CoreAPI:Entra:CallbackPath"];
identityOptions.ClientSecret = builder.Configuration[AppConfigurationKeys.FoundationaLLM_CoreAPI_Entra_ClientSecret];
identityOptions.Instance = builder.Configuration[AppConfigurationKeys.FoundationaLLM_CoreAPI_Entra_Instance] ?? "";
identityOptions.TenantId = builder.Configuration[AppConfigurationKeys.FoundationaLLM_CoreAPI_Entra_TenantId];
identityOptions.ClientId = builder.Configuration[AppConfigurationKeys.FoundationaLLM_CoreAPI_Entra_ClientId];
identityOptions.CallbackPath = builder.Configuration[AppConfigurationKeys.FoundationaLLM_CoreAPI_Entra_CallbackPath];
});
//.EnableTokenAcquisitionToCallDownstreamApi()
//.AddInMemoryTokenCaches();
Expand All @@ -223,7 +223,7 @@ public static void RegisterAuthConfiguration(WebApplicationBuilder builder)
builder.Services.AddScoped<IUserClaimsProviderService, EntraUserClaimsProviderService>();

// Configure the scope used by the API controllers:
var requiredScope = builder.Configuration["FoundationaLLM:CoreAPI:Entra:Scopes"] ?? "";
var requiredScope = builder.Configuration[AppConfigurationKeys.FoundationaLLM_CoreAPI_Entra_Scopes] ?? "";
builder.Services.AddAuthorizationBuilder()
.AddPolicy("RequiredScope", policyBuilder =>
{
Expand Down
Loading

0 comments on commit 05f6714

Please sign in to comment.