partial checkin
This commit is contained in:
parent
cb942598c8
commit
aedd0e38e9
@ -39,8 +39,15 @@ namespace Microsoft.AspNetCore.Hosting
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
var retries = 10;
|
||||||
var retry = Policy.Handle<SqlException>()
|
var retry = Policy.Handle<SqlException>()
|
||||||
.WaitAndRetry(10, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));
|
.WaitAndRetry(
|
||||||
|
retryCount: retries,
|
||||||
|
sleepDurationProvider: retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)),
|
||||||
|
onRetry: (exception, timeSpan, retry, ctx) =>
|
||||||
|
{
|
||||||
|
logger.LogWarning(exception, "[{prefix}] Exception {ExceptionType} with message {Message} detected on attempt {retry} of {retries}", nameof(TContext), exception.GetType().Name, exception.Message, retry, retries);
|
||||||
|
});
|
||||||
|
|
||||||
//if the sql server container is not created on run docker compose this
|
//if the sql server container is not created on run docker compose this
|
||||||
//migration can't fail for network related exception. The retry options for DbContext only
|
//migration can't fail for network related exception. The retry options for DbContext only
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
namespace Microsoft.eShopOnContainers.Services.Marketing.API.Infrastructure
|
namespace Microsoft.eShopOnContainers.Services.Marketing.API.Infrastructure
|
||||||
{
|
{
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
using EntityConfigurations;
|
using EntityConfigurations;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Design;
|
using Microsoft.EntityFrameworkCore.Design;
|
||||||
using Microsoft.eShopOnContainers.Services.Marketing.API.Model;
|
using Microsoft.eShopOnContainers.Services.Marketing.API.Model;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
public class MarketingContext : DbContext
|
public class MarketingContext : DbContext
|
||||||
{
|
{
|
||||||
@ -27,9 +30,17 @@
|
|||||||
{
|
{
|
||||||
public MarketingContext CreateDbContext(string[] args)
|
public MarketingContext CreateDbContext(string[] args)
|
||||||
{
|
{
|
||||||
|
IConfigurationRoot configuration = new ConfigurationBuilder()
|
||||||
|
.SetBasePath(Directory.GetCurrentDirectory())
|
||||||
|
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
|
||||||
|
.AddEnvironmentVariables()
|
||||||
|
.Build();
|
||||||
|
var connectionString = configuration["ConnectionString"];
|
||||||
|
Console.WriteLine(" -- Connection string");
|
||||||
|
Console.WriteLine(connectionString);
|
||||||
var optionsBuilder = new DbContextOptionsBuilder<MarketingContext>()
|
var optionsBuilder = new DbContextOptionsBuilder<MarketingContext>()
|
||||||
.UseSqlServer("Server=.;Initial Catalog=Microsoft.eShopOnContainers.Services.MarketingDb;Integrated Security=true");
|
.UseSqlServer(connectionString);
|
||||||
|
// .UseSqlServer("Server=.;Initial Catalog=Microsoft.eShopOnContainers.Services.MarketingDb;Integrated Security=true");
|
||||||
return new MarketingContext(optionsBuilder.Options);
|
return new MarketingContext(optionsBuilder.Options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,9 @@
|
|||||||
using Marketing.API.IntegrationEvents.Handlers;
|
using Marketing.API.IntegrationEvents.Handlers;
|
||||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||||
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||||
|
using Microsoft.eShopOnContainers.Services.Marketing.API.Controllers;
|
||||||
using Microsoft.eShopOnContainers.Services.Marketing.API.Infrastructure.Middlewares;
|
using Microsoft.eShopOnContainers.Services.Marketing.API.Infrastructure.Middlewares;
|
||||||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||||
using Microsoft.OpenApi.Models;
|
using Microsoft.OpenApi.Models;
|
||||||
@ -44,13 +46,18 @@
|
|||||||
|
|
||||||
|
|
||||||
// This method gets called by the runtime. Use this method to add services to the container.
|
// This method gets called by the runtime. Use this method to add services to the container.
|
||||||
public IServiceProvider ConfigureServices(IServiceCollection services)
|
public virtual IServiceProvider ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
RegisterAppInsights(services);
|
RegisterAppInsights(services);
|
||||||
|
|
||||||
// Add framework services.
|
// Add framework services.
|
||||||
services.AddCustomHealthCheck(Configuration);
|
services.AddCustomHealthCheck(Configuration);
|
||||||
services.AddControllers().AddNewtonsoftJson();
|
services
|
||||||
|
.AddControllers()
|
||||||
|
// Added for functional tests
|
||||||
|
.AddApplicationPart(typeof(LocationsController).Assembly)
|
||||||
|
.AddNewtonsoftJson()
|
||||||
|
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
|
||||||
services.Configure<MarketingSettings>(Configuration);
|
services.Configure<MarketingSettings>(Configuration);
|
||||||
|
|
||||||
ConfigureAuthService(services);
|
ConfigureAuthService(services);
|
||||||
@ -117,36 +124,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add framework services.
|
// Add framework services.
|
||||||
services.AddSwaggerGen(options =>
|
|
||||||
{
|
|
||||||
options.DescribeAllEnumsAsStrings();
|
|
||||||
options.SwaggerDoc("v1", new OpenApiInfo
|
|
||||||
{
|
|
||||||
Title = "eShopOnContainers - Marketing HTTP API",
|
|
||||||
Version = "v1",
|
|
||||||
Description = "The Marketing Service HTTP API"
|
|
||||||
});
|
|
||||||
|
|
||||||
options.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme
|
|
||||||
{
|
|
||||||
Type = SecuritySchemeType.OAuth2,
|
|
||||||
Flows = new OpenApiOAuthFlows()
|
|
||||||
{
|
|
||||||
Implicit = new OpenApiOAuthFlow()
|
|
||||||
{
|
|
||||||
AuthorizationUrl = new Uri($"{Configuration.GetValue<string>("IdentityUrlExternal")}/connect/authorize"),
|
|
||||||
TokenUrl = new Uri($"{Configuration.GetValue<string>("IdentityUrlExternal")}/connect/token"),
|
|
||||||
Scopes = new Dictionary<string, string>()
|
|
||||||
{
|
|
||||||
{ "marketing", "Marketing API" }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
options.OperationFilter<AuthorizeCheckOperationFilter>();
|
|
||||||
});
|
|
||||||
|
|
||||||
|
AddCustomSwagger(services);
|
||||||
services.AddCors(options =>
|
services.AddCors(options =>
|
||||||
{
|
{
|
||||||
options.AddPolicy("CorsPolicy",
|
options.AddPolicy("CorsPolicy",
|
||||||
@ -186,10 +165,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
app.UseCors("CorsPolicy");
|
app.UseCors("CorsPolicy");
|
||||||
|
app.UseRouting();
|
||||||
|
|
||||||
ConfigureAuth(app);
|
ConfigureAuth(app);
|
||||||
|
|
||||||
app.UseRouting();
|
|
||||||
app.UseEndpoints(endpoints =>
|
app.UseEndpoints(endpoints =>
|
||||||
{
|
{
|
||||||
endpoints.MapDefaultControllerRoute();
|
endpoints.MapDefaultControllerRoute();
|
||||||
@ -216,6 +195,39 @@
|
|||||||
ConfigureEventBus(app);
|
ConfigureEventBus(app);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void AddCustomSwagger(IServiceCollection services)
|
||||||
|
{
|
||||||
|
services.AddSwaggerGen(options =>
|
||||||
|
{
|
||||||
|
options.DescribeAllEnumsAsStrings();
|
||||||
|
options.SwaggerDoc("v1", new OpenApiInfo
|
||||||
|
{
|
||||||
|
Title = "eShopOnContainers - Marketing HTTP API",
|
||||||
|
Version = "v1",
|
||||||
|
Description = "The Marketing Service HTTP API"
|
||||||
|
});
|
||||||
|
|
||||||
|
options.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme
|
||||||
|
{
|
||||||
|
Type = SecuritySchemeType.OAuth2,
|
||||||
|
Flows = new OpenApiOAuthFlows()
|
||||||
|
{
|
||||||
|
Implicit = new OpenApiOAuthFlow()
|
||||||
|
{
|
||||||
|
AuthorizationUrl = new Uri($"{Configuration.GetValue<string>("IdentityUrlExternal")}/connect/authorize"),
|
||||||
|
TokenUrl = new Uri($"{Configuration.GetValue<string>("IdentityUrlExternal")}/connect/token"),
|
||||||
|
Scopes = new Dictionary<string, string>()
|
||||||
|
{
|
||||||
|
{ "marketing", "Marketing API" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
options.OperationFilter<AuthorizeCheckOperationFilter>();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void RegisterAppInsights(IServiceCollection services)
|
private void RegisterAppInsights(IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddApplicationInsightsTelemetry(Configuration);
|
services.AddApplicationInsightsTelemetry(Configuration);
|
||||||
@ -225,7 +237,7 @@
|
|||||||
private void ConfigureAuthService(IServiceCollection services)
|
private void ConfigureAuthService(IServiceCollection services)
|
||||||
{
|
{
|
||||||
// prevent from mapping "sub" claim to nameidentifier.
|
// prevent from mapping "sub" claim to nameidentifier.
|
||||||
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
|
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Remove("sub");
|
||||||
|
|
||||||
services.AddAuthentication(options =>
|
services.AddAuthentication(options =>
|
||||||
{
|
{
|
||||||
|
@ -17,8 +17,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.App" />
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="$(Microsoft_AspNetCore_Mvc_Testing)" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="2.2.0" />
|
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(Microsoft_NET_Test_Sdk)" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(Microsoft_NET_Test_Sdk)" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="$(Microsoft_AspNetCore_TestHost)" />
|
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="$(Microsoft_AspNetCore_TestHost)" />
|
||||||
<PackageReference Include="xunit" Version="$(xunit)" />
|
<PackageReference Include="xunit" Version="$(xunit)" />
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
using Microsoft.AspNetCore.Builder;
|
using System;
|
||||||
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.AspNetCore.Routing;
|
||||||
using Microsoft.eShopOnContainers.Services.Marketing.API;
|
using Microsoft.eShopOnContainers.Services.Marketing.API;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
namespace Marketing.FunctionalTests
|
namespace Marketing.FunctionalTests
|
||||||
{
|
{
|
||||||
@ -10,6 +13,14 @@ namespace Marketing.FunctionalTests
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override IServiceProvider ConfigureServices(IServiceCollection services)
|
||||||
|
{
|
||||||
|
// Added to avoid the Authorize data annotation in test environment.
|
||||||
|
// Property "SuppressCheckForUnhandledSecurityMetadata" in appsettings.json
|
||||||
|
services.Configure<RouteOptions>(Configuration);
|
||||||
|
return base.ConfigureServices(services);
|
||||||
|
}
|
||||||
|
|
||||||
protected override void ConfigureAuth(IApplicationBuilder app)
|
protected override void ConfigureAuth(IApplicationBuilder app)
|
||||||
{
|
{
|
||||||
if (Configuration["isTest"] == bool.TrueString.ToLowerInvariant())
|
if (Configuration["isTest"] == bool.TrueString.ToLowerInvariant())
|
||||||
|
@ -6,5 +6,6 @@
|
|||||||
"isTest": "true",
|
"isTest": "true",
|
||||||
"EventBusConnection": "localhost",
|
"EventBusConnection": "localhost",
|
||||||
"PicBaseUrl": "http://localhost:5110/api/v1/campaigns/[0]/pic/",
|
"PicBaseUrl": "http://localhost:5110/api/v1/campaigns/[0]/pic/",
|
||||||
"SubscriptionClientName": "Marketing"
|
"SubscriptionClientName": "Marketing",
|
||||||
|
"SuppressCheckForUnhandledSecurityMetadata":true
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user