mirror of
https://github.com/NecroticBamboo/QRBee.git
synced 2025-12-21 04:01:53 +00:00
DEEP-27 OpenTelemetry support added. Migrated to .NET 7.
This commit is contained in:
parent
f51e0a6ab8
commit
5d7223e801
@ -7,6 +7,12 @@ namespace QRBee.Core.Security
|
||||
/// </summary>
|
||||
public interface ISecurityService
|
||||
{
|
||||
/// <summary>
|
||||
/// Private key handler
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
IPrivateKeyHandler PrivateKeyHandler { get; }
|
||||
|
||||
// -------------------------- encryption --------------------------
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -7,13 +7,15 @@ namespace QRBee.Core.Security
|
||||
|
||||
public abstract class SecurityServiceBase : ISecurityService
|
||||
{
|
||||
protected IPrivateKeyHandler PrivateKeyHandler { get; }
|
||||
private IPrivateKeyHandler _privateKeyHandler;
|
||||
|
||||
protected SecurityServiceBase(IPrivateKeyHandler privateKeyHandler)
|
||||
{
|
||||
PrivateKeyHandler = privateKeyHandler;
|
||||
_privateKeyHandler = privateKeyHandler;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IPrivateKeyHandler PrivateKeyHandler => _privateKeyHandler;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public abstract X509Certificate2 CreateCertificate(string subjectName, byte[] rsaPublicKey);
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
|
||||
@ -14,7 +14,7 @@ namespace QRBee.Droid
|
||||
{
|
||||
|
||||
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "12.1.0.11")]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "13.2.0.99")]
|
||||
public partial class Resource
|
||||
{
|
||||
|
||||
|
||||
@ -8,8 +8,10 @@ namespace QRBee.Droid.Services
|
||||
{
|
||||
internal class AndroidSecurityService : SecurityServiceBase
|
||||
{
|
||||
private X509Certificate2 _apiServerCertificate;
|
||||
private string ApiServerCertificateFileName => $"{Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData)}/ApiServerCertificate.bin";
|
||||
#pragma warning disable CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
|
||||
private X509Certificate2? _apiServerCertificate;
|
||||
#pragma warning restore CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
|
||||
public static string ApiServerCertificateFileName => $"{Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData)}/ApiServerCertificate.bin";
|
||||
|
||||
public AndroidSecurityService(IPrivateKeyHandler privateKeyHandler)
|
||||
: base(privateKeyHandler)
|
||||
|
||||
@ -4,12 +4,12 @@ namespace QRBee.Api
|
||||
{
|
||||
public class DatabaseSettings
|
||||
{
|
||||
public string? ConnectionString { get; set;}
|
||||
public string? Connection { get; set;}
|
||||
public string? DatabaseName { get; set; }
|
||||
|
||||
public MongoClientSettings ToMongoDbSettings()
|
||||
{
|
||||
var settings = MongoClientSettings.FromConnectionString(ConnectionString);
|
||||
var settings = MongoClientSettings.FromConnectionString(Connection);
|
||||
|
||||
return settings;
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
using log4net;
|
||||
using Microsoft.Extensions.Options;
|
||||
using MongoDB.Driver;
|
||||
using OpenTelemetry.Metrics;
|
||||
using QRBee.Api;
|
||||
using QRBee.Api.Services;
|
||||
using QRBee.Api.Services.Database;
|
||||
@ -8,14 +9,22 @@ using QRBee.Core.Security;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.Logging.ClearProviders();
|
||||
GlobalContext.Properties["LOGS_ROOT"] = Environment.GetEnvironmentVariable("LOGS_ROOT") ?? "";
|
||||
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
||||
builder.Logging.AddLog4Net("log4net.config");
|
||||
|
||||
builder.Host.ConfigureLogging(logging =>
|
||||
{
|
||||
logging.ClearProviders();
|
||||
GlobalContext.Properties["LOGS_ROOT"] = Environment.GetEnvironmentVariable("LOGS_ROOT") ?? "";
|
||||
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
||||
logging.AddLog4Net("log4net.config");
|
||||
});
|
||||
builder.Services.AddOpenTelemetry()
|
||||
.WithMetrics(options =>
|
||||
{
|
||||
options
|
||||
.AddAspNetCoreInstrumentation()
|
||||
.AddHttpClientInstrumentation()
|
||||
.AddRuntimeInstrumentation()
|
||||
.AddProcessInstrumentation()
|
||||
.AddPrometheusExporter()
|
||||
;
|
||||
});
|
||||
|
||||
// Add services to the container.
|
||||
|
||||
@ -24,11 +33,19 @@ builder.Services.AddControllers();
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
|
||||
builder.Services
|
||||
.Configure<DatabaseSettings>(builder.Configuration.GetSection("QRBeeDatabase"))
|
||||
;
|
||||
|
||||
builder.Services
|
||||
.AddSingleton<IQRBeeAPI,QRBeeAPIService>()
|
||||
.AddSingleton<IStorage, Storage>()
|
||||
.Configure<DatabaseSettings>(builder.Configuration.GetSection("QRBeeDatabase"))
|
||||
.AddSingleton<IMongoClient>( cfg => new MongoClient(cfg.GetRequiredService<IOptions<DatabaseSettings>>().Value.ToMongoDbSettings()))
|
||||
.AddSingleton<IMongoClient>( cfg =>
|
||||
{
|
||||
var section = cfg.GetRequiredService<IOptions<DatabaseSettings>>().Value
|
||||
?? throw new ApplicationException("Configuration for DatabaseSettings is not found");
|
||||
return new MongoClient(section.ToMongoDbSettings());
|
||||
})
|
||||
.AddSingleton<IPrivateKeyHandler, ServerPrivateKeyHandler>()
|
||||
.AddSingleton<ISecurityService, SecurityService>()
|
||||
.AddSingleton<IPaymentGateway, PaymentGateway>()
|
||||
@ -44,10 +61,9 @@ var app = builder.Build();
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
|
||||
app.UseOpenTelemetryPrometheusScrapingEndpoint();
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UserSecretsId>3b7dc7f1-0b82-4746-b99b-73c43c8826e0</UserSecretsId>
|
||||
@ -20,7 +20,14 @@
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="6.1.0" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.15.0" />
|
||||
<PackageReference Include="MongoDB.Driver" Version="2.15.0" />
|
||||
<PackageReference Include="OpenTelemetry.Exporter.Prometheus.AspNetCore" Version="1.5.0-rc.1" />
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.Process" Version="0.5.0-beta.3" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.3.0" />
|
||||
<PackageReference Include="OpenTelemetry" Version="1.5.1" />
|
||||
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.5.1" />
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.5.0-beta.1" />
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.5.0-beta.1" />
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.5.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@ -204,6 +204,7 @@ namespace QRBee.Api.Services
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e, $"Transaction failed. Merchant={value.ClientResponse.MerchantRequest.MerchantId} Client={value.ClientResponse.ClientId}");
|
||||
var response = MakePaymentResponse(value, "", "", false, e.Message);
|
||||
return response;
|
||||
}
|
||||
@ -317,10 +318,10 @@ namespace QRBee.Api.Services
|
||||
throw new ApplicationException($"The valid from date: {validFrom} is wrong");
|
||||
}
|
||||
|
||||
if (holderName.Any(char.IsDigit))
|
||||
{
|
||||
throw new ApplicationException($"The card holder name: {holderName} is wrong");
|
||||
}
|
||||
//if (holderName.Any(char.IsDigit))
|
||||
//{
|
||||
// throw new ApplicationException($"The card holder name: {holderName} is wrong");
|
||||
//}
|
||||
}
|
||||
|
||||
private static RSA LoadRsaPublicKey(StringRSAParameters stringParameters)
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace QRBee.Api.Services
|
||||
{
|
||||
@ -20,7 +22,7 @@ namespace QRBee.Api.Services
|
||||
|
||||
private const string VeryBadNeverUseCertificatePassword = "+ñèbòFëc׎ßRúß¿ãçPN";
|
||||
|
||||
private string PrivateKeyFileName { get; set; } = $"{Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData)}/{FileName}";
|
||||
protected string PrivateKeyFileName { get; set; } = $"{Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData)}/{FileName}";
|
||||
private string PrivateKeyCertificatePassword { get; set; } = VeryBadNeverUseCertificatePassword;
|
||||
|
||||
public ServerPrivateKeyHandler(ILogger<ServerPrivateKeyHandler> logger, IConfiguration config)
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
{
|
||||
|
||||
"QRBeeDatabase": {
|
||||
"ConnectionString": "mongodb://localhost:27017",
|
||||
"Connection": "mongodb://localhost:27017",
|
||||
"DatabaseName": "QRBee"
|
||||
},
|
||||
|
||||
|
||||
@ -6,26 +6,28 @@
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<!-- <appender name="Console" type="log4net.Appender.ColoredConsoleAppender">
|
||||
<mapping>
|
||||
<level value="ERROR" />
|
||||
<foreColor value="White" />
|
||||
<backColor value="Red, HighIntensity" />
|
||||
</mapping>
|
||||
<mapping>
|
||||
<level value="DEBUG" />
|
||||
<foreColor value="White" />
|
||||
</mapping>
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
|
||||
</layout>
|
||||
</appender> -->
|
||||
|
||||
<appender name="Console" type="log4net.Appender.ConsoleAppender">
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
|
||||
</layout>
|
||||
</appender>
|
||||
<!--Console appender-->
|
||||
<appender name="Console" type="log4net.Appender.ManagedColoredConsoleAppender">
|
||||
<mapping>
|
||||
<level value="INFO" />
|
||||
<forecolor value="Green" />
|
||||
</mapping>
|
||||
<mapping>
|
||||
<level value="WARN" />
|
||||
<forecolor value="Yellow" />
|
||||
</mapping>
|
||||
<mapping>
|
||||
<level value="ERROR" />
|
||||
<forecolor value="Red" />
|
||||
</mapping>
|
||||
<mapping>
|
||||
<level value="DEBUG" />
|
||||
<forecolor value="Blue" />
|
||||
</mapping>
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
<conversionPattern value="%date{HH:mm:ss,fff} [%-2thread] %-5level %-15logger{1} %message%newline" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<!--
|
||||
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user