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

Merged 438-method signatures into 440

parents 81a1029b d08a69a2
No related branches found
No related tags found
1 merge request!3Feature/440 mvp net sdk part 1
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\FitConnect\FitConnect.csproj" /> <ProjectReference Include="..\FitConnect\FitConnect.csproj"/>
</ItemGroup> </ItemGroup>
</Project> </Project>
...@@ -91,7 +91,7 @@ async Task DetailSubscriberCall() { ...@@ -91,7 +91,7 @@ async Task DetailSubscriberCall() {
Console.WriteLine( Console.WriteLine(
"This is a dummy client to demonstrate the usage of the FitConnect SDK for .NET"); "This is a dummy client to demonstrate the usage of the FitConnect SDK for .NET");
_logger = new Microsoft.Extensions.Logging.Logger<System.AppDomain>(new NullLoggerFactory()); _logger = new Logger<AppDomain>(new NullLoggerFactory());
client = client =
new Client(FitConnectEndpoints.Create(FitConnectEndpoints.EndpointType.Development), new Client(FitConnectEndpoints.Create(FitConnectEndpoints.EndpointType.Development),
logger: _logger); logger: _logger);
using System; using System;
using System.IO; using System.IO;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using FitConnect; using FitConnect;
using FitConnect.Security; using FitConnect.Security;
using FluentAssertions; using FluentAssertions;
using Microsoft.IdentityModel.Tokens;
using Newtonsoft.Json; using Newtonsoft.Json;
using NUnit.Framework; using NUnit.Framework;
......
...@@ -8,7 +8,8 @@ using Microsoft.Extensions.Logging; ...@@ -8,7 +8,8 @@ using Microsoft.Extensions.Logging;
namespace FitConnect.BaseClasses; namespace FitConnect.BaseClasses;
public abstract class FunctionalBaseClass { public abstract class FunctionalBaseClass {
// protected readonly FitConnectApiService ApiService; public X509Certificate2 Certificate { get; }
// protected readonly FitConnectApiService ApiService;
protected IOAuthService OAuthService; protected IOAuthService OAuthService;
protected ISubmissionService SubmissionService; protected ISubmissionService SubmissionService;
...@@ -16,8 +17,6 @@ public abstract class FunctionalBaseClass { ...@@ -16,8 +17,6 @@ public abstract class FunctionalBaseClass {
public readonly IEncryption Encryption; public readonly IEncryption Encryption;
protected readonly ILogger? Logger; protected readonly ILogger? Logger;
protected readonly X509Certificate2 Certificate;
internal Client Owner { get; set; }
/// <summary> /// <summary>
...@@ -35,6 +34,7 @@ public abstract class FunctionalBaseClass { ...@@ -35,6 +34,7 @@ public abstract class FunctionalBaseClass {
IOAuthService oAuthService, IOAuthService oAuthService,
ISubmissionService submissionService, ISubmissionService submissionService,
IRouteService routeService) { IRouteService routeService) {
Certificate = certificate;
Endpoints = endpoints ?? Endpoints = endpoints ??
FitConnectEndpoints.Create(FitConnectEndpoints.EndpointType.Development); FitConnectEndpoints.Create(FitConnectEndpoints.EndpointType.Development);
...@@ -42,15 +42,16 @@ public abstract class FunctionalBaseClass { ...@@ -42,15 +42,16 @@ public abstract class FunctionalBaseClass {
OAuthService = oAuthService; OAuthService = oAuthService;
SubmissionService = submissionService; SubmissionService = submissionService;
RouteService = routeService; RouteService = routeService;
Certificate = certificate;
Encryption = new RsaEncryption(logger, certificate); Encryption = new RsaEncryption(logger, certificate);
} }
internal Client Owner { get; set; }
public FitConnectEndpoints Endpoints { get; } public FitConnectEndpoints Endpoints { get; }
/// <summary> /// <summary>
/// Requesting the OAuth-Token /// Requesting the OAuth-Token
/// </summary> /// </summary>
/// <param name="clientId"></param> /// <param name="clientId"></param>
/// <param name="clientSecret"></param> /// <param name="clientSecret"></param>
......
...@@ -11,13 +11,10 @@ namespace FitConnect; ...@@ -11,13 +11,10 @@ namespace FitConnect;
/// </summary> /// </summary>
// ReSharper disable once UnusedType.Global // ReSharper disable once UnusedType.Global
public class Client { public class Client {
private readonly X509Certificate2? _receiverCertificate;
private readonly X509Certificate2? _senderCertificate;
internal string? ClientId; internal string? ClientId;
internal string? ClientSecret; internal string? ClientSecret;
private readonly X509Certificate2? _senderCertificate;
private readonly X509Certificate2? _receiverCertificate;
public FluentSender Sender { get; }
public FluentSubscriber Subscriber { get; }
/// <summary> /// <summary>
/// FitConnect Client /// FitConnect Client
...@@ -51,6 +48,9 @@ public class Client { ...@@ -51,6 +48,9 @@ public class Client {
_receiverCertificate, logger) { Owner = this }; _receiverCertificate, logger) { Owner = this };
} }
public FluentSender Sender { get; }
public FluentSubscriber Subscriber { get; }
/// <summary> /// <summary>
/// Get destination for submission. /// Get destination for submission.
...@@ -144,4 +144,4 @@ public class Client { ...@@ -144,4 +144,4 @@ public class Client {
int limit = 100) { int limit = 100) {
return GetSubmissionsAsync(destinationId, offset, limit).Result; return GetSubmissionsAsync(destinationId, offset, limit).Result;
} }
} }
\ No newline at end of file
...@@ -47,10 +47,14 @@ public class FluentSender : Sender, IFluentApi<FluentSender> { ...@@ -47,10 +47,14 @@ public class FluentSender : Sender, IFluentApi<FluentSender> {
public CreateSubmissionDto? NewSubmission { get; set; } public CreateSubmissionDto? NewSubmission { get; set; }
public Submission Submission { get; set; } public Submission Submission { get; set; }
public static Sender Create() {
throw new NotImplementedException();
}
/// <summary>
/// Authenticates with the FitConnect API.
/// </summary>
/// <param name="clientId">The client id from the submission service</param>
/// <param name="clientSecret">The client secret</param>
/// <param name="scope">Optional scope for the credentials</param>
/// <returns></returns>
public FluentSender Authenticate(string clientId, string clientSecret, string? scope = null) { public FluentSender Authenticate(string clientId, string clientSecret, string? scope = null) {
if (_nextStep != State.Authenticate) if (_nextStep != State.Authenticate)
throw new InvalidOperationException( throw new InvalidOperationException(
...@@ -65,12 +69,12 @@ public class FluentSender : Sender, IFluentApi<FluentSender> { ...@@ -65,12 +69,12 @@ public class FluentSender : Sender, IFluentApi<FluentSender> {
} }
/// <summary> /// <summary>
/// Creates a new <see cref="Submission"/> on the FitConnect server. /// Creates a new <see cref="Submission" /> on the FitConnect server.
/// </summary> /// </summary>
/// <param name="submission"></param> /// <param name="submission" cref="Submission">The <see cref="Submission"/> body to be sent</param>
/// <returns></returns> /// <returns></returns>
/// <exception cref="InvalidOperationException"></exception> /// <exception cref="InvalidOperationException">If sender is not authenticated</exception>
/// <exception cref="ArgumentException"></exception> /// <exception cref="ArgumentException">If submission is not ready to be sent</exception>
public FluentSender CreateSubmission(Submission submission) { public FluentSender CreateSubmission(Submission submission) {
if (_nextStep != State.CreateSubmission) if (_nextStep != State.CreateSubmission)
throw new InvalidOperationException( throw new InvalidOperationException(
...@@ -97,6 +101,11 @@ public class FluentSender : Sender, IFluentApi<FluentSender> { ...@@ -97,6 +101,11 @@ public class FluentSender : Sender, IFluentApi<FluentSender> {
} }
/// <summary>
/// Posts the <see cref="Attachment"/>s to the FitConnect API. The attachment ids are sent with creating the submission.
/// </summary>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public FluentSender UploadAttachments() { public FluentSender UploadAttachments() {
if (_nextStep != State.UploadAttachments) if (_nextStep != State.UploadAttachments)
throw new InvalidOperationException( throw new InvalidOperationException(
...@@ -113,6 +122,17 @@ public class FluentSender : Sender, IFluentApi<FluentSender> { ...@@ -113,6 +122,17 @@ public class FluentSender : Sender, IFluentApi<FluentSender> {
return this; return this;
} }
/// <summary>
/// Sending the submission and finishing the process.
/// <para>
/// Finishing the submission by transmitting <see cref="Metadata"/> and <see cref="Data"/>.
/// </para>
/// </summary>
/// <param name="metadata"></param>
/// <param name="data"></param>
/// <returns></returns>
/// <remarks>This call finishes the submission process</remarks>
/// <exception cref="InvalidOperationException"></exception>
public FluentSender SendSubmission(Metadata metadata, Data? data = null) { public FluentSender SendSubmission(Metadata metadata, Data? data = null) {
if (_nextStep != State.SendSubmission) if (_nextStep != State.SendSubmission)
throw new InvalidOperationException( throw new InvalidOperationException(
......
...@@ -4,10 +4,10 @@ namespace FitConnect.Models; ...@@ -4,10 +4,10 @@ namespace FitConnect.Models;
public record Callback(string? Url, string? Secret) { public record Callback(string? Url, string? Secret) {
public static explicit operator Callback(CallbackDto dto) { public static explicit operator Callback(CallbackDto dto) {
return new(dto.Url, null); return new Callback(dto.Url, null);
} }
public static explicit operator CallbackDto(Callback model) { public static explicit operator CallbackDto(Callback model) {
return new() { Url = model.Url }; return new CallbackDto { Url = model.Url };
} }
} }
namespace FitConnect.Models; namespace FitConnect.Models;
/// <summary> /// <summary>
/// Representation of FitConnect error responses /// Representation of FitConnect error responses
/// </summary> /// </summary>
public class FitConnectException : Exception { public class FitConnectException : Exception {
public enum ErrorTypeEnum { public enum ErrorTypeEnum {
Unknown, Unknown
} }
public ErrorTypeEnum ErrorType { get; set; }
public FitConnectException(string message, ErrorTypeEnum errorType = ErrorTypeEnum.Unknown, public FitConnectException(string message, ErrorTypeEnum errorType = ErrorTypeEnum.Unknown,
Exception? innerException = null) : base(message, innerException) { Exception? innerException = null) : base(message, innerException) {
ErrorType = errorType; ErrorType = errorType;
} }
public ErrorTypeEnum ErrorType { get; set; }
} }
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
using FitConnect.Models;
namespace FitConnect.Models; namespace FitConnect.Models;
...@@ -13,7 +12,6 @@ public class Metadata : IEncrypt { ...@@ -13,7 +12,6 @@ public class Metadata : IEncrypt {
} }
} }
public class Data : IEncrypt { public class Data : IEncrypt {
public string Encrypt(PublicKey publicKey) { public string Encrypt(PublicKey publicKey) {
return ""; return "";
......
...@@ -9,7 +9,7 @@ public class ServiceType { ...@@ -9,7 +9,7 @@ public class ServiceType {
public string? Identifier { get; set; } public string? Identifier { get; set; }
public static explicit operator ServiceType(ServiceTypeDto dto) { public static explicit operator ServiceType(ServiceTypeDto dto) {
return new() { return new ServiceType {
Description = dto.Description, Description = dto.Description,
Identifier = dto.Identifier, Identifier = dto.Identifier,
Name = dto.Name Name = dto.Name
...@@ -17,13 +17,14 @@ public class ServiceType { ...@@ -17,13 +17,14 @@ public class ServiceType {
} }
public static explicit operator ServiceTypeDto(ServiceType model) { public static explicit operator ServiceTypeDto(ServiceType model) {
return new() { return new ServiceTypeDto {
Description = model.Description, Description = model.Description,
Identifier = model.Identifier, Identifier = model.Identifier,
Name = model.Name Name = model.Name
}; };
} }
public bool IsValid() => public bool IsValid() {
(!string.IsNullOrWhiteSpace(Name)) && (!string.IsNullOrWhiteSpace(Identifier)); return !string.IsNullOrWhiteSpace(Name) && !string.IsNullOrWhiteSpace(Identifier);
}
} }
using System.Security.Cryptography.X509Certificates;
using FitConnect.Services.Models; using FitConnect.Services.Models;
namespace FitConnect.Models; namespace FitConnect.Models;
...@@ -31,14 +30,14 @@ public class Submission { ...@@ -31,14 +30,14 @@ public class Submission {
public ServiceType ServiceType { get; init; } public ServiceType ServiceType { get; init; }
public Callback? Callback { get; set; } public Callback? Callback { get; set; }
public Metadata Metadata { get; set; }
public Data? Data { get; set; }
public bool IsSubmissionReadyToAdd(out string? error) { public bool IsSubmissionReadyToAdd(out string? error) {
var innerError = ""; var innerError = "";
if (string.IsNullOrEmpty(DestinationId)) innerError += "DestinationId is required\r\n"; if (string.IsNullOrEmpty(DestinationId)) innerError += "DestinationId is required\r\n";
if (ServiceType.IsValid()) { if (ServiceType.IsValid()) innerError += "ServiceType is invalid\r\n";
innerError += "ServiceType is invalid\r\n";
}
if (string.IsNullOrWhiteSpace(innerError)) { if (string.IsNullOrWhiteSpace(innerError)) {
error = null; error = null;
...@@ -53,16 +52,8 @@ public class Submission { ...@@ -53,16 +52,8 @@ public class Submission {
return true; return true;
} }
/// <summary>
/// Fachdaten
/// </summary>
public Data? Data { get; set; }
public Metadata Metadata { get; set; }
public static explicit operator Submission(SubmissionForPickupDto dto) { public static explicit operator Submission(SubmissionForPickupDto dto) {
return new() { return new Submission {
Id = dto.SubmissionId, Id = dto.SubmissionId,
Callback = null, Callback = null,
DestinationId = dto.DestinationId, DestinationId = dto.DestinationId,
...@@ -71,7 +62,7 @@ public class Submission { ...@@ -71,7 +62,7 @@ public class Submission {
} }
public static explicit operator Submission(SubmissionDto dto) { public static explicit operator Submission(SubmissionDto dto) {
return new() { return new Submission {
Id = dto.SubmissionId, Id = dto.SubmissionId,
Callback = (Callback)dto.Callback, Callback = (Callback)dto.Callback,
DestinationId = dto.DestinationId, DestinationId = dto.DestinationId,
...@@ -80,7 +71,7 @@ public class Submission { ...@@ -80,7 +71,7 @@ public class Submission {
} }
public static explicit operator CreateSubmissionDto(Submission sub) { public static explicit operator CreateSubmissionDto(Submission sub) {
return new() { return new CreateSubmissionDto {
AnnouncedAttachments = sub.Attachments.Select(a => a.Id).ToList(), AnnouncedAttachments = sub.Attachments.Select(a => a.Id).ToList(),
DestinationId = sub.DestinationId, DestinationId = sub.DestinationId,
ServiceType = (ServiceTypeDto)sub.ServiceType, ServiceType = (ServiceTypeDto)sub.ServiceType,
......
using System.Security.Cryptography.X509Certificates; using System.Runtime.ConstrainedExecution;
using System.Security.Cryptography.X509Certificates;
using Autofac; using Autofac;
using FitConnect.BaseClasses; using FitConnect.BaseClasses;
using FitConnect.Models; using FitConnect.Models;
...@@ -8,10 +9,10 @@ using Microsoft.Extensions.Logging; ...@@ -8,10 +9,10 @@ using Microsoft.Extensions.Logging;
namespace FitConnect; namespace FitConnect;
public partial class Sender : FunctionalBaseClass { public class Sender : FunctionalBaseClass {
internal Sender(FitConnectEndpoints endpoints, internal Sender(FitConnectEndpoints endpoints,
X509Certificate2 certificate, X509Certificate2 certificate,
IOAuthService oAuthService, IOAuthService oAuthService,
ISubmissionService submissionService, ISubmissionService submissionService,
IRouteService routeService, IRouteService routeService,
ILogger? logger = null ILogger? logger = null
...@@ -20,7 +21,7 @@ public partial class Sender : FunctionalBaseClass { ...@@ -20,7 +21,7 @@ public partial class Sender : FunctionalBaseClass {
} }
public static Sender Create(FitConnectEndpoints endpoints, public static Sender Create(FitConnectEndpoints endpoints,
X509Certificate2 certificate,ILogger? logger = null) { X509Certificate2 certificate, ILogger? logger = null) {
var container = DiContainer.GetContainer(endpoints, certificate, null, logger); var container = DiContainer.GetContainer(endpoints, certificate, null, logger);
return container.Resolve<Sender>(); return container.Resolve<Sender>();
} }
...@@ -78,14 +79,16 @@ public partial class Sender : FunctionalBaseClass { ...@@ -78,14 +79,16 @@ public partial class Sender : FunctionalBaseClass {
} }
/// <summary> /// <summary>
/// Encrypt attachments (Anhänge) /// Encrypt attachments (Anhänge)
/// </summary> /// </summary>
/// <param name="publicKey">Public key for encryption</param> /// <param name="publicKey">Public key for encryption</param>
/// <param name="attachments">List of attachments to encrypt</param> /// <param name="attachments">List of attachments to encrypt</param>
/// <returns></returns> /// <returns></returns>
public Dictionary<string, string> public Dictionary<string, string>
Encrypt(PublicKey publicKey, IEnumerable<Attachment> attachments) => Encrypt(PublicKey publicKey, IEnumerable<Attachment> attachments) {
attachments.Select(a => Encrypt(publicKey, a)).ToDictionary(p => p.Key, p => p.Value); return attachments.Select(a => Encrypt(publicKey, a))
.ToDictionary(p => p.Key, p => p.Value);
}
/// <summary> /// <summary>
/// Create Metadata incl. Hash /// Create Metadata incl. Hash
...@@ -98,7 +101,7 @@ public partial class Sender : FunctionalBaseClass { ...@@ -98,7 +101,7 @@ public partial class Sender : FunctionalBaseClass {
} }
public CreateSubmissionDto AddSubmission(Submission submission) { public CreateSubmissionDto AddSubmission(Submission submission) {
return new() { return new CreateSubmissionDto {
DestinationId = submission.DestinationId, DestinationId = submission.DestinationId,
ServiceType = (ServiceTypeDto)submission.ServiceType, ServiceType = (ServiceTypeDto)submission.ServiceType,
AnnouncedAttachments = submission.Attachments.Select(a => a.Id).ToList() AnnouncedAttachments = submission.Attachments.Select(a => a.Id).ToList()
...@@ -106,7 +109,7 @@ public partial class Sender : FunctionalBaseClass { ...@@ -106,7 +109,7 @@ public partial class Sender : FunctionalBaseClass {
} }
/// <summary> /// <summary>
/// Uploading the encrypted data to the server /// Uploading the encrypted data to the server
/// </summary> /// </summary>
/// <param name="encryptedAttachments">Encrypted attachments with id and content</param> /// <param name="encryptedAttachments">Encrypted attachments with id and content</param>
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
...@@ -126,7 +129,7 @@ public partial class Sender : FunctionalBaseClass { ...@@ -126,7 +129,7 @@ public partial class Sender : FunctionalBaseClass {
/// <summary> /// <summary>
/// Encrypt Metadata with public key /// Encrypt Metadata with public key
/// </summary> /// </summary>
/// <param name="publicKey"></param> /// <param name="publicKey"></param>
/// <param name="metadata"></param> /// <param name="metadata"></param>
...@@ -137,7 +140,7 @@ public partial class Sender : FunctionalBaseClass { ...@@ -137,7 +140,7 @@ public partial class Sender : FunctionalBaseClass {
} }
/// <summary> /// <summary>
/// Encrypt data with public key (Fachdaten) /// Encrypt data with public key (Fachdaten)
/// </summary> /// </summary>
/// <param name="publicKey"></param> /// <param name="publicKey"></param>
/// <param name="data"></param> /// <param name="data"></param>
...@@ -148,7 +151,7 @@ public partial class Sender : FunctionalBaseClass { ...@@ -148,7 +151,7 @@ public partial class Sender : FunctionalBaseClass {
} }
/// <summary> /// <summary>
/// Uploading the encrypted data and metadata to the server /// Uploading the encrypted data and metadata to the server
/// </summary> /// </summary>
/// <param name="encryptedData"></param> /// <param name="encryptedData"></param>
/// <param name="encryptedMetadata"></param> /// <param name="encryptedMetadata"></param>
...@@ -158,9 +161,9 @@ public partial class Sender : FunctionalBaseClass { ...@@ -158,9 +161,9 @@ public partial class Sender : FunctionalBaseClass {
} }
protected SubmitSubmissionDto CreateSubmitSubmissionDto(Submission submission) { protected SubmitSubmissionDto CreateSubmitSubmissionDto(Submission submission) {
return new() { return new SubmitSubmissionDto {
EncryptedData = submission.Data?.Encrypt(this.Certificate.PublicKey), EncryptedData = submission.Data?.Encrypt(Certificate.PublicKey),
EncryptedMetadata = submission.Metadata.Encrypt(Certificate.PublicKey), EncryptedMetadata = submission.Metadata.Encrypt(Certificate.PublicKey)
}; };
} }
} }
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.1"/>
</ItemGroup> </ItemGroup>
</Project> </Project>
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