-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial setup for Authorize access project (#1106)
- Loading branch information
Showing
13 changed files
with
134 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...AuthorizeAccessToATeacherRecord/Infrastructure/Logging/WebApplicationBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Serilog; | ||
using TeachingRecordSystem.Hosting; | ||
|
||
namespace TeachingRecordSystem.AuthorizeAccessToATeacherRecord.Infrastructure.Logging; | ||
|
||
public static class WebApplicationBuilderExtensions | ||
{ | ||
public static WebApplicationBuilder ConfigureLogging(this WebApplicationBuilder builder) | ||
{ | ||
if (builder.Environment.IsProduction()) | ||
{ | ||
builder.WebHost.UseSentry(dsn: builder.Configuration.GetRequiredValue("Sentry:Dsn")); | ||
} | ||
|
||
builder.Services.AddApplicationInsightsTelemetry(); | ||
|
||
// We want all logging to go through Serilog so that our filters are always applied | ||
builder.Logging.ClearProviders(); | ||
|
||
builder.Host.UseSerilog((ctx, services, config) => config.ConfigureSerilog(ctx.HostingEnvironment, ctx.Configuration, services)); | ||
|
||
return builder; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...gRecordSystem/src/TeachingRecordSystem.AuthorizeAccessToATeacherRecord/Pages/Index.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@page | ||
@model TeachingRecordSystem.AuthorizeAccessToATeacherRecord.Pages.IndexModel | ||
@{ | ||
} | ||
|
||
<h1>Hello world</h1> |
10 changes: 10 additions & 0 deletions
10
...cordSystem/src/TeachingRecordSystem.AuthorizeAccessToATeacherRecord/Pages/Index.cshtml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
|
||
namespace TeachingRecordSystem.AuthorizeAccessToATeacherRecord.Pages; | ||
|
||
public class IndexModel : PageModel | ||
{ | ||
public void OnGet() | ||
{ | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
...stem/src/TeachingRecordSystem.AuthorizeAccessToATeacherRecord/Pages/Shared/_Layout.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
@{ | ||
Layout = "_GovUkPageTemplate"; | ||
} | ||
|
||
@RenderBody() |
53 changes: 45 additions & 8 deletions
53
TeachingRecordSystem/src/TeachingRecordSystem.AuthorizeAccessToATeacherRecord/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,66 @@ | ||
using GovUk.Frontend.AspNetCore; | ||
using Joonasw.AspNetCore.SecurityHeaders; | ||
using TeachingRecordSystem.AuthorizeAccessToATeacherRecord.Infrastructure.Logging; | ||
using TeachingRecordSystem.Core; | ||
using TeachingRecordSystem.ServiceDefaults; | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
builder.WebHost.ConfigureKestrel(options => options.AddServerHeader = false); | ||
|
||
builder.AddServiceDefaults(dataProtectionBlobName: "AuthorizeAccess"); | ||
|
||
builder.ConfigureLogging(); | ||
|
||
builder.Services.AddGovUkFrontend(); | ||
builder.Services.AddCsp(nonceByteAmount: 32); | ||
|
||
// Add services to the container. | ||
builder.Services.AddRazorPages(); | ||
builder.Services | ||
.AddRazorPages(); | ||
|
||
var app = builder.Build(); | ||
|
||
// Configure the HTTP request pipeline. | ||
if (!app.Environment.IsDevelopment()) | ||
app.MapDefaultEndpoints(); | ||
|
||
if (app.Environment.IsDevelopment()) | ||
{ | ||
app.UseDeveloperExceptionPage(); | ||
app.UseMigrationsEndPoint(); | ||
} | ||
else if (!app.Environment.IsUnitTests()) | ||
{ | ||
app.UseExceptionHandler("/Error"); | ||
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. | ||
app.UseHsts(); | ||
app.UseExceptionHandler("/error"); | ||
app.UseStatusCodePagesWithReExecute("/error", "?code={0}"); | ||
} | ||
|
||
app.UseHttpsRedirection(); | ||
app.UseCsp(csp => | ||
{ | ||
var pageTemplateHelper = app.Services.GetRequiredService<PageTemplateHelper>(); | ||
|
||
csp.ByDefaultAllow | ||
.FromSelf(); | ||
|
||
csp.AllowScripts | ||
.FromSelf() | ||
.From(pageTemplateHelper.GetCspScriptHashes()) | ||
.AddNonce(); | ||
|
||
// Ensure ASP.NET Core's auto refresh works | ||
// See https://github.com/dotnet/aspnetcore/issues/33068 | ||
if (builder.Environment.IsDevelopment()) | ||
{ | ||
csp.AllowConnections | ||
.ToAnywhere(); | ||
} | ||
}); | ||
|
||
app.UseStaticFiles(); | ||
|
||
app.UseRouting(); | ||
|
||
app.UseAuthorization(); | ||
|
||
app.MapRazorPages(); | ||
app.MapControllers(); | ||
|
||
app.Run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 5 additions & 3 deletions
8
...tem/src/TeachingRecordSystem.AuthorizeAccessToATeacherRecord/appsettings.Development.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
{ | ||
"DetailedErrors": true, | ||
"Logging": { | ||
"LogLevel": { | ||
"Serilog": { | ||
"MinimumLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
"Override": { | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...stem/src/TeachingRecordSystem.AuthorizeAccessToATeacherRecord/appsettings.Production.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"Serilog": { | ||
"MinimumLevel": { | ||
"Default": "Error", | ||
"Override": { | ||
"TeachingRecordSystem.SupportUi": "Warning" | ||
} | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...dSystem/src/TeachingRecordSystem.AuthorizeAccessToATeacherRecord/appsettings.Testing.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"Serilog": { | ||
"MinimumLevel": { | ||
"Default": "Error", | ||
"Override": { | ||
"Microsoft.AspNetCore": "Fatal" | ||
} | ||
} | ||
} | ||
} |
11 changes: 7 additions & 4 deletions
11
...ingRecordSystem/src/TeachingRecordSystem.AuthorizeAccessToATeacherRecord/appsettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Serilog": { | ||
"MinimumLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
"Override": { | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
}, | ||
"Enrich": [ "FromLogContext" ] | ||
}, | ||
"AllowedHosts": "*" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters