Skip to content

Commit

Permalink
Merge branch 'main' into introduce-directory-build-props-file
Browse files Browse the repository at this point in the history
  • Loading branch information
tnotheis committed Oct 23, 2023
2 parents 62588f9 + 868630f commit 7e5b84d
Show file tree
Hide file tree
Showing 116 changed files with 1,967 additions and 1,178 deletions.
1 change: 0 additions & 1 deletion .ci/appsettings.override.postgres.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@
}
},
"Serilog": {
"Using": ["Serilog.Sinks.ApplicationInsights"],
"MinimumLevel": {
"Default": "Debug"
},
Expand Down
1 change: 0 additions & 1 deletion .ci/appsettings.override.sqlserver.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@
}
},
"Serilog": {
"Using": ["Serilog.Sinks.ApplicationInsights"],
"MinimumLevel": {
"Default": "Debug"
},
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/publish-artifacthub.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Artifact Repo Publish

on:
push:
branches: [main]
paths: [helm/artifacthub-repo.yml]

jobs:
upload-artifact-repo-config:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install oras
run: |
curl -L https://github.com/oras-project/oras/releases/download/v1.1.0/oras_1.1.0_linux_amd64.tar.gz -o oras.tar.gz
tar -xzf oras.tar.gz oras
sudo mv oras /usr/local/bin
rm oras.tar.gz
- name: Docker Login
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: oras push
working-directory: ./helm
run: |
oras push \
ghcr.io/nmshd/backbone-helm-chart:artifacthub.io \
--config /dev/null:application/vnd.cncf.artifacthub.config.v1+yaml \
artifacthub-repo.yml:application/vnd.cncf.artifacthub.repository-metadata.layer.v1.yaml
2 changes: 1 addition & 1 deletion AdminUi/src/AdminUi/AdminUi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
</PackageReference>
<PackageReference Include="OpenIddict.EntityFrameworkCore" Version="4.9.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.21.0" />
<PackageReference Include="FluentValidation.AspNetCore" Version="11.3.0" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.12" />
<PackageReference Include="NetEscapades.AspNetCore.SecurityHeaders" Version="0.21.0" />
Expand All @@ -34,6 +33,7 @@
<PackageReference Include="Serilog.Exceptions.EntityFrameworkCore" Version="8.4.0" />
<PackageReference Include="Serilog.Formatting.Compact" Version="1.1.0" />
<PackageReference Include="Serilog.Sinks.Http" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Seq" Version="5.2.3" />
<!-- CAUTION: Do not upgrade 'AspNetCore.HealthChecks.NpgSql' before the following issue is resolved: https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/issues/1993 -->
<PackageReference Include="AspNetCore.HealthChecks.NpgSql" Version="[6.0.2]" />
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="7.0.0" />
Expand Down
4 changes: 2 additions & 2 deletions AdminUi/src/AdminUi/Controllers/IdentitiesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
using Backbone.Modules.Devices.Application.Devices.DTOs;
using Backbone.Modules.Devices.Application.Identities.Commands.UpdateIdentity;
using Backbone.Modules.Quotas.Application.DTOs;
using Backbone.Modules.Quotas.Application.Tiers.Commands.CreateQuotaForIdentity;
using Backbone.Modules.Quotas.Application.Tiers.Commands.DeleteQuotaForIdentity;
using Backbone.Modules.Quotas.Application.Identities.Commands.CreateQuotaForIdentity;
using Backbone.Modules.Quotas.Application.Identities.Commands.DeleteQuotaForIdentity;
using Backbone.Modules.Quotas.Domain.Aggregates.Identities;
using MediatR;
using Microsoft.AspNetCore.Authorization;
Expand Down
91 changes: 63 additions & 28 deletions AdminUi/src/AdminUi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,74 @@
using Backbone.Tooling.Extensions;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.Extensions.Options;
using Microsoft.IdentityModel.Logging;
using Serilog;
using Serilog.Exceptions;
using Serilog.Exceptions.Core;
using Serilog.Exceptions.EntityFrameworkCore.Destructurers;
using Serilog.Settings.Configuration;
using LogHelper = Backbone.Infrastructure.Logging.LogHelper;

Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.CreateBootstrapLogger();

var builder = WebApplication.CreateBuilder(args);
builder.WebHost
.UseKestrel(options =>
{
options.AddServerHeader = false;
options.Limits.MaxRequestBodySize = 20.Mebibytes();
});
try
{
Log.Information("Creating app...");

var app = CreateApp(args);

Log.Information("App created.");

Log.Information("Starting app...");

app.Run();

return 0;
}
catch (Exception ex)
{
Log.Fatal(ex, "Host terminated unexpectedly");
return 1;
}
finally
{
Log.CloseAndFlush();
}

static WebApplication CreateApp(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.WebHost
.UseKestrel(options =>
{
options.AddServerHeader = false;
options.Limits.MaxRequestBodySize = 20.Mebibytes();
});

LoadConfiguration(builder, args);
LoadConfiguration(builder, args);

builder.Host
.UseSerilog((context, configuration) => configuration
.ReadFrom.Configuration(context.Configuration, new ConfigurationReaderOptions { SectionName = "Logging" })
.Enrich.WithCorrelationId("X-Correlation-Id", addValueIfHeaderAbsence: true)
.Enrich.WithDemystifiedStackTraces()
.Enrich.FromLogContext()
.Enrich.WithExceptionDetails(new DestructuringOptionsBuilder()
.WithDefaultDestructurers()
.WithDestructurers(new[] { new DbUpdateExceptionDestructurer() })))
.UseServiceProviderFactory(new AutofacServiceProviderFactory());
builder.Host
.UseSerilog((context, configuration) => configuration
.ReadFrom.Configuration(context.Configuration, new ConfigurationReaderOptions { SectionName = "Logging" })
.Enrich.WithCorrelationId("X-Correlation-Id", addValueIfHeaderAbsence: true)
.Enrich.WithDemystifiedStackTraces()
.Enrich.FromLogContext()
.Enrich.WithProperty("service", "adminui")
.Enrich.WithExceptionDetails(new DestructuringOptionsBuilder()
.WithDefaultDestructurers()
.WithDestructurers(new[] { new DbUpdateExceptionDestructurer() })))
.UseServiceProviderFactory(new AutofacServiceProviderFactory());

ConfigureServices(builder.Services, builder.Configuration, builder.Environment);
ConfigureServices(builder.Services, builder.Configuration, builder.Environment);

var app = builder.Build();
Configure(app);
var app = builder.Build();
Configure(app);

app.MigrateDbContext<AdminUiDbContext>();
app.MigrateDbContext<AdminUiDbContext>();

app.Run();
return app;
}

static void ConfigureServices(IServiceCollection services, IConfiguration configuration, IHostEnvironment environment)
{
Expand Down Expand Up @@ -89,7 +117,8 @@ static void ConfigureServices(IServiceCollection services, IConfiguration config
options
.UseEntityFrameworkCore()
.UseDbContext<DevicesDbContext>()
.ReplaceDefaultEntities<CustomOpenIddictEntityFrameworkCoreApplication, CustomOpenIddictEntityFrameworkCoreAuthorization, CustomOpenIddictEntityFrameworkCoreScope, CustomOpenIddictEntityFrameworkCoreToken, string>();
.ReplaceDefaultEntities<CustomOpenIddictEntityFrameworkCoreApplication, CustomOpenIddictEntityFrameworkCoreAuthorization, CustomOpenIddictEntityFrameworkCoreScope,
CustomOpenIddictEntityFrameworkCoreToken, string>();
options.AddApplicationStore<CustomOpenIddictEntityFrameworkCoreApplicationStore>();
});

Expand Down Expand Up @@ -124,6 +153,12 @@ static void Configure(WebApplication app)

var configuration = app.Services.GetRequiredService<IOptions<AdminConfiguration>>().Value;

app.UseSerilogRequestLogging(opts =>
{
opts.EnrichDiagnosticContext = LogHelper.EnrichFromRequest;
opts.GetLevel = LogHelper.GetLevel;
});

app.UseSecurityHeaders(policies =>
{
policies
Expand All @@ -136,10 +171,10 @@ static void Configure(WebApplication app)
});

if (configuration.SwaggerUi.Enabled)
{
app.UseSwagger().UseSwaggerUI();
IdentityModelEventSource.ShowPII = true;
}

if (app.Environment.IsDevelopment())
Microsoft.IdentityModel.Logging.IdentityModelEventSource.ShowPII = true;

app.UseCors();

Expand Down
9 changes: 8 additions & 1 deletion AdminUi/src/AdminUi/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@
},
"Logging": {
"MinimumLevel": {
"Default": "Error"
"Default": "Warning",
"Override": {
"Backbone": "Information",
"Enmeshed": "Information",
"AdminUi": "Information",

"Microsoft": "Information"
}
},
"WriteTo": {
"Console": {
Expand Down
17 changes: 16 additions & 1 deletion AdminUi/src/AdminUi/appsettings.override.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,22 @@
},
"Logging": {
"MinimumLevel": {
"Default": "Information"
"Default": "Information",
"Override": {
"Backbone": "Debug",
"Enmeshed": "Debug",
"AdminUi": "Debug",

"Microsoft.AspNetCore": "Warning"
}
},
"WriteTo": {
"Seq": {
"Name": "Seq",
"Args": {
"ServerUrl": "http://localhost:5341"
}
}
}
}
}
2 changes: 2 additions & 0 deletions Backbone.Infrastructure/Backbone.Infrastructure.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<PackageReference Include="Autofac" Version="7.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Serilog.AspNetCore" Version="7.0.0" />
<PackageReference Include="Serilog" Version="3.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
55 changes: 55 additions & 0 deletions Backbone.Infrastructure/Logging/LogHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using Microsoft.AspNetCore.Http;
using Serilog;
using Serilog.Events;

namespace Backbone.Infrastructure.Logging;

public static class LogHelper
{
public static LogEventLevel GetLevel(HttpContext ctx, double _, Exception? ex)
{
return ex != null
? LogEventLevel.Error
: ctx.Response.StatusCode > 499
? LogEventLevel.Error
: IsHealthCheckEndpoint(ctx)
? LogEventLevel.Verbose
: LogEventLevel.Information;
}

private static bool IsHealthCheckEndpoint(HttpContext ctx)
{
var endpoint = ctx.GetEndpoint();
if (endpoint != null)
{
return string.Equals(
endpoint.DisplayName,
"Health checks",
StringComparison.Ordinal);
}

return false;
}

public static void EnrichFromRequest(IDiagnosticContext diagnosticContext, HttpContext httpContext)
{
var request = httpContext.Request;

diagnosticContext.Set("Host", request.Host);
diagnosticContext.Set("Protocol", request.Protocol);
diagnosticContext.Set("Scheme", request.Scheme);

if (request.QueryString.HasValue)
{
diagnosticContext.Set("QueryString", request.QueryString.Value);
}

diagnosticContext.Set("ContentType", httpContext.Response.ContentType);

var endpoint = httpContext.GetEndpoint();
if (endpoint != null)
{
diagnosticContext.Set("EndpointName", endpoint.DisplayName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
<PackageReference Include="AspNetCore.HealthChecks.NpgSql" Version="[6.0.2]" />
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="7.0.0" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="FluentValidation" Version="11.7.1" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.21.0" />
<PackageReference Include="FluentValidation" Version="11.8.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.12" />
<PackageReference Include="Microsoft.Azure.AppConfiguration.AspNetCore" Version="6.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.12" />
<PackageReference Include="Microsoft.Extensions.Configuration.AzureAppConfiguration" Version="6.1.0" />
Expand Down
Loading

0 comments on commit 7e5b84d

Please sign in to comment.