-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
76 additions
and
66 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<GlobalPackageReference Include="Microsoft.SourceLink.GitHub" /> | ||
<GlobalPackageReference Include="MinVer" /> | ||
<PackageReference Include="JetBrains.Annotations" PrivateAssets="All" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageVersion Include="JetBrains.Annotations" Version="2023.3.0" /> | ||
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" /> | ||
<PackageVersion Include="MinVer" Version="4.3.0" /> | ||
<PackageVersion Include="FastEndpoints" Version="5.22.0" /> | ||
<PackageVersion Include="FastEndpoints.Security" Version="5.22.0" /> | ||
<PackageVersion Include="OpenTelemetry" Version="1.7.0" /> | ||
<PackageVersion Include="OpenTelemetry.Instrumentation.Http" Version="1.7.0" /> | ||
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.7.0" /> | ||
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="1.7.0" /> | ||
<PackageVersion Include="OpenTelemetry.Exporter.Console" Version="1.7.0" /> | ||
<PackageVersion Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.5.0" /> | ||
<PackageVersion Include="FluentValidation" Version="11.9.0" /> | ||
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.1" /> | ||
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.5.0" /> | ||
</ItemGroup> | ||
</Project> |
10 changes: 4 additions & 6 deletions
10
sample/Web/PipelineBehaviors/PostProcessors/MyResponseLogger.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
8 changes: 3 additions & 5 deletions
8
sample/Web/PipelineBehaviors/PreProcessors/AdminHeaderChecker.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,14 +1,12 @@ | ||
using FluentValidation.Results; | ||
|
||
namespace Web.PipelineBehaviors.PreProcessors; | ||
|
||
public class AdminHeaderChecker : IGlobalPreProcessor | ||
{ | ||
public async Task PreProcessAsync(object req, HttpContext ctx, List<ValidationFailure> failures, CancellationToken ct) | ||
public async Task PreProcessAsync(IPreProcessorContext context, CancellationToken ct) | ||
{ | ||
if (req is Customers.Create.Request && !ctx.Request.Headers.TryGetValue("tenant-id", out _) && !ctx.Response.HasStarted) | ||
if (context.Request is Customers.Create.Request request && !context.HttpContext.Request.Headers.TryGetValue("tenant-id", out _) && !context.HttpContext.Response.HasStarted) | ||
{ | ||
await ctx.Response.SendForbiddenAsync(ct); | ||
await context.HttpContext.Response.SendForbiddenAsync(ct); | ||
} | ||
} | ||
} |
10 changes: 4 additions & 6 deletions
10
sample/Web/PipelineBehaviors/PreProcessors/MyRequestLogger.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
14 changes: 6 additions & 8 deletions
14
sample/Web/PipelineBehaviors/PreProcessors/SecurityProcessor.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,19 +1,17 @@ | ||
using FluentValidation.Results; | ||
|
||
namespace Web.PipelineBehaviors.PreProcessors; | ||
namespace Web.PipelineBehaviors.PreProcessors; | ||
|
||
public class SecurityProcessor<TRequest> : IPreProcessor<TRequest> | ||
{ | ||
public Task PreProcessAsync(TRequest req, HttpContext ctx, List<ValidationFailure> failures, CancellationToken ct) | ||
public Task PreProcessAsync(IPreProcessorContext<TRequest> context, CancellationToken ct) | ||
{ | ||
var tenantID = ctx.Request.Headers["tenant-id"].FirstOrDefault(); | ||
var tenantID = context.HttpContext.Request.Headers["tenant-id"].FirstOrDefault(); | ||
|
||
if (tenantID == null) | ||
{ | ||
failures.Add(new("MissingHeaders", "The [tenant-id] header needs to be set!")); | ||
return ctx.Response.SendErrorsAsync(failures); | ||
context.ValidationFailures.Add(new("MissingHeaders", "The [tenant-id] header needs to be set!")); | ||
return context.HttpContext.Response.SendErrorsAsync(context.ValidationFailures); | ||
} | ||
|
||
return tenantID != "qwerty" ? ctx.Response.SendForbiddenAsync() : Task.CompletedTask; | ||
return tenantID != "qwerty" ? context.HttpContext.Response.SendForbiddenAsync() : Task.CompletedTask; | ||
} | ||
} |
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: 3 additions & 5 deletions
8
sample/Web/[Features]/TestCases/PreProcessorIsRunOnValidationFailure/MyPreProcessor.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,12 +1,10 @@ | ||
using FluentValidation.Results; | ||
|
||
namespace TestCases.PreProcessorIsRunOnValidationFailure; | ||
namespace TestCases.PreProcessorIsRunOnValidationFailure; | ||
|
||
public class MyPreProcessor : IPreProcessor<Request> | ||
{ | ||
public Task PreProcessAsync(Request req, HttpContext ctx, List<ValidationFailure> failures, CancellationToken ct) | ||
public Task PreProcessAsync(IPreProcessorContext<Request> context, CancellationToken ct) | ||
{ | ||
failures.Add(new("x", "blah")); | ||
context.ValidationFailures.Add(new("x", "blah")); | ||
return Task.CompletedTask; | ||
} | ||
} |
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
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
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