Skip to content
Snippets Groups Projects
Commit d0d58886 authored by Klaus Fischer's avatar Klaus Fischer
Browse files

Due to implementation of the guts the methode signatures have changed on a large scale

Therefore the merge from the implementation ticket into the methode signaure ticket was necessary
parents 88dee073 e835c472
No related branches found
No related tags found
1 merge request!3Feature/440 mvp net sdk part 1
Showing
with 572 additions and 42 deletions
......@@ -8,15 +8,16 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.7.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
<PackageReference Include="coverlet.collector" Version="3.1.0" />
<PackageReference Include="FluentAssertions" Version="6.7.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0"/>
<PackageReference Include="NUnit" Version="3.13.2"/>
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0"/>
<PackageReference Include="coverlet.collector" Version="3.1.0"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FitConnect\FitConnect.csproj" />
<ProjectReference Include="..\FitConnect\FitConnect.csproj"/>
<ProjectReference Include="..\Services\Services.csproj"/>
</ItemGroup>
</Project>
using System;
using System.IO;
using FitConnect;
using FitConnect.Services;
using FluentAssertions;
using Newtonsoft.Json;
using NUnit.Framework;
namespace E2ETests;
public class OAuthServiceTest {
private string _clientId;
private string _clientSecret;
private OAuthService _oAuthService = null!;
[OneTimeSetUp]
public void OneTimeSetup() {
// relative to the project execution directory
const string secretFile = "../../../http-client.private.env.json";
if (!File.Exists(secretFile)) {
// If the secret file is not found, create it with the default values
// The file will be pretty in C#11, when """ is introduced
File.WriteAllText(secretFile, @"
{
""sender"": {
""id"": ""00000000-0000-0000-0000-000000000000"",
""secret"": ""0000000000000000000000000000000000000000000"",
""scope"": ""send:region:DE""
}
}");
throw new Exception("Please fill the secret.json file with your sender credentials");
}
var jsonContent = File.ReadAllText(secretFile);
var secret = JsonConvert.DeserializeObject<dynamic>(jsonContent);
_clientId = secret.sender.id;
_clientSecret = secret.sender.secret;
}
[SetUp]
public void SetUp() {
var endpoints = FitConnectEndpoints.Create(FitConnectEndpoints.EndpointType.Development);
_oAuthService = new OAuthService(endpoints.TokenUrl);
}
[Test]
public void GetAccessToken_ExpiresInShouldBe1800_WithoutScope() {
var token = _oAuthService.GetTokenAsync(_clientId, _clientSecret).Result;
token.Should().NotBeNull();
token!.ExpiresIn.Should().Be(1800);
token.Scope.Should().Be("send:region:DE");
}
[Test]
public void GetAccessToken_ScopeShouldMatch_WithScope() {
var token = _oAuthService.GetTokenAsync(_clientId, _clientSecret, "send:region:DE01010")
.Result;
token.Should().NotBeNull();
token!.ExpiresIn.Should().Be(1800);
token.Scope.Should().Be("send:region:DE01010");
}
}
......@@ -12,6 +12,10 @@ public class SenderTest {
private string _clientSecret = "";
private Sender _sender;
/// <summary>
/// Setup creates json file for credentials if not found
/// </summary>
/// <exception cref="Exception"></exception>
[OneTimeSetUp]
public void OneTimeSetup() {
// relative to the project execution directory
......@@ -48,20 +52,4 @@ public class SenderTest {
_clientId.Should().NotBe("00000000-0000-0000-0000-000000000000");
_clientSecret.Should().NotBe("0000000000000000000000000000000000000000000");
}
[Test]
public void GetAccessToken() {
var token = _sender.GetTokenAsync(_clientId, _clientSecret).Result;
token.Should().NotBeNull();
token!.ExpiresIn.Should().Be(1800);
token.Scope.Should().Be("send:region:DE");
}
[Test]
public void GetAccessTokenWithScope() {
var token = _sender.GetTokenAsync(_clientId, _clientSecret, "send:region:DE01010").Result;
token.Should().NotBeNull();
token!.ExpiresIn.Should().Be(1800);
token.Scope.Should().Be("send:region:DE01010");
}
}
-----BEGIN CERTIFICATE-----
MIIEyjCCArKgAwIBAgIIMIw7HOs7698wDQYJKoZIhvcNAQELBQAwJTEWMBQGA1UEAxMNZml0Y29u
bmVjdC5kZTELMAkGA1UEBhMCREUwHhcNMjIwNjA4MTEwNzQ3WhcNMjcwNjA4MTEwNzUyWjAlMRYw
FAYDVQQDEw1maXRjb25uZWN0LmRlMQswCQYDVQQGEwJERTCCAiIwDQYJKoZIhvcNAQEBBQADggIP
ADCCAgoCggIBAJxxbIieIEY9Vvql4R6ED5HqtGMjoJZ2xiwF5Zv/DuLseAZEUR7QuBvPG8CLcYOE
JArXcAS5smLfG2LiNerMgDnrLGvBl3qrYOEq0kRIqGkSr5JM2V/bk2UgMToOJGQDBMh6IbU707Xp
u1gHe2wuNxbJE4kALZV8zJX9fE2bc87o3URsw4yv3EnCpR3TskPI2uazNxKWVWjgpZ5yB6PQMbG0
R7e0qGdEeIo5PpaxdkzbJUN4LwnEdZCKbXt3bMqr7wUJ4lXrqCUhO1Y57iR5YoNBTkKgJHV9fbcy
EHs6IZAhxQCCyuczby5UDS4VzXvnqpxxnvI/rv12nc2WPPctvmA3AyHOH7hTugg7UZ75UKFFHqfU
TeY6lWkifUpTpWVZ3Krm0+3Ja/VZzufPSybifTR9v5JMxQdwaqp9E53Cqh1csqciLVazDOjU6Lhn
fjLr4GwSri1FveXDqpq/jJhkTbuDL1fAEs+eDauD3vNxb0Bverpb5/7rOcAKTH0GEzZhSHV23fyP
DpKmpi5h0py42SdbBAZat8C1StMQ7m3UxuDdoMg+zRS5d12d6s0ZFf2xwFCjDVNVN6y7BkSGuA2l
2/I5ojXhK/Wm+DAcKT/osZznyNq4OlHL2ck6LOSSgFCJFrdkpku++gROx2xjUIFQjryUkcPZ6y0l
PLXAHJUEGO97AgMBAAEwDQYJKoZIhvcNAQELBQADggIBADXJ6LP4HdnUiFCgQR8PoY+fR8XCnYx8
FdVB9v9xdsBhE1/B1c8z6kUInQdq2NfsRjyfgA1wIdPElP+b1bu/TKS/GpWrsPHUXDRv67qT13cB
rw8I6rHTDdnF00pEU4mabI32EqGnEAwu8DGlKnDbnh/dY7IQjYK40/ZutcqzybzvBiNFoYu7rKXg
7CThPwc92fnPfFcDJJMU9YlA5C6MaLSxDj0e3z1rl+ew9pab8gclnbzgxGOqFMNPhNRHx0SvFrCF
dPzva9mYDATHgR66hJAo/hov8qJnz6/7xkQgFPy4jHwBk2ubM2SN8+UEyklm7u3v8X6mpvdE7/gC
qWJYJjcpzz7QEBmvJ9yYIALNo8E9UyZNfYgE/hEyBpEccNk7z6y/yHNThcojwbfmYjztl5Ed4uHY
i1ycf5LYcSAxtzD6V5CuIVzmPNkSgB1m8Wu/+5Sy2/uQGIKNK/X6E9f1GjTDBv5KzxOoongc4yri
VinYgmrpoF6Uh6G423IGT6/+SpyQa5oegpSbKKDcSAQKK/fCJQbck03WTbpgKDhc0KDLB2C07yiI
RNgSDRO+eg8BTFjxE3uPVwY8AP+QxK2+Xn5ozuT7aedeS41MQYeeatd6StNy809DvIMb44ZUA6JU
/n8Ok8eHWVY+aShfomcLyH7+EeL9e2LTSp0geUdmsnNI
-----END CERTIFICATE-----
\ No newline at end of file
File added
......@@ -5,20 +5,26 @@
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<RootNamespace>SenderTest</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.7.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
<PackageReference Include="coverlet.collector" Version="3.1.0" />
<PackageReference Include="FluentAssertions" Version="6.7.0"/>
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0"/>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0"/>
<PackageReference Include="NUnit" Version="3.13.2"/>
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0"/>
<PackageReference Include="coverlet.collector" Version="3.1.0"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FitConnect\FitConnect.csproj"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FitConnect\FitConnect.csproj" />
<Folder Include="Certificates"/>
</ItemGroup>
</Project>
using FitConnect;
using Microsoft.Extensions.Logging;
using NUnit.Framework;
namespace SenderTest;
public class JweTest {
private ILogger<JweTest> _logger;
private Sender _sender;
[SetUp]
public void SetUp() {
_logger = LoggerFactory.Create(cfg => cfg.AddConsole())
.CreateLogger<JweTest>();
_sender = new Sender(_logger,
FitConnectEndpoints.Create(FitConnectEndpoints.EndpointType.Development));
}
[Test]
public void TestJwe() {
var jwe = _sender.Encryption.GetTestToken();
Assert.IsNotNull(jwe);
_logger.LogInformation(jwe);
}
}
using System.Security.Cryptography.X509Certificates;
using FitConnect;
using Microsoft.Extensions.Logging;
using NUnit.Framework;
namespace SenderTest;
public class SenderEncryptionWithImportedCertificateTest {
private ILogger _logger = null!;
private Sender _sender = null!;
[OneTimeSetUp]
public void OneTimeSetUp() {
// Import certificate
}
[SetUp]
public void SetUp() {
// Create a new Sender
var fileName = "../../../Certificates/certificate.cer";
var cert = new X509Certificate2(fileName);
_logger = LoggerFactory.Create(cfg => cfg.AddConsole())
.CreateLogger<SenderEncryptionWithSelfSignedCertificateTest>();
_sender = new Sender(_logger,
FitConnectEndpoints.Create(FitConnectEndpoints.EndpointType.Development), cert);
}
[TearDown]
public void TearDown() {
// Dispose the Sender
}
[OneTimeTearDown]
public void OneTimeTearDown() {
// Delete certificate
}
[Test]
public void TestEncryption() {
// Encrypt a message
}
}
using System;
using System.IO;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using FitConnect;
using FitConnect.Security;
using FluentAssertions;
using Microsoft.Extensions.Logging;
using NUnit.Framework;
namespace SenderTest;
public class SenderEncryptionWithSelfSignedCertificateTest {
private const string ToEncrypt = "This is a test message";
private static byte[]? cypher;
private X509Certificate2 _certificate = null!;
private ILogger<SenderEncryptionWithSelfSignedCertificateTest> _logger = null!;
private Sender _sender = null!;
/*
* Encryption test must be changed for production to only allow extern signed certificates
* and forbid self-signed certificates.
*/
[OneTimeSetUp]
public void OneTimeSetup() {
_certificate = RsaEncryption.CreateSelfSignedCertificate("./");
}
[OneTimeTearDown]
public void OneTimeTearDown() {
_certificate.Dispose();
// File.Copy("./certificate.pfx", "../../../Certificates/certificate.pfx", true);
// File.Copy("./certificate.cer", "../../../Certificates/certificate.cer", true);
File.Delete("./certificate.pfx");
File.Delete("./certificate.cer");
}
[SetUp]
public void Setup() {
_logger = LoggerFactory.Create(cfg => cfg.AddConsole())
.CreateLogger<SenderEncryptionWithSelfSignedCertificateTest>();
_sender = new Sender(_logger,
FitConnectEndpoints.Create(FitConnectEndpoints.EndpointType.Development));
var certificate = new X509Certificate2("./certificate.pfx");
_sender.Encryption.ImportCertificate(certificate);
}
[Test]
[Order(10)]
public void CryptWithOutPublicKeyImport() {
cypher = _sender.Encryption.EncryptData(Encoding.UTF8.GetBytes(ToEncrypt));
_logger.LogInformation("Cypher: {}", Convert.ToBase64String(cypher));
}
[Test]
[Order(20)]
public void Decrypt_ResultShouldMatchToEncrypt() {
var result = _sender.Encryption.DecryptDataAsync(cypher!);
Encoding.UTF8.GetString(result).Should().Be(ToEncrypt);
}
[Test]
public void ExportPrivateKey() {
var privateKey = _sender.Encryption.ExportPrivateKey();
_logger.LogInformation("Private key: {}", Convert.ToBase64String(privateKey));
}
}
using System;
using System.Text;
using FitConnect;
using FluentAssertions;
using Microsoft.Extensions.Logging;
using NUnit.Framework;
namespace SenderTest;
public class SenderEncryptionWithoutCertificateTest {
private Sender _sender = null!;
private const string ToEncrypt = "Hello World";
private string _cypherText = null!;
private ILogger<SenderEncryptionWithoutCertificateTest> _logger = null!;
private Sender _sender = null!;
/*
* Encryption test must be changed for production to only allow extern signed certificates
* and forbid self-signed certificates.
*/
[SetUp]
public void Setup() {
[OneTimeSetUp]
public void OneTimeSetUp() {
_logger = LoggerFactory.Create(cfg => cfg.AddConsole())
.CreateLogger<SenderEncryptionWithoutCertificateTest>();
_sender = new Sender(_logger,
......@@ -26,28 +28,27 @@ public class SenderEncryptionWithoutCertificateTest {
[Test]
public void CryptWithOutPublicKeyImport() {
var cypher = _sender.EncryptData(Encoding.UTF8.GetBytes("test"));
[Order(10)]
public void EncryptData_ShouldNotThrowAnyException() {
var cypher = _sender.Encryption.EncryptData(Encoding.UTF8.GetBytes(ToEncrypt));
_logger.LogInformation("Cypher: {}", Convert.ToBase64String(cypher));
_cypherText = Convert.ToBase64String(cypher);
_logger.LogInformation("Cypher: {}", _cypherText);
}
[Test]
[Ignore("Not applicable for production")]
public void CryptWithPublicKeyImport() {
var publicKey = Convert.FromBase64String(
"MIIBCgKCAQEAzu/ek6A5AMuROs+12pncbYNteGkd6ReU28ZY5gCM4hNFI0h1E+0+OST+Yxw7zhvbFhZbYdVt8LmzonMAtENituLxzZj7MsWom/ZzxTdp4Cx5zlx8x6Qx/ZPoSS2T2Sf0ttymaMc6ZadpWsDhg/Mnf6beF1W/QoGH/bHBa8U4rhkUa+OKf3wyo08km8oyUJaj6kkB0VdhRp5rSyvXJtUMZ5A0LcYFygnkHTSQlQhdrAK+6nTo//mfNfPtqta2wBb9ONpVwN0V7I5PSdH2WxZMZsYFicLOGbNeF08gibmL+7TeBTssYtrNVM88cG0v+aWeBun0WVrpCntDIA9HIujWowIDAQAB");
[Order(20)]
public void DecryptData_ShouldMatchToEncrypt() {
var cypher = Convert.FromBase64String(_cypherText);
var plain = _sender.Encryption.DecryptDataAsync(cypher);
var cypher = _sender.EncryptData(Encoding.UTF8.GetBytes("test"), publicKey);
_logger.LogInformation("Cypher: {}", Convert.ToBase64String(cypher));
Encoding.UTF8.GetString(plain).Should().Be(ToEncrypt);
}
[Test]
public void ExportPrivateKey() {
var privateKey = _sender.ExportPrivateKey();
public void ExportPrivateKey_ShouldNotThrowAnyException() {
var privateKey = _sender.Encryption.ExportPrivateKey();
_logger.LogInformation("Private key: {}", Convert.ToBase64String(privateKey));
}
}
using System.Security.Cryptography.X509Certificates;
using FitConnect;
using Microsoft.Extensions.Logging;
using NUnit.Framework;
namespace SenderTest;
public class SubscriberEncryptionWithImportedCertificateTest {
private ILogger _logger = null!;
private Subscriber _subscriber = null!;
[OneTimeSetUp]
public void OneTimeSetUp() {
// Import certificate
}
[SetUp]
public void SetUp() {
// Create a new Sender
var fileName = "../../../Certificates/certificate.pfx";
var cert = new X509Certificate2(fileName);
_logger = LoggerFactory.Create(cfg => cfg.AddConsole())
.CreateLogger<SenderEncryptionWithSelfSignedCertificateTest>();
_subscriber = new Subscriber(_logger,
FitConnectEndpoints.Create(FitConnectEndpoints.EndpointType.Development), cert);
}
[TearDown]
public void TearDown() {
// Dispose the Sender
}
[OneTimeTearDown]
public void OneTimeTearDown() {
// Delete certificate
}
[Test]
public void TestEncryption() {
// Encrypt a message
}
}
......@@ -8,7 +8,13 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InitializationTests", "Init
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "E2ETests", "E2ETests\E2ETests.csproj", "{27115A99-2AE8-42BC-9495-BE2DCEDDF1E8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SenderTest", "SenderTest\SenderTest.csproj", "{68F1EC39-B234-4422-9AA8-E55CFA15025D}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EncryptionTests", "EncryptionTests\EncryptionTests.csproj", "{68F1EC39-B234-4422-9AA8-E55CFA15025D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Services", "Services\Services.csproj", "{1BB06AF4-492C-4041-A947-FE65F7A48698}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RestService", "RestService\RestService.csproj", "{51743B56-6147-43FF-8513-EE38A3E7B188}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Models", "Models\Models.csproj", "{98C78243-6ABD-492D-ACA8-23B3BF17FBDA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
......@@ -32,6 +38,18 @@ Global
{68F1EC39-B234-4422-9AA8-E55CFA15025D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{68F1EC39-B234-4422-9AA8-E55CFA15025D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{68F1EC39-B234-4422-9AA8-E55CFA15025D}.Release|Any CPU.Build.0 = Release|Any CPU
{1BB06AF4-492C-4041-A947-FE65F7A48698}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1BB06AF4-492C-4041-A947-FE65F7A48698}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1BB06AF4-492C-4041-A947-FE65F7A48698}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1BB06AF4-492C-4041-A947-FE65F7A48698}.Release|Any CPU.Build.0 = Release|Any CPU
{51743B56-6147-43FF-8513-EE38A3E7B188}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{51743B56-6147-43FF-8513-EE38A3E7B188}.Debug|Any CPU.Build.0 = Debug|Any CPU
{51743B56-6147-43FF-8513-EE38A3E7B188}.Release|Any CPU.ActiveCfg = Release|Any CPU
{51743B56-6147-43FF-8513-EE38A3E7B188}.Release|Any CPU.Build.0 = Release|Any CPU
{98C78243-6ABD-492D-ACA8-23B3BF17FBDA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{98C78243-6ABD-492D-ACA8-23B3BF17FBDA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{98C78243-6ABD-492D-ACA8-23B3BF17FBDA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{98C78243-6ABD-492D-ACA8-23B3BF17FBDA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{73CE5625-4C13-458E-B524-0DAA850F4041} = {D382641C-B027-411A-814C-C8C20A9505F3}
......
using System.Security.Cryptography.X509Certificates;
using FitConnect.Models;
using FitConnect.RestService;
using FitConnect.Security;
using FitConnect.Services;
using Microsoft.Extensions.Logging;
namespace FitConnect.BaseClasses;
public abstract class FunctionalBaseClass {
public readonly IEncryption Encryption;
protected readonly ILogger? Logger;
protected readonly FitConnectApiService ApiService;
/// <summary>
/// Constructor for the FunctionalBaseClass
/// </summary>
/// <param name="logger">ILogger implementation</param>
/// <param name="endpoints">FitConnect endpoints</param>
/// <param name="certificate">The Encryption certificate</param>
/// <example>
/// new Sender(logger, FitConnectEndpoints.Create(FitConnectEndpoints.EndpointType.Development))
/// </example>
protected FunctionalBaseClass(ILogger? logger, FitConnectEndpoints? endpoints,
X509Certificate2? certificate) {
Endpoints = endpoints ??
FitConnectEndpoints.Create(FitConnectEndpoints.EndpointType.Development);
Logger = logger;
Encryption = new RsaEncryption(logger, certificate);
ApiService = new FitConnectApiService(Endpoints, logger);
}
public FitConnectEndpoints Endpoints { get; }
/// <summary>
/// Receive the SET data
/// </summary>
/// <returns></returns>
public Task<SecurityEventToken> GetSetDataAsync() {
throw new NotImplementedException();
}
}
using System.Security.Cryptography.X509Certificates;
using FitConnect.Models;
using FitConnect.Services;
using FitConnect.Services.Models;
using Microsoft.Extensions.Logging;
namespace FitConnect;
/// <summary>
/// The FitConnect API Client
/// </summary>
// ReSharper disable once UnusedType.Global
public class Client {
private readonly string _clientId;
private readonly string _clientSecret;
private readonly Sender _sender;
private readonly Subscriber _subscriber;
public Client(FitConnectEndpoints endpoints,
string clientId, string clientSecret,
X509Certificate2? certificate = null,
ILogger? logger = null) {
_clientId = clientId;
_clientSecret = clientSecret;
_sender = new Sender(logger, endpoints, certificate);
_subscriber = new Subscriber(logger, endpoints, certificate);
//_service = new FitConnectApiService(endpoints, logger);
}
/// <summary>
/// Get destination for submission.
/// <para>Leika-Key and one of the area specifier has to be set.</para>
/// </summary>
/// <param name="leiaKey">Mandatory</param>
/// <param name="ags"></param>
/// <param name="ars"></param>
/// <param name="areaId"></param>
/// <returns></returns>
public async Task<string> GetDestinationIdAsync(string leiaKey, string? ags, string? ars,
string? areaId) {
if (string.IsNullOrEmpty(leiaKey)) {
throw new ArgumentException("leiaKey is mandatory");
}
if (string.IsNullOrEmpty(ags) &&
string.IsNullOrEmpty(ars) &&
string.IsNullOrEmpty(areaId)) {
throw new ArgumentException("One of the area specifier has to be set");
}
return await _sender.GetDestinationIdAsync(leiaKey, ags, ars, areaId);
}
/// <summary>
/// Sending a submission to the FitConnect API<br/>
/// <para>The submission is prepared for sending to the FitConnect API.</para>
/// </summary>
/// <param name="submission">The submission to send</param>
/// <returns>success</returns>
// ReSharper disable once MemberCanBePrivate.Global
public async Task<bool> SendSubmissionAsync(Submission submission) {
// Einreichung anlegen und ankündigen
var createSubmissionDto = _sender.CreateSubmissionDto(submission);
// Anlagen verschlüsseln
var encryptedAttachments = submission.Attachments
.Select(a => _sender.EncryptAttachment(a)).ToList();
// Anlagen hochladen
await _sender.UploadAttachmentsAsync(encryptedAttachments);
// Metadaten befüllen und verschlüsseln
var metaData = await _sender.CreateMetadataAsync("", new byte[] { });
// Fachdaten verschlüsseln
var encryptedData = _sender.EncryptDataAsync(submission.Data);
// Fachdaten & Metadaten hochladen und Einreichung absenden
await _sender.SubmitSubmissionAsync(submission);
return true;
}
/// <summary>
/// Gets all submissions from the FitConnect API
/// </summary>
/// <returns>List of the available submissions</returns>
// ReSharper disable once MemberCanBePrivate.Global
public async Task<List<Submission>> GetSubmissionsAsync(string destinationId, int offset = 0,
int limit = 100) {
// var pickUpList =
// await _service.SubmissionService.ListSubmissions(destinationId, offset, limit);
// return pickUpList.Submissions.Select(dto => (Submission)dto).ToList();
throw new NotImplementedException();
}
/// <summary>
/// Sending a submission to the FitConnect API
/// </summary>
/// <param name="submission">The submission to send</param>
/// <returns>success</returns>
public bool SendSubmission(Submission submission) {
return SendSubmissionAsync(submission).Result;
}
/// <summary>
/// Gets all submissions from the FitConnect API
/// </summary>
/// <returns>List of the available submissions</returns>
public List<Submission> GetSubmissions(string destinationId, int offset = 0,
int limit = 100) {
return GetSubmissionsAsync(destinationId, offset, limit).Result;
}
}
......@@ -11,18 +11,24 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Newtonsoft.Json.Schema" Version="3.0.14" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Newtonsoft.Json.Schema" Version="3.0.14" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.19.0" />
</ItemGroup>
<ItemGroup>
<None Remove="metadata.schema.json" />
<EmbeddedResource Include="metadata.schema.json" />
<None Remove="metadata.schema.json" />
<EmbeddedResource Include="metadata.schema.json" />
</ItemGroup>
<ItemGroup>
<Folder Include="Interfaces" />
<Folder Include="Interfaces" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Models\Models.csproj" />
<ProjectReference Include="..\Services\Services.csproj" />
</ItemGroup>
</Project>
### Get areas
GET {{routing_api_url}}/v1/areas?areaSearchexpression=93437
Accept: application/json
### Get areas
GET {{routing_api_url}}/v1/routes?leikaKey=99012070006000
Accept: application/json
{
"dev": {
"routing_api_url": "https://routing-api-testing.fit-connect.fitko.dev"
}
}
\ No newline at end of file
using System.Text.Json.Serialization;
namespace FitConnect.Models;
public record Area(string Id, string Name, string Type);
\ No newline at end of file
namespace FitConnect.Models;
public record Attachment(string Id, byte[] Content, string Hash);
using System.Text.Json.Serialization;
using FitConnect.Services.Models;
namespace FitConnect.Models;
public class Callback {
[JsonPropertyName("url")]
public string? Url { get; set; }
public record Callback(string? Url, string? Secret) {
public static explicit operator Callback(CallbackDto dto) => new(dto.Url, null);
[JsonPropertyName("secret")]
public string? Secret { get; set; }
public static explicit operator CallbackDto(Callback model) => new() { Url = model.Url };
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment