Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3d4fa16d04 | |||
| 62fc6c1a49 | |||
| 4b968099ad | |||
| 4ab4c615e9 | |||
| 90d04d7a42 | |||
| 2d603e4fc6 | |||
| ec62f5a566 | |||
| a23953fe11 | |||
| 2533b5298f | |||
| 6ac6b1e08e | |||
| 4ebd93d39b | |||
| b4a9d797dd | |||
| eba39f8c5a | |||
| 3a217bc28e | |||
| 0df3605c40 |
@@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPublishable>false</IsPublishable>
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace PortBlog.API.Controllers
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogCritical(ex, "Exception while sending OTP for {ToEmail}.", messageSendDto.ToEmail);
|
||||
return StatusCode(500, "A problem happened while handling your request.");
|
||||
return StatusCode(500, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -262,8 +262,8 @@ namespace PortBlog.API.Controllers
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogCritical($"Exception while sending message from {message.Name}.", ex);
|
||||
return StatusCode(500, "A problem happened while handling your request.");
|
||||
_logger.LogCritical(ex, "Exception while sending message from {Name}.", message.Name);
|
||||
return StatusCode(500, ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||
@@ -10,10 +10,10 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Asp.Versioning.Mvc" Version="8.1.1" />
|
||||
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="8.1.0" />
|
||||
<PackageReference Include="AutoMapper" Version="15.0.1" />
|
||||
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="8.1.1" />
|
||||
<PackageReference Include="AutoMapper" Version="16.0.0" />
|
||||
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.10" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.3" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="9.0.9" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.9" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.9">
|
||||
|
||||
@@ -696,5 +696,10 @@
|
||||
<param name="model">The model to use when rendering the view.</param>
|
||||
<returns>A task that represents the asynchronous operation. The task result contains the rendered view as a string.</returns>
|
||||
</member>
|
||||
<member name="T:Program">
|
||||
<summary>
|
||||
Auto-generated public partial Program class for top-level statement apps.
|
||||
</summary>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
|
||||
+19
-8
@@ -12,7 +12,7 @@ using PortBlog.API.Middleware;
|
||||
using Serilog;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
using KBR.Shared.Extensions;
|
||||
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
@@ -33,13 +33,25 @@ Log.Logger = loggerConfiguration
|
||||
.WriteTo.File("logs/portblog.txt", rollingInterval: RollingInterval.Day)
|
||||
.CreateLogger();
|
||||
|
||||
var urls = builder.Configuration.GetSection("Urls");
|
||||
var urlsSection = builder.Configuration.GetSection("Urls");
|
||||
var urlsValue = urlsSection.Value;
|
||||
|
||||
if (!string.IsNullOrEmpty(urls.Value))
|
||||
if (!string.IsNullOrWhiteSpace(urlsValue))
|
||||
{
|
||||
var allowedUrlsToUse = urls.Value.Split(',');
|
||||
var allowedUrlsToUse = urlsValue
|
||||
.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
|
||||
.Where(u => Uri.IsWellFormedUriString(u, UriKind.Absolute))
|
||||
.ToArray();
|
||||
|
||||
builder.WebHost.UseUrls(allowedUrlsToUse);
|
||||
if (allowedUrlsToUse.Length > 0)
|
||||
{
|
||||
builder.WebHost.UseUrls(allowedUrlsToUse);
|
||||
}
|
||||
else
|
||||
{
|
||||
// optionally log or throw depending on desired behavior
|
||||
Log.Warning("Configured 'Urls' section was present but no valid URLs were found.");
|
||||
}
|
||||
}
|
||||
|
||||
var allowedCorsOrigins = builder.Configuration.GetSection("AllowedCorsOrigins");
|
||||
@@ -131,14 +143,13 @@ builder.Services.AddSwaggerGen(c =>
|
||||
Scheme = "ApiKeyScheme"
|
||||
});
|
||||
|
||||
var key = new OpenApiSecurityScheme()
|
||||
var key = new OpenApiSecurityScheme
|
||||
{
|
||||
Reference = new OpenApiReference
|
||||
{
|
||||
Type = ReferenceType.SecurityScheme,
|
||||
Id = "ApiKey"
|
||||
},
|
||||
In = ParameterLocation.Header
|
||||
}
|
||||
};
|
||||
|
||||
// JWT Bearer Security Definition
|
||||
|
||||
@@ -67,16 +67,14 @@ namespace PortBlog.API.Services
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogCritical(
|
||||
"Exception while sending mail from {FromEmail} ({Name}): {Exception}",
|
||||
messageSendDto.FromEmail,
|
||||
messageSendDto.Name,
|
||||
ex.Message
|
||||
);
|
||||
// Log full exception and persist failed message.
|
||||
logger.LogCritical(ex, "Exception while sending mail from {FromEmail} ({Name}).", messageSendDto.FromEmail, messageSendDto.Name);
|
||||
messageSendDto.SentStatus = (int)MailConstants.MailStatus.Failed;
|
||||
mailRepository.AddMessage(messageEntity);
|
||||
await mailRepository.SaveChangesAsync();
|
||||
throw new Exception();
|
||||
|
||||
// Throw a descriptive exception so callers can return an error message to the client.
|
||||
throw new InvalidOperationException($"Failed to send email to '{messageSendDto.ToEmail}'. See inner exception for details.", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
},
|
||||
"Cache": {
|
||||
"ConnectionString": "SERVER=192.168.0.197; DATABASE=cv_blog; UID=PortBlogDevUser; PWD=p@$$w0rd1234;Allow User Variables=true;",
|
||||
"Encryption": "false",
|
||||
"Provider": "SqlServer"
|
||||
},
|
||||
"Jwt": {
|
||||
|
||||
@@ -8,10 +8,16 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.4" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||
<PackageReference Include="coverlet.collector" Version="8.0.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using KBR.Cache.Constants;
|
||||
using KBR.Cache.Options;
|
||||
using KBR.Shared.Extensions;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
@@ -20,9 +21,14 @@ namespace KBR.Cache.Extensions
|
||||
}
|
||||
else if (cacheOptions.Provider == CacheProviders.SqlServer)
|
||||
{
|
||||
var connectionString = cacheOptions.ConnectionString;
|
||||
if ((bool)cacheOptions.Encryption)
|
||||
{
|
||||
connectionString = configuration.DecryptConnectionString(connectionString);
|
||||
}
|
||||
services.AddDistributedMySqlCache(options =>
|
||||
{
|
||||
options.ConnectionString = cacheOptions.ConnectionString;
|
||||
options.ConnectionString = connectionString;
|
||||
options.TableName = "Cache";
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="9.0.9" />
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.SqlServer" Version="9.0.9" />
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="9.0.9" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.9" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.9" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.9" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="9.0.9" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.9" />
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="10.0.3" />
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.SqlServer" Version="10.0.3" />
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="10.0.3" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="10.0.3" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="10.0.3" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.3" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="10.0.3" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options" Version="10.0.3" />
|
||||
<PackageReference Include="Pomelo.Extensions.Caching.MySql" Version="2.2.1" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
{
|
||||
public string Provider { get; set; } = null!;
|
||||
|
||||
public bool? Encryption { get; set; } = false;
|
||||
|
||||
public string? ConnectionString { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
+5
-3
@@ -1,12 +1,14 @@
|
||||
using System.Security.Cryptography;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace PortBlog.API.Extensions
|
||||
namespace KBR.Shared.Extensions
|
||||
{
|
||||
public static class ConfigurationExtensions
|
||||
{
|
||||
public static string DecryptConnectionString(this IConfiguration configuration, string encryptedConnectionString)
|
||||
{
|
||||
string keyBase64 = configuration.GetValue<string>("ConnectionStrings:Key").ToString();
|
||||
// Fix: Use GetSection and Value instead of GetValue (since GetValue is not available on IConfiguration)
|
||||
string keyBase64 = configuration.GetSection("ConnectionStrings:Key").Value;
|
||||
|
||||
string vectorBase64 = encryptedConnectionString.Split(":")[1];
|
||||
string cipherText = encryptedConnectionString.Split(":")[0];
|
||||
@@ -1,13 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="9.0.9" />
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="10.0.3" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="10.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user