Skip to content

Commit

Permalink
updated logging/cors
Browse files Browse the repository at this point in the history
  • Loading branch information
HaikAsatryan committed Aug 26, 2024
1 parent 9d4a1db commit 51c01f1
Show file tree
Hide file tree
Showing 18 changed files with 380 additions and 237 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
using RegexBox;
using Pandatech.VerticalSlices.SharedKernel.Helpers;

namespace Pandatech.ModularMonolith.ApiGateway.Extensions;

public static class CorsExtension
{
public static WebApplicationBuilder AddCors(this WebApplicationBuilder builder)
{
var configuration = builder.Configuration;
if (builder.Environment.IsProduction())
{
var allowedOrigins = configuration["CorsSettings:AllowedOrigins"];

ValidateCorsOrigins(allowedOrigins!);

builder.Services.AddCors(options => options.AddPolicy("AllowSpecific",
p => p
.WithOrigins(allowedOrigins!)
.WithOrigins(builder.Configuration
.GetAllowedCorsOrigins()
.SplitOrigins())
.AllowCredentials()
.AllowAnyMethod()
.AllowAnyHeader()));
Expand All @@ -39,23 +36,21 @@ public static WebApplication UseCors(this WebApplication app)
return app;
}

private static void ValidateCorsOrigins(string allowedOrigins)
private static string[] SplitOrigins(this string input)
{
var originsArray = allowedOrigins.Split(',', StringSplitOptions.RemoveEmptyEntries);

if (originsArray.Length == 0)
if (string.IsNullOrEmpty(input))
{
throw new InvalidOperationException(
"The Cors origins are empty or incorrectly formatted.");
throw new ArgumentException("Cors Origins cannot be null or empty.");
}

foreach (var origin in originsArray)
var result = input.Split([';', ','], StringSplitOptions.RemoveEmptyEntries);

for (var i = 0; i < result.Length; i++)
{
if (!PandaValidator.IsUri(origin, true, false))
{
throw new InvalidOperationException(
$"The origin {origin} is not valid URI.");
}
result[i] = result[i]
.Trim();
}

return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.7.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.7.3" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@
}
},
"ResponseCrafterVisibility": "Private",
"RepositoryName": "be-tmp-modular-monolith",
"ConnectionStrings": {
"Postgres.Scheduler": "**",
"Postgres.Localization": "**",
"Postgres.Mock1": "**",
"Postgres.Mock2": "**",
"Postgres.Bridge": "**",
"Postgres": "**",
"PersistentStorage": "/persistent",
"Redis": "**",
"RabbitMq": "**",
"ElasticSearch": "**"
"RabbitMq": "**"
},
"Security": {
"SuperUser": {
Expand All @@ -41,9 +38,29 @@
"CookieDomain": ".pandatech.it",
"AESKey": "**"
},
"ElasticIndexName": "be-ft-finhub",
"Communicator": {
"SmsFake": true,
"EmailFake": true
"SmsFake": false,
"SmsConfigurations": {
"GeneralSender": {
"Provider": "**",
"From": "**",
"Properties": {
"X-Dexatel-Key": "**"
},
"TimeoutMs": "10000"
}
},
"EmailFake": false,
"EmailConfigurations": {
"GeneralSender": {
"SmtpServer": "**",
"SmtpPort": "465",
"SmtpUsername": "**",
"SmtpPassword": "**",
"SenderEmail": "**",
"UseSsl": "true",
"TimeoutMs": "10000"
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,15 @@
}
},
"ResponseCrafterVisibility": "Private",
"Postgres": {
},
"ConnectionStrings": {
"Postgres.Scheduler": "Server=localhost;Port=5432;Database=pandatech_modular_monolith_scheduler;User Id=test;Password=test;Pooling=true;",
"Postgres.Mock1": "Server=localhost;Port=5432;Database=pandatech_modular_monolith_mock1;User Id=test;Password=test;Pooling=true;",
"Postgres.Mock2": "Server=localhost;Port=5432;Database=pandatech_modular_monolith_mock2;User Id=test;Password=test;Pooling=true;",
"Postgres": "Server=localhost;Port=5432;Database=pandatech_modular_monolith;User Id=test;Password=test;Pooling=true;",
"Redis": "localhost:6379",
"RabbitMq": "amqp://test:test@localhost:5672"
},
"Security": {
"SuperUser": {
"Username": "[email protected]",
"Password": "Qwerty123"
"Password": "Qwertyui123@"
},
"Hangfire": {
"Username": "test",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,12 @@
}
},
"ResponseCrafterVisibility": "Public",
"RepositoryName": "be-tmp-modular-monolith",
"ConnectionStrings": {
"Postgres": "**",
"ElasticSearch": "**",
"PersistentStorage": "/persistent",
"Redis": "**",
"AuditTrail": "**"
},
"RabbitMqSettings": {
"RabbitMqHost": "**",
"AuditTrail": {
"ExchangeName": "**",
"RoutingKey": "**",
"QueueName": "**",
"RoutingKeyDlx": "**",
"QueueNameDlx": "**"
}
"RabbitMq": "**"
},
"Security": {
"SuperUser": {
Expand All @@ -45,11 +36,8 @@
"RefreshTokenExpirationMinutes": "1440",
"RefreshTokenMaxExpirationMinutes": "3110400",
"CookieDomain": ".pandatech.it",
"AESKey": "**"
},
"ElasticIndexName": "be-tmp-pandatech-vertical-slices",
"CorsSettings": {
"AllowedOrigins": "*pandatech.it"
"AESKey": "**",
"AllowedCorsOrigins": "https://pandatech.it; https://www.pandatech.it"
},
"Communicator": {
"SmsFake": false,
Expand Down
16 changes: 3 additions & 13 deletions src/Pandatech.ModularMonolith.ApiGateway/appsettings.QA.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,12 @@
}
},
"ResponseCrafterVisibility": "Private",
"RepositoryName": "be-tmp-modular-monolith",
"ConnectionStrings": {
"Postgres": "**",
"ElasticSearch": "**",
"PersistentStorage": "/persistent",
"Redis": "**",
"AuditTrail": "**"
},
"RabbitMqSettings": {
"RabbitMqHost": "**",
"AuditTrail": {
"ExchangeName": "**",
"RoutingKey": "**",
"QueueName": "**",
"RoutingKeyDlx": "**",
"QueueNameDlx": "**"
}
"RabbitMq": "**"
},
"Security": {
"SuperUser": {
Expand All @@ -47,7 +38,6 @@
"CookieDomain": ".pandatech.it",
"AESKey": "**"
},
"ElasticIndexName": "be-tmp-pandatech-vertical-slices",
"Communicator": {
"SmsFake": false,
"SmsConfigurations": {
Expand Down
76 changes: 0 additions & 76 deletions src/Pandatech.ModularMonolith.ApiGateway/appsettings.Staging.json

This file was deleted.

8 changes: 2 additions & 6 deletions src/Pandatech.ModularMonolith.ApiGateway/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@
"JSONRoutePrefix": "",
"ApiBasePath": "/",
"Versions": {
"MainV1": {
"Title": "MainV1",
"Description": "Powered by PandaTech LLC: Where precision meets innovation. Let's build the future, one endpoint at a time."
},
"Fake": {
"Title": "Fake",
"Vertical": {
"Title": "Vertical",
"Description": "Powered by PandaTech LLC: Where precision meets innovation. Let's build the future, one endpoint at a time."
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using Microsoft.AspNetCore.Builder;
using Pandatech.Crypto;
using Pandatech.ModularMonolith.SharedKernel.Helpers;
using Pandatech.VerticalSlices.SharedKernel.Helpers;

namespace Pandatech.ModularMonolith.SharedKernel.Extensions;

public static class CryptoExtensions
{
public static WebApplicationBuilder AddPandaCryptoAndFilters(this WebApplicationBuilder builder)
{
builder.Services.AddPandatechCryptoAes256(o => o.Key = builder.Configuration[ConfigurationPaths.AesKey]!);
builder.Services.AddPandatechCryptoAes256(o => o.Key = builder.Configuration.GetAesKey());
builder.Services.AddPandatechCryptoArgon2Id();


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Pandatech.ModularMonolith.SharedKernel.Helpers;
using Pandatech.VerticalSlices.SharedKernel.Helpers;

namespace Pandatech.ModularMonolith.SharedKernel.Extensions;

Expand All @@ -18,7 +19,7 @@ public static WebApplicationBuilder AddMassTransit(this WebApplicationBuilder bu
x.UsingRabbitMq((context, cfg) =>
{
cfg.Host(builder.Configuration.GetConnectionString(ConfigurationPaths.RabbitMqUrl));
cfg.Host(builder.Configuration.GetConnectionString(builder.Configuration.GetRabbitMqUrl()));
cfg.ConfigureEndpoints(context);
cfg.UseMessageRetry(r =>
r.Exponential(10, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(100), TimeSpan.FromSeconds(2)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public static WebApplicationBuilder ConfigureOpenTelemetry(this WebApplicationBu
.WithTracing(tracing =>
{
tracing.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddGrpcClientInstrumentation();
.AddHttpClientInstrumentation();
});

return builder;
Expand Down
Loading

0 comments on commit 51c01f1

Please sign in to comment.