-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from SaintAngeLs/development
Development into main
- Loading branch information
Showing
720 changed files
with
35,266 additions
and
8,559 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: .NET SwiftParcel Microservice CI/CD | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
build-and-test: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 30 | ||
strategy: | ||
matrix: | ||
project: [ | ||
'SwiftParcel.Services.Availability/src/SwiftParcel.Services.Availability.Api/SwiftParcel.Services.Availability.Api/', | ||
'SwiftParcel.Services.Couriers/src/SwiftParcel.Services.Couriers.Api/SwiftParcel.Services.Couriers.Api', | ||
'SwiftParcel.Services.Customers/src/SwiftParcel.Services.Customers.Api/SwiftParcel.Services.Customers.Api', | ||
'SwiftParcel.Services.Orders/src/SwiftParcel.Services.Orders.Api/SwiftParcel.Services.Orders.Api', | ||
'SwiftParcel.Services.OrdersCreator/src/SwiftParcel.Services.OrdersCreator', | ||
'SwiftParcel.Services.Parcels/src/SwiftParcel.Services.Parcels.Api/SwiftParcel.Services.Parcels.Api', | ||
'SwifttParcel.Services.Identity/src/SwiftParcel.Services.Identity.Api/SwiftParcel.Services.Identity.Api', | ||
'SwiftParcel.Services.Deliveries/src/SwiftParcel.Services.Deliveries.Api/SwiftParcel.Services.Deliveries.Api', | ||
'SwiftParcel.API.Gateway/src/SwiftParcel.API.Gateway' | ||
] | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Setup .NET | ||
uses: actions/setup-dotnet@v1 | ||
with: | ||
dotnet-version: '6.0.x' | ||
- name: Build and Test ${{ matrix.project }} | ||
run: | | ||
cd ${{ matrix.project }} | ||
dotnet restore | ||
dotnet build --no-restore | ||
# dotnet test --no-build --if-present --verbosity normal |
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,3 @@ | ||
#!/bin/bash | ||
cd ../src/SwiftParcel.Services.Identity.Api/SwiftParcel.Services.Identity.Api | ||
dotnet build -c release |
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,4 @@ | ||
#!/bin/bash | ||
export ASPNETCORE_ENVIRONMENT=Development | ||
cd ../src/SwiftParcel.API.Gateway | ||
dotnet 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/bash | ||
dotnet test |
27 changes: 27 additions & 0 deletions
27
SwiftParcel.API.Gateway/src/SwiftParcel.API.Gateway/Infrastructure/CorrelationContext.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,27 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace SwiftParcel.API.Gateway.Infrastructure | ||
{ | ||
internal class CorrelationContext | ||
{ | ||
public string CorrelationId { get; set; } | ||
public string SpanContext { get; set; } | ||
public UserContext User { get; set; } | ||
public string ResourceId { get; set; } | ||
public string TraceId { get; set; } | ||
public string ConnectionId { get; set; } | ||
public string Name { get; set; } | ||
public DateTime CreatedAt { get; set; } | ||
|
||
public class UserContext | ||
{ | ||
public string Id { get; set; } | ||
public bool IsAuthenticated { get; set; } | ||
public string Role { get; set; } | ||
public IDictionary<string, string> Claims { get; set; } | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...arcel.API.Gateway/src/SwiftParcel.API.Gateway/Infrastructure/CorrelationContextBuilder.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,58 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Security.Claims; | ||
using System.Threading.Tasks; | ||
using Ntrada; | ||
using Ntrada.Extensions.RabbitMq; | ||
using OpenTracing; | ||
|
||
namespace SwiftParcel.API.Gateway.Infrastructure | ||
{ | ||
internal sealed class CorrelationContextBuilder : IContextBuilder | ||
{ | ||
private readonly IServiceProvider _serviceProvider; | ||
|
||
public CorrelationContextBuilder(IServiceProvider serviceProvider) | ||
{ | ||
_serviceProvider = serviceProvider; | ||
} | ||
|
||
public object Build(ExecutionData executionData) | ||
{ | ||
var tracer = _serviceProvider.GetService<ITracer>(); | ||
var spanContext = tracer is null ? string.Empty : | ||
tracer.ActiveSpan is null ? string.Empty : tracer.ActiveSpan.Context.ToString(); | ||
|
||
var name = string.Empty; | ||
if (executionData.Route.Config is {} && | ||
executionData.Route.Config.TryGetValue("routing_key", out var routingKey)) | ||
{ | ||
name = routingKey ?? string.Empty; | ||
} | ||
|
||
if (string.IsNullOrWhiteSpace(name)) | ||
{ | ||
name = $"{executionData.Context.Request.Method} {executionData.Context.Request.Path}"; | ||
} | ||
|
||
return new CorrelationContext | ||
{ | ||
CorrelationId = executionData.RequestId, | ||
User = new CorrelationContext.UserContext | ||
{ | ||
Id = executionData.UserId, | ||
Claims = executionData.Claims, | ||
Role = executionData.Claims.FirstOrDefault(c => c.Key == ClaimTypes.Role).Value, | ||
IsAuthenticated = !string.IsNullOrWhiteSpace(executionData.UserId) | ||
}, | ||
ResourceId = executionData.ResourceId, | ||
TraceId = executionData.TraceId, | ||
ConnectionId = executionData.Context.Connection.Id, | ||
Name = name, | ||
CreatedAt = DateTime.UtcNow, | ||
SpanContext = spanContext | ||
}; | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
SwiftParcel.API.Gateway/src/SwiftParcel.API.Gateway/Infrastructure/HttpRequestHook.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,30 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Newtonsoft.Json; | ||
using Ntrada; | ||
using Ntrada.Extensions.RabbitMq; | ||
using Ntrada.Hooks; | ||
|
||
namespace SwiftParcel.API.Gateway.Infrastructure | ||
{ | ||
internal sealed class HttpRequestHook : IHttpRequestHook | ||
{ | ||
private readonly IContextBuilder _contextBuilder; | ||
|
||
public HttpRequestHook(IContextBuilder contextBuilder) | ||
{ | ||
_contextBuilder = contextBuilder; | ||
} | ||
|
||
|
||
public Task InvokeAsync(HttpRequestMessage request, ExecutionData data) | ||
{ | ||
var context = JsonConvert.SerializeObject(_contextBuilder.Build(data)); | ||
request.Headers.TryAddWithoutValidation("Correlation-Context", context); | ||
|
||
return Task.CompletedTask; | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
SwiftParcel.API.Gateway/src/SwiftParcel.API.Gateway/Infrastructure/SpanContextBuilder.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,29 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Ntrada; | ||
using Ntrada.Extensions.RabbitMq; | ||
using OpenTracing; | ||
|
||
namespace SwiftParcel.API.Gateway.Infrastructure | ||
{ | ||
internal sealed class SpanContextBuilder : ISpanContextBuilder | ||
{ | ||
private readonly IServiceProvider _serviceProvider; | ||
|
||
public SpanContextBuilder(IServiceProvider serviceProvider) | ||
{ | ||
_serviceProvider = serviceProvider; | ||
} | ||
|
||
public string Build(ExecutionData executionData) | ||
{ | ||
var tracer = _serviceProvider.GetService<ITracer>(); | ||
var spanContext = tracer is null ? string.Empty : | ||
tracer.ActiveSpan is null ? string.Empty : tracer.ActiveSpan.Context.ToString(); | ||
|
||
return spanContext; | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
SwiftParcel.API.Gateway/src/SwiftParcel.API.Gateway/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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Convey; | ||
using Convey.Logging; | ||
using Convey.Metrics.AppMetrics; | ||
using Convey.Security; | ||
using Ntrada; | ||
using Ntrada.Extensions.RabbitMq; | ||
using Ntrada.Hooks; | ||
using SwiftParcel.API.Gateway.Infrastructure; | ||
|
||
namespace SwiftParcel.API.Gateway | ||
{ | ||
public static class Program | ||
{ | ||
public static Task Main(string[] args) | ||
=> CreateHostBuilder(args).Build().RunAsync(); | ||
|
||
public static IHostBuilder CreateHostBuilder(string[] args) => | ||
Host.CreateDefaultBuilder(args) | ||
.ConfigureWebHostDefaults(webBuilder => | ||
{ | ||
webBuilder.ConfigureAppConfiguration(builder => | ||
{ | ||
const string extension = "yml"; | ||
var ntradaConfig = Environment.GetEnvironmentVariable("NTRADA_CONFIG"); | ||
var configPath = args?.FirstOrDefault() ?? ntradaConfig ?? $"ntrada.{extension}"; | ||
if (!configPath.EndsWith($".{extension}")) | ||
{ | ||
configPath += $".{extension}"; | ||
} | ||
|
||
builder.AddYamlFile(configPath, false); | ||
}) | ||
.ConfigureServices(services => services.AddNtrada() | ||
.AddSingleton<IContextBuilder, CorrelationContextBuilder>() | ||
.AddSingleton<ISpanContextBuilder, SpanContextBuilder>() | ||
.AddSingleton<IHttpRequestHook, HttpRequestHook>() | ||
.AddConvey() | ||
.AddMetrics() | ||
.AddSecurity()) | ||
.Configure(app => app.UseNtrada()) | ||
.UseLogging(); | ||
}); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
SwiftParcel.API.Gateway/src/SwiftParcel.API.Gateway/Properties/launchSettings.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,28 @@ | ||
{ | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:61158", | ||
"sslPort": 44393 | ||
} | ||
}, | ||
"profiles": { | ||
"SwiftParcel.API.Gateway": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"applicationUrl": "https://localhost:7082;http://localhost:5292", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
SwiftParcel.API.Gateway/src/SwiftParcel.API.Gateway/SwiftParcel.API.Gateway.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,31 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>disable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Convey.Logging" Version="1.1.448" /> | ||
<PackageReference Include="Convey.Metrics.AppMetrics" Version="1.1.448" /> | ||
<PackageReference Include="Convey.Security" Version="1.1.448" /> | ||
<PackageReference Include="NetEscapades.Configuration.Yaml" Version="3.1.0" /> | ||
<PackageReference Include="Ntrada" Version="0.4.4" /> | ||
<PackageReference Include="Ntrada.Extensions.Cors" Version="0.4.0" /> | ||
<PackageReference Include="Ntrada.Extensions.CustomErrors" Version="0.4.0" /> | ||
<PackageReference Include="Ntrada.Extensions.Jwt" Version="0.4.0" /> | ||
<PackageReference Include="Ntrada.Extensions.RabbitMq" Version="0.4.1" /> | ||
<PackageReference Include="Ntrada.Extensions.Swagger" Version="0.4.0" /> | ||
<PackageReference Include="Ntrada.Extensions.Tracing" Version="0.4.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Remove="ntrada.yml" /> | ||
<Content Include="ntrada.yml"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</Content> | ||
</ItemGroup> | ||
|
||
|
||
</Project> |
8 changes: 8 additions & 0 deletions
8
SwiftParcel.API.Gateway/src/SwiftParcel.API.Gateway/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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
SwiftParcel.API.Gateway/src/SwiftParcel.API.Gateway/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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"logger": { | ||
"excludePaths": ["/", "/ping", "/metrics"], | ||
"console": { | ||
"enabled": true | ||
}, | ||
"file": { | ||
"enabled": true, | ||
"path": "logs/logs.txt", | ||
"interval": "day" | ||
}, | ||
"seq": { | ||
"enabled": true, | ||
"url": "http://localhost:5341", | ||
"apiKey": "secret" | ||
} | ||
}, | ||
"metrics": { | ||
"enabled": true, | ||
"influxEnabled": false, | ||
"prometheusEnabled": true, | ||
"influxUrl": "http://localhost:8086", | ||
"database": "swiftparcel", | ||
"env": "local", | ||
"interval": 5 | ||
} | ||
} |
Oops, something went wrong.