diff --git a/src/Tgstation.Server.Host/Components/Interop/Bridge/BridgeParameters.cs b/src/Tgstation.Server.Host/Components/Interop/Bridge/BridgeParameters.cs index e633a4c240..1240bc81cb 100644 --- a/src/Tgstation.Server.Host/Components/Interop/Bridge/BridgeParameters.cs +++ b/src/Tgstation.Server.Host/Components/Interop/Bridge/BridgeParameters.cs @@ -50,5 +50,14 @@ namespace Tgstation.Server.Host.Components.Interop.Bridge /// The port that should be used to send world topics, if not the default. /// public ushort? TopicPort { get; set; } + + /// + /// Initializes a new instance of the class. + /// + /// The access identifier for the . + public BridgeParameters(string accessIdentifier) + : base(accessIdentifier) + { + } } } diff --git a/src/Tgstation.Server.Host/Components/Interop/DMApiParameters.cs b/src/Tgstation.Server.Host/Components/Interop/DMApiParameters.cs index 2a31c9efbc..64b774aeb5 100644 --- a/src/Tgstation.Server.Host/Components/Interop/DMApiParameters.cs +++ b/src/Tgstation.Server.Host/Components/Interop/DMApiParameters.cs @@ -1,4 +1,5 @@ -using System.ComponentModel.DataAnnotations; +using System; +using System.ComponentModel.DataAnnotations; namespace Tgstation.Server.Host.Components.Interop { @@ -11,6 +12,24 @@ namespace Tgstation.Server.Host.Components.Interop /// Used to identify and authenticate the DreamDaemon instance. /// [Required] - public string? AccessIdentifier { get; set; } + public string AccessIdentifier { get; set; } + + /// + /// Initializes a new instance of the class. + /// + /// The value of . + public DMApiParameters(string accessIdentifier) + { + AccessIdentifier = accessIdentifier ?? throw new ArgumentNullException(nameof(accessIdentifier)); + } + + /// + /// Initializes a new instance of the class. + /// + /// For use by EFCore only. + protected DMApiParameters() + { + AccessIdentifier = null!; + } } } diff --git a/src/Tgstation.Server.Host/Components/Interop/Topic/TopicParameters.cs b/src/Tgstation.Server.Host/Components/Interop/Topic/TopicParameters.cs index f84a404289..bdc8405b02 100644 --- a/src/Tgstation.Server.Host/Components/Interop/Topic/TopicParameters.cs +++ b/src/Tgstation.Server.Host/Components/Interop/Topic/TopicParameters.cs @@ -188,6 +188,7 @@ namespace Tgstation.Server.Host.Components.Interop.Topic /// /// The value of . protected TopicParameters(TopicCommandType commandType) + : base(String.Empty) // access identifier gets set before send { CommandType = commandType; } diff --git a/src/Tgstation.Server.Host/Components/Session/ReattachInformation.cs b/src/Tgstation.Server.Host/Components/Session/ReattachInformation.cs index 3ddeff51d7..31aa0834b7 100644 --- a/src/Tgstation.Server.Host/Components/Session/ReattachInformation.cs +++ b/src/Tgstation.Server.Host/Components/Session/ReattachInformation.cs @@ -74,13 +74,12 @@ namespace Tgstation.Server.Host.Components.Session RuntimeInformation runtimeInformation, string accessIdentifier, ushort port) + : base(accessIdentifier) { Dmb = dmb ?? throw new ArgumentNullException(nameof(dmb)); ProcessId = process?.Id ?? throw new ArgumentNullException(nameof(process)); RuntimeInformation = runtimeInformation ?? throw new ArgumentNullException(nameof(runtimeInformation)); - AccessIdentifier = accessIdentifier ?? throw new ArgumentNullException(nameof(accessIdentifier)); - LaunchSecurityLevel = runtimeInformation.SecurityLevel; LaunchVisibility = runtimeInformation.Visibility; Port = port; diff --git a/src/Tgstation.Server.Host/Components/Session/SessionPersistor.cs b/src/Tgstation.Server.Host/Components/Session/SessionPersistor.cs index 7eebd9a2af..2cd093c3ee 100644 --- a/src/Tgstation.Server.Host/Components/Session/SessionPersistor.cs +++ b/src/Tgstation.Server.Host/Components/Session/SessionPersistor.cs @@ -75,9 +75,8 @@ namespace Tgstation.Server.Host.Components.Session await ClearImpl(db, false, cancellationToken); - var dbReattachInfo = new Models.ReattachInformation + var dbReattachInfo = new Models.ReattachInformation(reattachInformation.AccessIdentifier) { - AccessIdentifier = reattachInformation.AccessIdentifier, CompileJobId = reattachInformation.Dmb.CompileJob.Id.Value, InitialCompileJobId = reattachInformation.InitialDmb?.CompileJob.Id.Value, Port = reattachInformation.Port, @@ -103,7 +102,7 @@ namespace Tgstation.Server.Host.Components.Session logger.LogTrace("Updating reattach information: {info}...", reattachInformation); - var dbReattachInfo = new Models.ReattachInformation + var dbReattachInfo = new Models.ReattachInformation(String.Empty) { Id = reattachInformation.Id.Value, }; diff --git a/src/Tgstation.Server.Host/Controllers/BridgeController.cs b/src/Tgstation.Server.Host/Controllers/BridgeController.cs index c4d33be706..4b1a1fac3e 100644 --- a/src/Tgstation.Server.Host/Controllers/BridgeController.cs +++ b/src/Tgstation.Server.Host/Controllers/BridgeController.cs @@ -97,10 +97,10 @@ namespace Tgstation.Server.Host.Controllers using (LogContext.PushProperty(SerilogContextHelper.BridgeRequestIterationContextProperty, Interlocked.Increment(ref requestsProcessed))) { - var request = new BridgeParameters(); + BridgeParameters? request; try { - JsonConvert.PopulateObject(data, request, DMApiConstants.SerializerSettings); + request = JsonConvert.DeserializeObject(data, DMApiConstants.SerializerSettings); } catch (Exception ex) { diff --git a/src/Tgstation.Server.Host/Models/ReattachInformation.cs b/src/Tgstation.Server.Host/Models/ReattachInformation.cs index 9454e4acf6..49360cf3e5 100644 --- a/src/Tgstation.Server.Host/Models/ReattachInformation.cs +++ b/src/Tgstation.Server.Host/Models/ReattachInformation.cs @@ -1,4 +1,5 @@ -using System.ComponentModel.DataAnnotations; +using System; +using System.ComponentModel.DataAnnotations; namespace Tgstation.Server.Host.Models { @@ -27,5 +28,22 @@ namespace Tgstation.Server.Host.Models /// The of . /// public long? InitialCompileJobId { get; set; } + + /// + /// Initializes a new instance of the class. + /// + [Obsolete("For use by EFCore only", true)] + public ReattachInformation() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The access identifier for the . + public ReattachInformation(string accessIdentifier) + : base(accessIdentifier) + { + } } } diff --git a/src/Tgstation.Server.Host/Models/ReattachInformationBase.cs b/src/Tgstation.Server.Host/Models/ReattachInformationBase.cs index 3d3d4411cb..fc6d07a8f3 100644 --- a/src/Tgstation.Server.Host/Models/ReattachInformationBase.cs +++ b/src/Tgstation.Server.Host/Models/ReattachInformationBase.cs @@ -49,19 +49,30 @@ namespace Tgstation.Server.Host.Models /// /// Initializes a new instance of the class. /// + /// For use by EFCore only. protected ReattachInformationBase() { } + /// + /// Initializes a new instance of the class. + /// + /// The access identifier for the . + protected ReattachInformationBase(string accessIdentifier) + : base(accessIdentifier) + { + } + /// /// Initializes a new instance of the class. /// /// The to copy values from. protected ReattachInformationBase(ReattachInformationBase copy) + : base(copy == null + ? throw new ArgumentNullException(nameof(copy)) + : copy.AccessIdentifier) { - ArgumentNullException.ThrowIfNull(copy); Id = copy.Id; - AccessIdentifier = copy.AccessIdentifier; Port = copy.Port; TopicPort = copy.TopicPort; ProcessId = copy.ProcessId; diff --git a/tests/Tgstation.Server.Tests/Live/Instance/TestBridgeHandler.cs b/tests/Tgstation.Server.Tests/Live/Instance/TestBridgeHandler.cs index 4276067b19..e00421e295 100644 --- a/tests/Tgstation.Server.Tests/Live/Instance/TestBridgeHandler.cs +++ b/tests/Tgstation.Server.Tests/Live/Instance/TestBridgeHandler.cs @@ -15,17 +15,20 @@ namespace Tgstation.Server.Tests.Live.Instance { sealed class TestBridgeHandler : Chunker, IBridgeHandler { - class DMApiParametersImpl : DMApiParameters { } + class DMApiParametersImpl : DMApiParameters + { + public DMApiParametersImpl(string accessIdentifier) + : base(accessIdentifier) + { + } + } class BridgeResponseHack : BridgeResponse { public string IntegrationHack { get; set; } } - public DMApiParameters DMApiParameters => new DMApiParametersImpl - { - AccessIdentifier = accessIdentifier - }; + public DMApiParameters DMApiParameters => new DMApiParametersImpl(accessIdentifier); long lastBridgeRequestSize = 0;