1
0
mirror of https://github.com/bitwarden/server synced 2026-01-06 10:34:01 +00:00

upgrade to aspnet core 3.1

This commit is contained in:
Kyle Spearrin
2020-01-10 08:33:13 -05:00
parent 8026912eeb
commit 29580684a3
60 changed files with 429 additions and 420 deletions

View File

@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
LABEL com.bitwarden.product="bitwarden"

View File

@@ -2,17 +2,12 @@
<PropertyGroup>
<Version>1.33.0</Version>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>Bit.Events</RootNamespace>
<UserSecretsId>bitwarden-Events</UserSecretsId>
<MvcRazorCompileOnPublish>false</MvcRazorCompileOnPublish>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Core\Core.csproj" />
</ItemGroup>

View File

@@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Hosting;
using Bit.Core.Utilities;
using Serilog.Events;
using Microsoft.Extensions.Hosting;
namespace Bit.Events
{
@@ -9,28 +10,31 @@ namespace Bit.Events
{
public static void Main(string[] args)
{
WebHost
Host
.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.ConfigureLogging((hostingContext, logging) =>
logging.AddSerilog(hostingContext, e =>
{
var context = e.Properties["SourceContext"].ToString();
if(context.Contains("IdentityServer4.Validation.TokenValidator") ||
context.Contains("IdentityServer4.Validation.TokenRequestValidator"))
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
webBuilder.ConfigureLogging((hostingContext, logging) =>
logging.AddSerilog(hostingContext, e =>
{
return e.Level > LogEventLevel.Error;
}
var context = e.Properties["SourceContext"].ToString();
if(context.Contains("IdentityServer4.Validation.TokenValidator") ||
context.Contains("IdentityServer4.Validation.TokenRequestValidator"))
{
return e.Level > LogEventLevel.Error;
}
if(e.Properties.ContainsKey("RequestPath") &&
!string.IsNullOrWhiteSpace(e.Properties["RequestPath"]?.ToString()) &&
(context.Contains(".Server.Kestrel") || context.Contains(".Core.IISHttpServer")))
{
return false;
}
if(e.Properties.ContainsKey("RequestPath") &&
!string.IsNullOrWhiteSpace(e.Properties["RequestPath"]?.ToString()) &&
(context.Contains(".Server.Kestrel") || context.Contains(".Core.IISHttpServer")))
{
return false;
}
return e.Level >= LogEventLevel.Error;
}))
return e.Level >= LogEventLevel.Error;
}));
})
.Build()
.Run();
}

View File

@@ -7,12 +7,13 @@ using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace Bit.Events
{
public class Startup
{
public Startup(IHostingEnvironment env, IConfiguration configuration)
public Startup(IWebHostEnvironment env, IConfiguration configuration)
{
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
Configuration = configuration;
@@ -20,7 +21,7 @@ namespace Bit.Events
}
public IConfiguration Configuration { get; }
public IHostingEnvironment Environment { get; set; }
public IWebHostEnvironment Environment { get; set; }
public void ConfigureServices(IServiceCollection services)
{
@@ -82,8 +83,8 @@ namespace Bit.Events
public void Configure(
IApplicationBuilder app,
IHostingEnvironment env,
IApplicationLifetime appLifetime,
IWebHostEnvironment env,
IHostApplicationLifetime appLifetime,
GlobalSettings globalSettings)
{
app.UseSerilog(env, appLifetime, globalSettings);
@@ -96,18 +97,22 @@ namespace Bit.Events
// Default Middleware
app.UseDefaultMiddleware(env, globalSettings);
// Add routing
app.UseRouting();
// Add Cors
app.UseCors(policy => policy.SetIsOriginAllowed(h => true)
.AllowAnyMethod().AllowAnyHeader().AllowCredentials());
// Add authentication to the request pipeline.
// Add authentication and authorization to the request pipeline.
app.UseAuthentication();
app.UseAuthorization();
// Add current context
app.UseMiddleware<CurrentContextMiddleware>();
// Add MVC to the request pipeline.
app.UseMvc();
app.UseEndpoints(endpoints => endpoints.MapDefaultControllerRoute());
}
}
}