From 60aeec1839c0aedc0c6296368cea978cc56b4a38 Mon Sep 17 00:00:00 2001 From: Roman Ettlinger Date: Thu, 9 Nov 2023 15:59:47 +0100 Subject: [PATCH] feat: introduce enums for API responses --- .../Controllers/ApplicationsController.cs | 2 +- .../Models/ApiModels/ApplicationApiModel.cs | 23 +++++++++++++++---- .../ApiModels/CertificateGroupApiModel.cs | 23 +++++++++++++++---- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/GDSwithREST/Controllers/ApplicationsController.cs b/GDSwithREST/Controllers/ApplicationsController.cs index 0c8953d..e25236b 100644 --- a/GDSwithREST/Controllers/ApplicationsController.cs +++ b/GDSwithREST/Controllers/ApplicationsController.cs @@ -101,7 +101,7 @@ public async Task> RegisterApplication([FromBo { ApplicationId = applicationRaw.ApplicationId, ApplicationUri = applicationRaw.ApplicationUri, - ApplicationType = (ApplicationType)applicationRaw.ApplicationType, + ApplicationType = (Opc.Ua.ApplicationType)applicationRaw.ApplicationType, ApplicationNames = applicationName, ProductUri = applicationRaw.ProductUri }; diff --git a/GDSwithREST/Data/Models/ApiModels/ApplicationApiModel.cs b/GDSwithREST/Data/Models/ApiModels/ApplicationApiModel.cs index 00aee51..c727616 100644 --- a/GDSwithREST/Data/Models/ApiModels/ApplicationApiModel.cs +++ b/GDSwithREST/Data/Models/ApiModels/ApplicationApiModel.cs @@ -1,4 +1,5 @@ -using System.Security.Cryptography.X509Certificates; +using System.Runtime.Serialization; +using System.Security.Cryptography.X509Certificates; using System.Text.Json.Serialization; namespace GDSwithREST.Data.Models.ApiModels @@ -20,7 +21,7 @@ public class ApplicationApiModel /// The name of the Application /// public string ApplicationName { get; set; } = null!; - public int ApplicationType { get; set; } + public ApplicationType ApplicationType { get; set; } public string ProductUri { get; set; } = null!; /// /// The gds signed certificate of the Application @@ -34,7 +35,7 @@ public ApplicationApiModel(Applications application) ApplicationUri = application.ApplicationUri; ApplicationName = application.ApplicationName; ProductUri = application.ProductUri; - ApplicationType = application.ApplicationType; + ApplicationType = (ApplicationType)application.ApplicationType; if(application.Certificate.Length > 0) Certificate = new X509CertificateApiModel(new X509Certificate2(application.Certificate)); } @@ -44,8 +45,22 @@ public ApplicationApiModel(Guid applicationId, string applicationUri, string app ApplicationId = applicationId; ApplicationUri = applicationUri; ApplicationName = applicationName; - ApplicationType = applicationType; + ApplicationType = (ApplicationType)applicationType; ProductUri = productUri; } } + /// + /// Type of the registered OPC UA Application + /// + public enum ApplicationType + { + [EnumMember(Value = "Server_0")] + Server, + [EnumMember(Value = "Client_1")] + Client, + [EnumMember(Value = "ClientAndServer_2")] + ClientAndServer, + [EnumMember(Value = "DiscoveryServer_3")] + DiscoveryServer + } } diff --git a/GDSwithREST/Data/Models/ApiModels/CertificateGroupApiModel.cs b/GDSwithREST/Data/Models/ApiModels/CertificateGroupApiModel.cs index 29a96e7..22fd149 100644 --- a/GDSwithREST/Data/Models/ApiModels/CertificateGroupApiModel.cs +++ b/GDSwithREST/Data/Models/ApiModels/CertificateGroupApiModel.cs @@ -3,6 +3,7 @@ using System.Security.Cryptography.X509Certificates; using System.Configuration; using GDSwithREST.Services.GdsBackgroundService.Databases; +using System.Runtime.Serialization; namespace GDSwithREST.Data.Models.ApiModels { @@ -15,7 +16,7 @@ public CertificateGroupApiModel(CertificateGroup certificateGroup) { try { - Id = (uint)certificateGroup.Id.Identifier; + Id = (CertificateGroupType)(uint)certificateGroup.Id.Identifier; UpdateRequired = certificateGroup.UpdateRequired; Ceritificate = new X509CertificateApiModel(certificateGroup.Certificate); } @@ -27,7 +28,7 @@ public CertificateGroupApiModel(uint id, X509Certificate2 certificate, bool upda { try { - Id = id; + Id = (CertificateGroupType)id; UpdateRequired = updateRequired; Ceritificate = new X509CertificateApiModel(certificate); } @@ -36,9 +37,21 @@ public CertificateGroupApiModel(uint id, X509Certificate2 certificate, bool upda } } - public uint Id { get; set; } + public CertificateGroupType Id { get; set; } public bool UpdateRequired { get; set; } - public X509CertificateApiModel? Ceritificate { get; set; } - + public X509CertificateApiModel? Ceritificate { get; set; } + } + + /// + /// Type of the Certificate Group + /// + public enum CertificateGroupType + { + [EnumMember(Value = "DefaultApplicationGroup_615")] + DefaultApplicationGroup = 615, + [EnumMember(Value = "DefaultHttpsGroup_649")] + DefaultHttpsGroup = 649, + [EnumMember(Value = "DefaultUserTokenGroup_683")] + DefaultUserTokenGroup = 683, } }