Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#170-Add support for the v1.IATSSCD interface #171

Merged
merged 9 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions src/fiskaltrust.Launcher/Clients/ATSSCDClientFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using fiskaltrust.ifPOS.v1.at;
using fiskaltrust.Launcher.Common.Configuration;
using fiskaltrust.Middleware.Abstractions;
using fiskaltrust.Middleware.Interface.Client;
using fiskaltrust.Middleware.Interface.Client.Grpc;
using fiskaltrust.Middleware.Interface.Client.Http;
using fiskaltrust.Middleware.Interface.Client.Http.ATSSCD;
using fiskaltrust.Middleware.Interface.Client.Soap;
using Grpc.Core;
using Grpc.Net.Client;

namespace fiskaltrust.Launcher.Clients
{
public class ATSSCDClientFactory : IClientFactory<IATSSCD>
{
private readonly LauncherConfiguration _launcherConfiguration;

public ATSSCDClientFactory(LauncherConfiguration launcherConfiguration) => _launcherConfiguration = launcherConfiguration;

public IATSSCD CreateClient(ClientConfiguration configuration)
{
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}

var retryPolicyoptions = new RetryPolicyOptions
{
DelayBetweenRetries = configuration.DelayBetweenRetries != default ? configuration.DelayBetweenRetries : RetryPolicyOptions.Default.DelayBetweenRetries,
Retries = configuration.RetryCount ?? RetryPolicyOptions.Default.Retries,
ClientTimeout = configuration.Timeout != default ? configuration.Timeout : RetryPolicyOptions.Default.ClientTimeout
};

var isHttps = !string.IsNullOrEmpty(_launcherConfiguration?.TlsCertificatePath) || !string.IsNullOrEmpty(_launcherConfiguration?.TlsCertificateBase64);
var sslValidationDisabled = _launcherConfiguration != null && _launcherConfiguration.SslValidation.HasValue && !_launcherConfiguration.SslValidation.Value;

return configuration.UrlType switch
{
"grpc" => GrpcATSSCDFactory.CreateSSCDAsync(new GrpcClientOptions
{
Url = new Uri(configuration.Url.Replace("grpc://", isHttps ? "https://" : "http://")),
RetryPolicyOptions = retryPolicyoptions,
ChannelOptions = new GrpcChannelOptions
{
Credentials = isHttps ? ChannelCredentials.SecureSsl : ChannelCredentials.Insecure,
HttpHandler = isHttps && sslValidationDisabled ? new HttpClientHandler { ServerCertificateCustomValidationCallback = (httpRequestMessage, cert, cetChain, policyErrors) => true } : null
}
}).Result,
"rest" => HttpATSSCDFactory.CreateSSCDAsync(new HttpATSSCDClientOptions
{
Url = new Uri(configuration.Url.Replace("rest://", isHttps ? "https://" : "http://")),
RetryPolicyOptions = retryPolicyoptions,
DisableSslValidation = sslValidationDisabled
}).Result,
"http" or "https" or "net.tcp" => SoapATSSCDFactory.CreateSSCDAsync(new ClientOptions
{
Url = new Uri(configuration.Url),
RetryPolicyOptions = retryPolicyoptions
}).Result,
_ => throw new ArgumentException("This version of the fiskaltrust Launcher currently only supports gRPC, REST and SOAP communication."),
};
}
}
}
4 changes: 4 additions & 0 deletions src/fiskaltrust.Launcher/Commands/HostCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using fiskaltrust.Launcher.Helpers;
using ILogger = Microsoft.Extensions.Logging.ILogger;
using fiskaltrust.Launcher.Factories;
using fiskaltrust.ifPOS.v1.at;

