This repository has been archived by the owner on Feb 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extracted plugins #1, refactoring, cleanup
- Loading branch information
Showing
64 changed files
with
568 additions
and
326 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System.Linq; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Ntrada.Core; | ||
|
||
namespace Ntrada.Extensions.Cors | ||
{ | ||
public class CorsExtension : IExtension | ||
{ | ||
public string Name => "cors"; | ||
public string Description => "Cross-Origin Resource Sharing"; | ||
|
||
public void Add(IServiceCollection services, IOptionsProvider optionsProvider) | ||
{ | ||
var options = optionsProvider.GetForExtension<CorsOptions>(Name); | ||
services.AddCors(cors => | ||
{ | ||
var allowedHeaders = options.AllowedHeaders ?? Enumerable.Empty<string>(); | ||
var allowedMethods = options.AllowedMethods ?? Enumerable.Empty<string>(); | ||
var allowedOrigins = options.AllowedOrigins ?? Enumerable.Empty<string>(); | ||
var exposedHeaders = options.ExposedHeaders ?? Enumerable.Empty<string>(); | ||
cors.AddPolicy("CorsPolicy", builder => | ||
{ | ||
if (options.AllowCredentials) | ||
{ | ||
builder.AllowCredentials(); | ||
} | ||
else | ||
{ | ||
builder.DisallowCredentials(); | ||
} | ||
|
||
builder.WithHeaders(allowedHeaders.ToArray()) | ||
.WithMethods(allowedMethods.ToArray()) | ||
.WithOrigins(allowedOrigins.ToArray()) | ||
.WithExposedHeaders(exposedHeaders.ToArray()); | ||
}); | ||
}); | ||
} | ||
|
||
public void Use(IApplicationBuilder app, IOptionsProvider optionsProvider) | ||
{ | ||
app.UseCors("CorsPolicy"); | ||
} | ||
} | ||
} |
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,14 @@ | ||
using System.Collections.Generic; | ||
using Ntrada.Core; | ||
|
||
namespace Ntrada.Extensions.Cors | ||
{ | ||
public class CorsOptions : IOptions | ||
{ | ||
public bool AllowCredentials { get; set; } | ||
public IEnumerable<string> AllowedOrigins { get; set; } | ||
public IEnumerable<string> AllowedMethods { get; set; } | ||
public IEnumerable<string> AllowedHeaders { get; set; } | ||
public IEnumerable<string> ExposedHeaders { get; set; } | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
extensions/Ntrada.Extensions.Cors/Ntrada.Extensions.Cors.csproj
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,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Ntrada.Core\Ntrada.Core.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,14 @@ | ||
cors: | ||
allowCredentials: true | ||
allowedOrigins: | ||
- '*' | ||
allowedMethods: | ||
- post | ||
- delete | ||
allowedHeaders: | ||
- '*' | ||
exposedHeaders: | ||
- Request-ID | ||
- Resource-ID | ||
- Trace-ID | ||
- Total-Count |
24 changes: 24 additions & 0 deletions
24
extensions/Ntrada.Extensions.CustomErrors/CustomErrorsExtension.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 Microsoft.AspNetCore.Builder; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Ntrada.Core; | ||
|
||
namespace Ntrada.Extensions.CustomErrors | ||
{ | ||
public class CustomErrorsExtension : IExtension | ||
{ | ||
public string Name => "customErrors"; | ||
public string Description => "Custom errors handler"; | ||
|
||
public void Add(IServiceCollection services, IOptionsProvider optionsProvider) | ||
{ | ||
var options = optionsProvider.GetForExtension<CustomErrorsOptions>(Name); | ||
services.AddSingleton(options); | ||
services.AddScoped<ErrorHandlerMiddleware>(); | ||
} | ||
|
||
public void Use(IApplicationBuilder app, IOptionsProvider optionsProvider) | ||
{ | ||
app.UseMiddleware<ErrorHandlerMiddleware>(); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
extensions/Ntrada.Extensions.CustomErrors/CustomErrorsOptions.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,9 @@ | ||
using Ntrada.Core; | ||
|
||
namespace Ntrada.Extensions.CustomErrors | ||
{ | ||
public class CustomErrorsOptions : IOptions | ||
{ | ||
public bool IncludeExceptionMessage { get; set; } | ||
} | ||
} |
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
11 changes: 11 additions & 0 deletions
11
extensions/Ntrada.Extensions.CustomErrors/Ntrada.Extensions.CustomErrors.csproj
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,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Ntrada.Core\Ntrada.Core.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,2 @@ | ||
customErrors: | ||
includeExceptionMessage: true |
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Ntrada.Core; | ||
|
||
namespace Ntrada.Extensions.Jwt | ||
|
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
18 changes: 18 additions & 0 deletions
18
extensions/Ntrada.Extensions.Tracing/Ntrada.Extensions.Tracing.csproj
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,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.2</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Jaeger" Version="0.3.4" /> | ||
<PackageReference Include="OpenTracing" Version="0.12.0" /> | ||
<PackageReference Include="OpenTracing.Contrib.Grpc" Version="0.1.0" /> | ||
<PackageReference Include="OpenTracing.Contrib.NetCore" Version="0.6.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Ntrada.Core\Ntrada.Core.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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
src/Ntrada/Tracing/JaegerOptions.cs → ...rada.Extensions.Tracing/TracingOptions.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
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,7 @@ | ||
tracing: | ||
serviceName: ntrada | ||
udpHost: localhost | ||
udpPort: 6831 | ||
maxPacketSize: 0 | ||
sampler: const | ||
useEmptyTracer: false |
Oops, something went wrong.