Configure so tests work again
This commit is contained in:
parent
0cbaec81c1
commit
512623e45d
@ -16,19 +16,30 @@
|
||||
"Protocols": "Http2"
|
||||
}
|
||||
},
|
||||
"OpenApi": {
|
||||
"Endpoint": {
|
||||
"Name": ""
|
||||
},
|
||||
"Document": {
|
||||
"Name": "Basket API",
|
||||
"Description": "Basket API",
|
||||
"Title": "Basket API",
|
||||
"Version": "v1"
|
||||
}
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"Redis": "127.0.0.1"
|
||||
},
|
||||
"Identity": {
|
||||
"Url": "",
|
||||
"Auidence": "basket",
|
||||
"Scope": "basket"
|
||||
"Audience": "basket",
|
||||
"Scope": "basket",
|
||||
"Scopes": {
|
||||
"basket": "Basket API"
|
||||
}
|
||||
},
|
||||
"EventBus": {
|
||||
"SubscriptionClientName": "Basket",
|
||||
"ConnectionString": "your-event-bus-connection-string",
|
||||
"UserName": "your-event-bus-username",
|
||||
"Password": "your-event-bus-password",
|
||||
"ConnectionString": "localhost",
|
||||
"RetryCount": 5
|
||||
},
|
||||
"ApplicationInsights": {
|
||||
|
@ -10,7 +10,6 @@ public class BasketScenarios :
|
||||
var content = new StringContent(BuildBasket(), UTF8Encoding.UTF8, "application/json");
|
||||
var uri = "/api/v1/basket/";
|
||||
var response = await server.CreateClient().PostAsync(uri, content);
|
||||
|
||||
response.EnsureSuccessStatusCode();
|
||||
}
|
||||
|
||||
|
@ -9,8 +9,10 @@
|
||||
"Microsoft": "Information"
|
||||
}
|
||||
},
|
||||
"IdentityUrl": "http://localhost:5105",
|
||||
"IdentityUrlExternal": "http://localhost:5105",
|
||||
"Identity": {
|
||||
"ExternalUrl": "http://localhost:5105",
|
||||
"Url": "http://localhost:5105"
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"Redis": "127.0.0.1"
|
||||
},
|
||||
|
@ -96,14 +96,18 @@ public static class CommonExtensions
|
||||
|
||||
var pathBase = configuration["PATH_BASE"];
|
||||
var openApiSection = configuration.GetRequiredSection("OpenApi");
|
||||
var authSection = openApiSection.GetRequiredSection("Auth");
|
||||
var authSection = openApiSection.GetSection("Auth");
|
||||
var endpointSection = openApiSection.GetRequiredSection("Endpoint");
|
||||
|
||||
var swaggerUrl = endpointSection["Url"] ?? $"{(!string.IsNullOrEmpty(pathBase) ? pathBase : string.Empty)}/swagger/v1/swagger.json";
|
||||
|
||||
setup.SwaggerEndpoint(swaggerUrl, endpointSection.GetRequiredValue("Name"));
|
||||
setup.OAuthClientId(authSection.GetRequiredValue("ClientId"));
|
||||
setup.OAuthAppName(authSection.GetRequiredValue("AppName"));
|
||||
|
||||
if (authSection.Exists())
|
||||
{
|
||||
setup.OAuthClientId(authSection.GetRequiredValue("ClientId"));
|
||||
setup.OAuthAppName(authSection.GetRequiredValue("AppName"));
|
||||
}
|
||||
});
|
||||
|
||||
return app;
|
||||
@ -136,7 +140,7 @@ public static class CommonExtensions
|
||||
|
||||
var identitySection = configuration.GetSection("Identity");
|
||||
|
||||
if (identitySection is null)
|
||||
if (!identitySection.Exists())
|
||||
{
|
||||
// No identity section, so no authentication open api definition
|
||||
return;
|
||||
@ -152,7 +156,7 @@ public static class CommonExtensions
|
||||
// }
|
||||
|
||||
var identityUrlExternal = identitySection.GetRequiredValue("ExternalUrl");
|
||||
var scopes = openApi.GetRequiredSection("Scopes").AsEnumerable().ToDictionary(p => p.Key, p => p.Value);
|
||||
var scopes = identitySection.GetRequiredSection("Scopes").AsEnumerable().ToDictionary(p => p.Key, p => p.Value);
|
||||
|
||||
options.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme
|
||||
{
|
||||
@ -183,7 +187,7 @@ public static class CommonExtensions
|
||||
|
||||
var identitySection = configuration.GetSection("Identity");
|
||||
|
||||
if (identitySection is null)
|
||||
if (!identitySection.Exists())
|
||||
{
|
||||
// No identity section, so no authentication
|
||||
return services;
|
||||
@ -266,6 +270,14 @@ public static class CommonExtensions
|
||||
|
||||
public static IServiceCollection AddApplicationInsights(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
var appInsightsSection = configuration.GetSection("ApplicationInsights");
|
||||
|
||||
// No instrumentation key, so no application insights
|
||||
if (string.IsNullOrEmpty(appInsightsSection["InstrumentationKey"]))
|
||||
{
|
||||
return services;
|
||||
}
|
||||
|
||||
services.AddApplicationInsightsTelemetry(configuration);
|
||||
services.AddApplicationInsightsKubernetesEnricher();
|
||||
return services;
|
||||
@ -288,7 +300,7 @@ public static class CommonExtensions
|
||||
var eventBusSection = configuration.GetRequiredSection("EventBus");
|
||||
var eventBusConnectionString = eventBusSection.GetRequiredValue("ConnectionString");
|
||||
|
||||
return eventBusSection.GetRequiredValue("ProviderName").ToLowerInvariant() switch
|
||||
return eventBusSection["ProviderName"]?.ToLowerInvariant() switch
|
||||
{
|
||||
"servicebus" => hcBuilder.AddAzureServiceBusTopic(
|
||||
eventBusConnectionString,
|
||||
@ -438,5 +450,5 @@ public static class CommonExtensions
|
||||
}
|
||||
|
||||
private static string GetRequiredValue(this IConfiguration configuration, string name) =>
|
||||
configuration[name] ?? throw new InvalidOperationException($"Configuration missing value for: {(configuration is IConfigurationSection s ? s.Key + ":" + name : name)}");
|
||||
configuration[name] ?? throw new InvalidOperationException($"Configuration missing value for: {(configuration is IConfigurationSection s ? s.Path + ":" + name : name)}");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user