namespace fiskaltrust.Launcher.Commands
{
Expand Down Expand Up @@ -133,6 +134,7 @@ public static async Task<int> HandleAsync(HostOptions hostOptions, HostServices

services.AddSingleton<IClientFactory<IDESSCD>, DESSCDClientFactory>();
services.AddSingleton<IClientFactory<IITSSCD>, ITSSCDClientFactory>();
services.AddSingleton<IClientFactory<IATSSCD>, ATSSCDClientFactory>();
services.AddSingleton<IClientFactory<IPOS>, POSClientFactory>();

using var downloader = new PackageDownloader(services.BuildServiceProvider().GetRequiredService<ILogger<PackageDownloader>>(), launcherConfiguration, hostServices.LauncherExecutablePath);
Expand All @@ -147,9 +149,11 @@ public static async Task<int> HandleAsync(HostOptions hostOptions, HostServices
typeof(IPOS),
typeof(IDESSCD),
typeof(IITSSCD),
typeof(IATSSCD),
typeof(IClientFactory<IPOS>),
typeof(IClientFactory<IDESSCD>),
typeof(IClientFactory<IITSSCD>),
typeof(IClientFactory<IATSSCD>),
typeof(JournalRequest),
typeof(JournalResponse),
typeof(IHelper),
Expand Down
15 changes: 13 additions & 2 deletions src/fiskaltrust.Launcher/Extensions/WebApplicationExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using fiskaltrust.ifPOS.v1;
using fiskaltrust.ifPOS.v1.at;
using fiskaltrust.ifPOS.v1.de;
using fiskaltrust.ifPOS.v1.it;
using Microsoft.AspNetCore.Mvc;
Expand All @@ -21,8 +22,8 @@ private static IEnumerable<RouteHandlerBuilder> MapMultiplePrefixed(this WebAppl

public static WebApplication AddQueueEndpoints(this WebApplication app, IPOS pos)
{
app.MapMultiplePrefixed(_prefixesV1, "Echo", EndpointRouteBuilderExtensions.MapPost, async (EchoRequest req) => await pos.EchoAsync(req));
app.MapMultiplePrefixed(_prefixesV0, "Echo", EndpointRouteBuilderExtensions.MapPost, async ([FromBody] string message) => (await pos.EchoAsync(new EchoRequest { Message = message })).Message);
app.MapMultiplePrefixed(_prefixesV1, "Echo", EndpointRouteBuilderExtensions.MapPost, async (ifPOS.v1.EchoRequest req) => await pos.EchoAsync(req));
app.MapMultiplePrefixed(_prefixesV0, "Echo", EndpointRouteBuilderExtensions.MapPost, async ([FromBody] string message) => (await pos.EchoAsync(new ifPOS.v1.EchoRequest { Message = message })).Message);
app.MapMultiplePrefixed(_prefixes, "Sign", EndpointRouteBuilderExtensions.MapPost, async (ReceiptRequest req) => await pos.SignAsync(req));
app.MapMultiplePrefixed(_prefixes, "Journal", EndpointRouteBuilderExtensions.MapPost, ([FromQuery] long type, [FromQuery] long? from, [FromQuery] long? to) =>
{
Expand Down Expand Up @@ -72,5 +73,15 @@ public static WebApplication AddScuItEndpoints(this WebApplication app, IITSSCD
app.MapMultiplePrefixed(_prefixesV1, "GetRTInfo", EndpointRouteBuilderExtensions.MapGet, async () => await sscd.GetRTInfoAsync());
return app;
}


public static WebApplication AddScuAtEndpoints(this WebApplication app, IATSSCD ssat)
{
app.MapMultiplePrefixed(_prefixesV1, "Certificate", EndpointRouteBuilderExtensions.MapGet, async () => await ssat.CertificateAsync());
app.MapMultiplePrefixed(_prefixesV1, "ZDA", EndpointRouteBuilderExtensions.MapGet, async () => await ssat.ZdaAsync());
app.MapMultiplePrefixed(_prefixesV1, "Sign", EndpointRouteBuilderExtensions.MapPost, async (SignRequest req) => await ssat.SignAsync(req));
app.MapMultiplePrefixed(_prefixesV1, "Echo", EndpointRouteBuilderExtensions.MapPost, async (ifPOS.v1.at.EchoRequest req) => await ssat.EchoAsync(req));
return app;
}
}
}
8 changes: 4 additions & 4 deletions src/fiskaltrust.Launcher/ProcessHost/ProcessHostMonarch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ private void Setup()
_process.OutputDataReceived += ReceiveStdOut;
_process.ErrorDataReceived += ReceiveStdOut;

// if (Debugger.IsAttached && _packageType == PackageType.Helper)
// {
// _process.StartInfo.Arguments += " --debugging";
// }
//if (Debugger.IsAttached && _packageType == PackageType.Queue)
//{
// _process.StartInfo.Arguments += " --debugging";
//}
}

private void ReceiveStdOut(object sender, DataReceivedEventArgs e)
Expand Down
11 changes: 11 additions & 0 deletions src/fiskaltrust.Launcher/ProcessHost/ProcessHostPlebeian.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using fiskaltrust.ifPOS.v1;
using fiskaltrust.ifPOS.v1.at;
using fiskaltrust.ifPOS.v1.de;
using fiskaltrust.ifPOS.v1.it;
using fiskaltrust.Launcher.Common.Configuration;
Expand Down Expand Up @@ -150,6 +151,10 @@ private async Task StartHosting(string[] uris)
{
await _hosting.HostService(url, hostingType.Value, (IITSSCD)instance, addEndpoints);
}
else if (instanceInterface == typeof(IATSSCD))
{
await _hosting.HostService(url, hostingType.Value, (IATSSCD)instance, addEndpoints);
}
break;
case PackageType.Queue:
await _hosting.HostService(url, hostingType.Value, (IPOS)instance, addEndpoints);
Expand Down Expand Up @@ -212,6 +217,12 @@ private static (object, Action<WebApplication>, Type) GetScu(IServiceProvider se
return (scuIt, (WebApplication app) => app.AddScuItEndpoints(scuIt), typeof(IITSSCD));
}

var scuAt = services.GetService<IATSSCD>();
if (scuAt is not null)
{
return (scuAt, (WebApplication app) => app.AddScuAtEndpoints(scuAt), typeof(IATSSCD));
}

throw new Exception("Could not resolve SCU with supported country. (Curently supported are DE and IT)");
}

Expand Down
11 changes: 5 additions & 6 deletions src/fiskaltrust.Launcher/fiskaltrust.Launcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
<ItemGroup>
<PackageReference Include="CoreWCF.Http" Version="1.5.1" />
<PackageReference Include="CoreWCF.NetTcp" Version="1.5.1" />
<PackageReference Include="fiskaltrust.interface" Version="1.3.50-rc1" />
<PackageReference Include="fiskaltrust.interface" Version="1.3.55-rc2" />
<PackageReference Include="fiskaltrust.Middleware.Abstractions" Version="1.3.3" />

<PackageReference Include="fiskaltrust.Middleware.Interface.Client.Soap" Version="1.3.50-rc2" />
<PackageReference Include="fiskaltrust.Middleware.Interface.Client.Soap" Version="1.3.55-rc2" />
<PackageReference Include="fiskaltrust.storage.serialization" Version="1.3.47" />
<PackageReference Include="fiskaltrust.Middleware.Interface.Client.Grpc" Version="1.3.50-rc2" />
<PackageReference Include="fiskaltrust.Middleware.Interface.Client.Http" Version="1.3.50-rc2" />
<PackageReference Include="fiskaltrust.Middleware.Interface.Client.Grpc" Version="1.3.55-rc2" />
<PackageReference Include="fiskaltrust.Middleware.Interface.Client.Http" Version="1.3.55-rc2" />
<PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="8.0.0" />
<PackageReference Include="Polly" Version="8.2.1" />
<PackageReference Include="Polly.Extensions.Http" Version="3.0.0" />
Expand All @@ -39,7 +39,6 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="../fiskaltrust.Launcher.Common/fiskaltrust.Launcher.Common.csproj"
PrivateAssets="all" />
<ProjectReference Include="../fiskaltrust.Launcher.Common/fiskaltrust.Launcher.Common.csproj" PrivateAssets="all" />
</ItemGroup>
</Project>
Loading