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