diff --git a/GDSwithREST.Domain/Entities/Application.cs b/GDSwithREST.Domain/Entities/Application.cs index 2769efb..71a8359 100644 --- a/GDSwithREST.Domain/Entities/Application.cs +++ b/GDSwithREST.Domain/Entities/Application.cs @@ -18,11 +18,8 @@ public Application() public string ServerCapabilities { get; set; } = null!; public byte[] Certificate { get; set; } = Array.Empty(); public byte[]? HttpsCertificate { get; set; } - public int? TrustListId { get; set; } - public int? HttpsTrustListId { get; set; } - - public CertificateStore HttpsTrustList { get; set; } = null!; - public CertificateStore TrustList { get; set; } = null!; + public string? TrustListId { get; set; } + public string? HttpsTrustListId { get; set; } public ICollection ApplicationNames { get; set; } public ICollection CertificateRequests { get; set; } public ICollection ServerEndpoints { get; set; } diff --git a/GDSwithREST.Domain/Entities/CertificateStore.cs b/GDSwithREST.Domain/Entities/CertificateStore.cs deleted file mode 100644 index 08654f7..0000000 --- a/GDSwithREST.Domain/Entities/CertificateStore.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace GDSwithREST.Domain.Entities -{ - public sealed record CertificateStore - { - public CertificateStore() - { - ApplicationsHttpsTrustList = new HashSet(); - ApplicationsTrustList = new HashSet(); - } - - public int Id { get; set; } - public string Path { get; set; } = null!; - public string AuthorityId { get; set; } = null!; - - public ICollection ApplicationsHttpsTrustList { get; set; } - public ICollection ApplicationsTrustList { get; set; } - } -} diff --git a/GDSwithREST.Domain/GDSwithREST.Domain.csproj b/GDSwithREST.Domain/GDSwithREST.Domain.csproj index c07375d..a9fb9ba 100644 --- a/GDSwithREST.Domain/GDSwithREST.Domain.csproj +++ b/GDSwithREST.Domain/GDSwithREST.Domain.csproj @@ -1,14 +1,14 @@  - net7.0 + net8.0 enable enable - - + + diff --git a/GDSwithREST.Domain/Repositories/ICertificateStoreRepository.cs b/GDSwithREST.Domain/Repositories/ICertificateStoreRepository.cs deleted file mode 100644 index 73af144..0000000 --- a/GDSwithREST.Domain/Repositories/ICertificateStoreRepository.cs +++ /dev/null @@ -1,14 +0,0 @@ -using GDSwithREST.Domain.Entities; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace GDSwithREST.Domain.Repositories -{ - public interface ICertificateStoreRepository - { - public Task GetCertificateStoreByPath(string path); - } -} diff --git a/GDSwithREST.Domain/Services/ApplicationService.cs b/GDSwithREST.Domain/Services/ApplicationService.cs index 1d1755d..af974f2 100644 --- a/GDSwithREST.Domain/Services/ApplicationService.cs +++ b/GDSwithREST.Domain/Services/ApplicationService.cs @@ -577,43 +577,71 @@ public override bool GetApplicationCertificate( public override bool SetApplicationTrustLists( NodeId applicationId, - string trustListId, - string httpsTrustListId + string certificateTypeId, + string trustListId ) { using var scope = _serviceScopeFactory.CreateScope(); var applicationRepository = scope.ServiceProvider.GetRequiredService(); - var certificateStoreRepository = scope.ServiceProvider.GetRequiredService(); Guid id = GetNodeIdGuid(applicationId); var application = applicationRepository.GetApplicationById(id).Result; - if (application == null) + if (application == null || string.IsNullOrEmpty(trustListId)) { return false; } - application.TrustListId = null; - application.HttpsTrustListId = null; - if (trustListId != null) + if(certificateTypeId == nameof(Opc.Ua.ObjectTypeIds.ApplicationCertificateType)) + { + application.TrustListId = trustListId; + } + if(certificateTypeId == nameof(Opc.Ua.ObjectTypeIds.HttpsCertificateType)) { - var certificateStore = certificateStoreRepository.GetCertificateStoreByPath(httpsTrustListId); + application.HttpsTrustListId = trustListId; + } + + applicationRepository.SaveChanges(); - if (certificateStore != null) + return true; + } + + public override bool GetApplicationTrustLists( + NodeId applicationId, + string certificateTypeId, + out string trustListId + ) + { + trustListId = null!; + using var scope = _serviceScopeFactory.CreateScope(); + var applicationRepository = scope.ServiceProvider.GetRequiredService(); + + Guid id = GetNodeIdGuid(applicationId); + var application = applicationRepository.GetApplicationById(id).Result; + + if (application == null) + { + return false; + } + + if (certificateTypeId == nameof(Opc.Ua.ObjectTypeIds.ApplicationCertificateType)) + { + if(string.IsNullOrEmpty(application.TrustListId)) { - application.TrustListId = certificateStore.Id; + return false; } + trustListId = application.TrustListId; + return true; } - - if (httpsTrustListId != null) + if (certificateTypeId == nameof(Opc.Ua.ObjectTypeIds.HttpsCertificateType)) { - var certificateStore = certificateStoreRepository.GetCertificateStoreByPath(httpsTrustListId); - - if (certificateStore != null) + if (string.IsNullOrEmpty(application.HttpsTrustListId)) { - application.HttpsTrustListId = certificateStore.Id; + return false; } + trustListId = application.HttpsTrustListId; + return true; } applicationRepository.SaveChanges(); diff --git a/GDSwithREST.Domain/Services/CertificateGroupService.cs b/GDSwithREST.Domain/Services/CertificateGroupService.cs index b289673..55feaa8 100644 --- a/GDSwithREST.Domain/Services/CertificateGroupService.cs +++ b/GDSwithREST.Domain/Services/CertificateGroupService.cs @@ -1,5 +1,6 @@ using Opc.Ua; using Opc.Ua.Gds.Server; +using System.Runtime.InteropServices; using System.Security.Cryptography.X509Certificates; namespace GDSwithREST.Domain.Services @@ -10,9 +11,10 @@ public class CertificateGroupService : CertificateGroup, ICertificateGroupServic public override CertificateGroupService Create( string storePath, - CertificateGroupConfiguration certificateGroupConfiguration) + CertificateGroupConfiguration certificateGroupConfiguration, + [Optional] string trustedIssuerCertificatesStorePath) { - var cg = new CertificateGroupService(storePath, certificateGroupConfiguration); + var cg = new CertificateGroupService(storePath, certificateGroupConfiguration, trustedIssuerCertificatesStorePath); CertificateGroups.Add(cg); return cg; } @@ -21,10 +23,12 @@ public CertificateGroupService() : base() { } protected CertificateGroupService( string authoritiesStorePath, - CertificateGroupConfiguration certificateGroupConfiguration + CertificateGroupConfiguration certificateGroupConfiguration, + [Optional] string trustedIssuerCertificatesStorePath ) : base(authoritiesStorePath, - certificateGroupConfiguration) + certificateGroupConfiguration, + trustedIssuerCertificatesStorePath) { } public async Task GetTrustList() diff --git a/GDSwithREST.Domain/Services/GdsService.cs b/GDSwithREST.Domain/Services/GdsService.cs index 8856aa9..7a24531 100644 --- a/GDSwithREST.Domain/Services/GdsService.cs +++ b/GDSwithREST.Domain/Services/GdsService.cs @@ -3,8 +3,7 @@ using Opc.Ua.Configuration; using Opc.Ua.Gds.Server; using Opc.Ua.Gds.Server.Database; -using Opc.Ua.Gds.Server.Database.Linq; -using static Org.BouncyCastle.Math.EC.ECCurve; +using Opc.Ua.Server.UserDatabase; namespace GDSwithREST.Domain.Services { @@ -49,7 +48,7 @@ public async Task StartServer(CancellationToken stoppingToken) // get the DatabaseStorePath configuration parameter. GlobalDiscoveryServerConfiguration gdsConfiguration = _applicationInstance.ApplicationConfiguration.ParseExtension(); string usersDatabaseStorePath = Utils.ReplaceSpecialFolderNames(gdsConfiguration.UsersDatabaseStorePath); - var usersDatabase = JsonUsersDatabase.Load(usersDatabaseStorePath); + var usersDatabase = JsonUserDatabase.Load(usersDatabaseStorePath); //await _certificateGroup.Init(); var gdsServer = new GlobalDiscoverySampleServer( _applications, @@ -61,12 +60,12 @@ public async Task StartServer(CancellationToken stoppingToken) //start GDS await _applicationInstance.Start(gdsServer); - //trust GDS CA - var defaultCertificateGroup = _certificateGroups.CertificateGroups.SingleOrDefault(cg => cg.Id.Identifier is (uint)CertificateGroupType.DefaultApplicationGroup); - if (defaultCertificateGroup is null) - throw new Exception("Failed to initialze GDS CA Certifcate"); + ////trust GDS CA + //var defaultCertificateGroup = _certificateGroups.CertificateGroups.SingleOrDefault(cg => cg.Id.Identifier is (uint)CertificateGroupType.DefaultApplicationGroup); + //if (defaultCertificateGroup is null) + // throw new Exception("Failed to initialze GDS CA Certifcate"); - await _applicationInstance.AddOwnCertificateToTrustedStoreAsync(defaultCertificateGroup.Certificate, stoppingToken); + //await _applicationInstance.AddOwnCertificateToTrustedStoreAsync(defaultCertificateGroup.Certificate, stoppingToken); var endpoints = _applicationInstance.Server.GetEndpoints().Select(e => e.EndpointUrl).Distinct(); diff --git a/GDSwithREST.Infrastructure/GDSwithREST.Infrastructure.csproj b/GDSwithREST.Infrastructure/GDSwithREST.Infrastructure.csproj index e2fb0ed..fe7077d 100644 --- a/GDSwithREST.Infrastructure/GDSwithREST.Infrastructure.csproj +++ b/GDSwithREST.Infrastructure/GDSwithREST.Infrastructure.csproj @@ -1,21 +1,21 @@  - net7.0 + net8.0 enable enable - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + diff --git a/GDSwithREST.Infrastructure/GdsDbContext.cs b/GDSwithREST.Infrastructure/GdsDbContext.cs index dabe357..534dae9 100644 --- a/GDSwithREST.Infrastructure/GdsDbContext.cs +++ b/GDSwithREST.Infrastructure/GdsDbContext.cs @@ -20,7 +20,6 @@ public GdsDbContext(DbContextOptions options) public virtual DbSet ApplicationNames { get; set; } public virtual DbSet Applications { get; set; } public virtual DbSet CertificateRequests { get; set; } - public virtual DbSet CertificateStores { get; set; } public virtual DbSet ServerEndpoints { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) @@ -52,12 +51,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.Entity(entity => { - entity.HasIndex(e => e.HttpsTrustListId) - .HasDatabaseName("IX_FK_Applications_HttpsTrustListId"); - - entity.HasIndex(e => e.TrustListId) - .HasDatabaseName("IX_FK_Applications_TrustListId"); - entity.Property(e => e.HttpsTrustListId).IsRequired(false); entity.Property(e => e.TrustListId).IsRequired(false); @@ -78,17 +71,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) entity.Property(e => e.ServerCapabilities).HasMaxLength(500); - entity.HasOne(d => d.HttpsTrustList) - .WithMany(p => p.ApplicationsHttpsTrustList) - .HasForeignKey(d => d.HttpsTrustListId) - .HasConstraintName("FK_Applications_HttpsTrustListId") - .OnDelete(DeleteBehavior.ClientSetNull); - - entity.HasOne(d => d.TrustList) - .WithMany(p => p.ApplicationsTrustList) - .HasForeignKey(d => d.TrustListId) - .HasConstraintName("FK_Applications_TrustListId") - .OnDelete(DeleteBehavior.ClientSetNull); }); modelBuilder.Entity(entity => @@ -122,19 +104,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasConstraintName("FK_CertificateRequests_Applications"); }); - modelBuilder.Entity(entity => - { - entity.Property(e => e.Id).HasColumnName("ID"); - - entity.Property(e => e.AuthorityId) - .HasMaxLength(50) - .IsRequired(false); - - entity.Property(e => e.Path) - .IsRequired() - .HasMaxLength(256); - }); - modelBuilder.Entity(entity => { entity.HasIndex(e => e.ApplicationId) diff --git a/GDSwithREST.Infrastructure/Migrations/20240302183210_TrustlistUpdate.Designer.cs b/GDSwithREST.Infrastructure/Migrations/20240302183210_TrustlistUpdate.Designer.cs new file mode 100644 index 0000000..b89dac7 --- /dev/null +++ b/GDSwithREST.Infrastructure/Migrations/20240302183210_TrustlistUpdate.Designer.cs @@ -0,0 +1,238 @@ +// +using System; +using GDSwithREST.Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace GDSwithREST.Infrastructure.Migrations +{ + [DbContext(typeof(GdsDbContext))] + [Migration("20240302183210_TrustlistUpdate")] + partial class TrustlistUpdate + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.2") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("GDSwithREST.Domain.Entities.Application", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ID"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ApplicationId") + .HasColumnType("uniqueidentifier"); + + b.Property("ApplicationName") + .IsRequired() + .HasMaxLength(1000) + .HasColumnType("nvarchar(1000)"); + + b.Property("ApplicationType") + .HasColumnType("int"); + + b.Property("ApplicationUri") + .IsRequired() + .HasMaxLength(1000) + .HasColumnType("nvarchar(1000)"); + + b.Property("Certificate") + .IsRequired() + .HasColumnType("varbinary(max)"); + + b.Property("HttpsCertificate") + .HasColumnType("varbinary(max)"); + + b.Property("HttpsTrustListId") + .HasColumnType("nvarchar(max)"); + + b.Property("ProductUri") + .IsRequired() + .HasMaxLength(1000) + .HasColumnType("nvarchar(1000)"); + + b.Property("ServerCapabilities") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("TrustListId") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Applications"); + }); + + modelBuilder.Entity("GDSwithREST.Domain.Entities.ApplicationName", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ID"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ApplicationId") + .HasColumnType("int"); + + b.Property("Locale") + .HasMaxLength(10) + .HasColumnType("nvarchar(10)"); + + b.Property("Text") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.HasKey("Id"); + + b.HasIndex("ApplicationId") + .HasDatabaseName("IX_FK_ApplicationNames_ApplicationId"); + + b.ToTable("ApplicationNames"); + }); + + modelBuilder.Entity("GDSwithREST.Domain.Entities.CertificateRequest", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ID"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ApplicationId") + .HasColumnType("int"); + + b.Property("AuthorityId") + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("CertificateGroupId") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("CertificateSigningRequest") + .HasColumnType("varbinary(max)"); + + b.Property("CertificateTypeId") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("DomainNames") + .HasColumnType("nvarchar(max)"); + + b.Property("PrivateKeyFormat") + .HasMaxLength(3) + .HasColumnType("nvarchar(3)"); + + b.Property("PrivateKeyPassword") + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("RequestId") + .HasColumnType("uniqueidentifier"); + + b.Property("State") + .HasColumnType("int"); + + b.Property("SubjectName") + .HasMaxLength(1000) + .HasColumnType("nvarchar(1000)"); + + b.HasKey("Id"); + + b.HasIndex("ApplicationId") + .HasDatabaseName("IX_FK_CertificateRequests_Applications"); + + b.ToTable("CertificateRequests"); + }); + + modelBuilder.Entity("GDSwithREST.Domain.Entities.ServerEndpoint", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ID"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ApplicationId") + .HasColumnType("int"); + + b.Property("DiscoveryUrl") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.HasKey("Id"); + + b.HasIndex("ApplicationId") + .HasDatabaseName("IX_FK_ServerEndpoints_ApplicationId"); + + b.ToTable("ServerEndpoints"); + }); + + modelBuilder.Entity("GDSwithREST.Domain.Entities.ApplicationName", b => + { + b.HasOne("GDSwithREST.Domain.Entities.Application", "Application") + .WithMany("ApplicationNames") + .HasForeignKey("ApplicationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("FK_ApplicationNames_ApplicationId"); + + b.Navigation("Application"); + }); + + modelBuilder.Entity("GDSwithREST.Domain.Entities.CertificateRequest", b => + { + b.HasOne("GDSwithREST.Domain.Entities.Application", "Application") + .WithMany("CertificateRequests") + .HasForeignKey("ApplicationId") + .HasConstraintName("FK_CertificateRequests_Applications"); + + b.Navigation("Application"); + }); + + modelBuilder.Entity("GDSwithREST.Domain.Entities.ServerEndpoint", b => + { + b.HasOne("GDSwithREST.Domain.Entities.Application", "Application") + .WithMany("ServerEndpoints") + .HasForeignKey("ApplicationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("FK_ServerEndpoints_ApplicationId"); + + b.Navigation("Application"); + }); + + modelBuilder.Entity("GDSwithREST.Domain.Entities.Application", b => + { + b.Navigation("ApplicationNames"); + + b.Navigation("CertificateRequests"); + + b.Navigation("ServerEndpoints"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/GDSwithREST.Infrastructure/Migrations/20240302183210_TrustlistUpdate.cs b/GDSwithREST.Infrastructure/Migrations/20240302183210_TrustlistUpdate.cs new file mode 100644 index 0000000..2768494 --- /dev/null +++ b/GDSwithREST.Infrastructure/Migrations/20240302183210_TrustlistUpdate.cs @@ -0,0 +1,152 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace GDSwithREST.Infrastructure.Migrations +{ + /// + public partial class TrustlistUpdate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Applications_HttpsTrustListId", + table: "Applications"); + + migrationBuilder.DropForeignKey( + name: "FK_Applications_TrustListId", + table: "Applications"); + + migrationBuilder.DropForeignKey( + name: "FK_CertificateRequests_Applications", + table: "CertificateRequests"); + + migrationBuilder.DropTable( + name: "CertificateStores"); + + migrationBuilder.DropIndex( + name: "IX_FK_Applications_HttpsTrustListId", + table: "Applications"); + + migrationBuilder.DropIndex( + name: "IX_FK_Applications_TrustListId", + table: "Applications"); + + migrationBuilder.AlterColumn( + name: "ApplicationId", + table: "CertificateRequests", + type: "int", + nullable: true, + oldClrType: typeof(int), + oldType: "int"); + + migrationBuilder.AlterColumn( + name: "TrustListId", + table: "Applications", + type: "nvarchar(max)", + nullable: true, + oldClrType: typeof(int), + oldType: "int", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "HttpsTrustListId", + table: "Applications", + type: "nvarchar(max)", + nullable: true, + oldClrType: typeof(int), + oldType: "int", + oldNullable: true); + + migrationBuilder.AddForeignKey( + name: "FK_CertificateRequests_Applications", + table: "CertificateRequests", + column: "ApplicationId", + principalTable: "Applications", + principalColumn: "ID"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_CertificateRequests_Applications", + table: "CertificateRequests"); + + migrationBuilder.AlterColumn( + name: "ApplicationId", + table: "CertificateRequests", + type: "int", + nullable: false, + defaultValue: 0, + oldClrType: typeof(int), + oldType: "int", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "TrustListId", + table: "Applications", + type: "int", + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(max)", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "HttpsTrustListId", + table: "Applications", + type: "int", + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(max)", + oldNullable: true); + + migrationBuilder.CreateTable( + name: "CertificateStores", + columns: table => new + { + ID = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + AuthorityId = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: true), + Path = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CertificateStores", x => x.ID); + }); + + migrationBuilder.CreateIndex( + name: "IX_FK_Applications_HttpsTrustListId", + table: "Applications", + column: "HttpsTrustListId"); + + migrationBuilder.CreateIndex( + name: "IX_FK_Applications_TrustListId", + table: "Applications", + column: "TrustListId"); + + migrationBuilder.AddForeignKey( + name: "FK_Applications_HttpsTrustListId", + table: "Applications", + column: "HttpsTrustListId", + principalTable: "CertificateStores", + principalColumn: "ID"); + + migrationBuilder.AddForeignKey( + name: "FK_Applications_TrustListId", + table: "Applications", + column: "TrustListId", + principalTable: "CertificateStores", + principalColumn: "ID"); + + migrationBuilder.AddForeignKey( + name: "FK_CertificateRequests_Applications", + table: "CertificateRequests", + column: "ApplicationId", + principalTable: "Applications", + principalColumn: "ID", + onDelete: ReferentialAction.Cascade); + } + } +} diff --git a/GDSwithREST.Infrastructure/Migrations/GdsDbContextModelSnapshot.cs b/GDSwithREST.Infrastructure/Migrations/GdsDbContextModelSnapshot.cs index 104229a..2765930 100644 --- a/GDSwithREST.Infrastructure/Migrations/GdsDbContextModelSnapshot.cs +++ b/GDSwithREST.Infrastructure/Migrations/GdsDbContextModelSnapshot.cs @@ -17,7 +17,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "7.0.14") + .HasAnnotation("ProductVersion", "8.0.2") .HasAnnotation("Relational:MaxIdentifierLength", 128); SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); @@ -54,8 +54,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("HttpsCertificate") .HasColumnType("varbinary(max)"); - b.Property("HttpsTrustListId") - .HasColumnType("int"); + b.Property("HttpsTrustListId") + .HasColumnType("nvarchar(max)"); b.Property("ProductUri") .IsRequired() @@ -67,17 +67,11 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasMaxLength(500) .HasColumnType("nvarchar(500)"); - b.Property("TrustListId") - .HasColumnType("int"); + b.Property("TrustListId") + .HasColumnType("nvarchar(max)"); b.HasKey("Id"); - b.HasIndex("HttpsTrustListId") - .HasDatabaseName("IX_FK_Applications_HttpsTrustListId"); - - b.HasIndex("TrustListId") - .HasDatabaseName("IX_FK_Applications_TrustListId"); - b.ToTable("Applications"); }); @@ -120,7 +114,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("ApplicationId") - .IsRequired() .HasColumnType("int"); b.Property("AuthorityId") @@ -169,29 +162,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("CertificateRequests"); }); - modelBuilder.Entity("GDSwithREST.Domain.Entities.CertificateStore", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasColumnName("ID"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("AuthorityId") - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.Property("Path") - .IsRequired() - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.HasKey("Id"); - - b.ToTable("CertificateStores"); - }); - modelBuilder.Entity("GDSwithREST.Domain.Entities.ServerEndpoint", b => { b.Property("Id") @@ -217,25 +187,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("ServerEndpoints"); }); - modelBuilder.Entity("GDSwithREST.Domain.Entities.Application", b => - { - b.HasOne("GDSwithREST.Domain.Entities.CertificateStore", "HttpsTrustList") - .WithMany("ApplicationsHttpsTrustList") - .HasForeignKey("HttpsTrustListId") - .IsRequired() - .HasConstraintName("FK_Applications_HttpsTrustListId"); - - b.HasOne("GDSwithREST.Domain.Entities.CertificateStore", "TrustList") - .WithMany("ApplicationsTrustList") - .HasForeignKey("TrustListId") - .IsRequired() - .HasConstraintName("FK_Applications_TrustListId"); - - b.Navigation("HttpsTrustList"); - - b.Navigation("TrustList"); - }); - modelBuilder.Entity("GDSwithREST.Domain.Entities.ApplicationName", b => { b.HasOne("GDSwithREST.Domain.Entities.Application", "Application") @@ -253,8 +204,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasOne("GDSwithREST.Domain.Entities.Application", "Application") .WithMany("CertificateRequests") .HasForeignKey("ApplicationId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired() .HasConstraintName("FK_CertificateRequests_Applications"); b.Navigation("Application"); @@ -280,13 +229,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Navigation("ServerEndpoints"); }); - - modelBuilder.Entity("GDSwithREST.Domain.Entities.CertificateStore", b => - { - b.Navigation("ApplicationsHttpsTrustList"); - - b.Navigation("ApplicationsTrustList"); - }); #pragma warning restore 612, 618 } } diff --git a/GDSwithREST.Infrastructure/Repositories/CertificateStoreRepository.cs b/GDSwithREST.Infrastructure/Repositories/CertificateStoreRepository.cs deleted file mode 100644 index 4924e88..0000000 --- a/GDSwithREST.Infrastructure/Repositories/CertificateStoreRepository.cs +++ /dev/null @@ -1,24 +0,0 @@ -using GDSwithREST.Domain.Entities; -using GDSwithREST.Infrastructure; -using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace GDSwithREST.Domain.Repositories -{ - public class CertificateStoreRepository:ICertificateStoreRepository - { - private readonly GdsDbContext _context; - public CertificateStoreRepository(GdsDbContext context) - { - _context = context; - } - public async Task GetCertificateStoreByPath(string path) - { - return await _context.CertificateStores.SingleOrDefaultAsync(x => x.Path == path); - } - } -} diff --git a/GDSwithREST/Dockerfile b/GDSwithREST/Dockerfile index 1ebfca7..5aafa20 100644 --- a/GDSwithREST/Dockerfile +++ b/GDSwithREST/Dockerfile @@ -1,17 +1,19 @@ #See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging. -FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base WORKDIR /app COPY ["GDSwithREST/GdsConfig", "/OPC Foundation/GDS/config"] COPY ["GDSwithREST/HTTPSCert", "/OPC Foundation/HTTPSCert"] EXPOSE 8080 EXPOSE 8081 EXPOSE 58810 -RUN apt-get update -RUN apt-get --yes install curl +USER root +RUN apt-get update && apt-get install -y curl --fix-missing +# Switch back to the desired user (e.g., jovyan) +USER $NB_UID HEALTHCHECK --interval=5s --timeout=10s --retries=3 CMD curl --silent --fail https://localhost:8081/hc -k || exit 1 -FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build WORKDIR /src COPY ["GDSwithREST/GDSwithREST.csproj", "GDSwithREST/"] RUN dotnet restore "GDSwithREST/GDSwithREST.csproj" diff --git a/GDSwithREST/GDSwithREST.csproj b/GDSwithREST/GDSwithREST.csproj index 1c8e6e9..e89b4be 100644 --- a/GDSwithREST/GDSwithREST.csproj +++ b/GDSwithREST/GDSwithREST.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 enable enable 6914888c-64ea-485e-88e3-f8da36bfff21 @@ -28,8 +28,12 @@ - - + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + diff --git a/GDSwithREST/Program.cs b/GDSwithREST/Program.cs index 1ae9e72..a4cbb05 100644 --- a/GDSwithREST/Program.cs +++ b/GDSwithREST/Program.cs @@ -16,7 +16,6 @@ builder.Configuration.GetConnectionString("Default"))); builder.Services.AddScoped(); builder.Services.AddScoped(); -builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); @@ -53,7 +52,7 @@ app.UseOpenApi(); //GET: /swagger -app.UseSwaggerUi3(); +app.UseSwaggerUi(); //Map Endpoints app.MapControllers(); diff --git a/GDSwithRest.IntegrationTests/GDSwithRest.IntegrationTests.csproj b/GDSwithRest.IntegrationTests/GDSwithRest.IntegrationTests.csproj index 80b2e9a..567df7a 100644 --- a/GDSwithRest.IntegrationTests/GDSwithRest.IntegrationTests.csproj +++ b/GDSwithRest.IntegrationTests/GDSwithRest.IntegrationTests.csproj @@ -1,7 +1,7 @@ - net7.0 + net8.0 enable enable @@ -10,16 +10,16 @@ - + - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/GDSwithRest.Tests/GDSwithRest.Tests.csproj b/GDSwithRest.Tests/GDSwithRest.Tests.csproj index d90f98f..113e8d5 100644 --- a/GDSwithRest.Tests/GDSwithRest.Tests.csproj +++ b/GDSwithRest.Tests/GDSwithRest.Tests.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 enable enable @@ -11,13 +11,13 @@ - - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all