From 8054ba94f884adf9e4ffd1ce1d0ebb175f4f12bc Mon Sep 17 00:00:00 2001 From: Matt Richardson Date: Mon, 15 Jun 2026 16:45:55 +1000 Subject: [PATCH] Fix CS9124: avoid double-storing primary-constructor log parameter KubernetesDiscovererBase captured the 'log' primary-constructor parameter (via LogDeserialisationError) while also storing it in an explicit 'protected readonly ILog Log' field, so the value was held twice (CS9124). Remove the redundant base field; the base now relies on the captured parameter. AwsKubernetesDiscoverer keeps its own 'readonly ILog log = log' field and uses it for TryGetCredentials, with the remaining Log.Verbose calls binding to the static logger. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../Kubernetes/Discovery/AwsKubernetesDiscoverer.cs | 6 ++++-- .../Features/Discovery/KubernetesDiscovererBase.cs | 6 +----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/source/Calamari.Aws/Kubernetes/Discovery/AwsKubernetesDiscoverer.cs b/source/Calamari.Aws/Kubernetes/Discovery/AwsKubernetesDiscoverer.cs index 82a0e5f63..80ef8ec56 100644 --- a/source/Calamari.Aws/Kubernetes/Discovery/AwsKubernetesDiscoverer.cs +++ b/source/Calamari.Aws/Kubernetes/Discovery/AwsKubernetesDiscoverer.cs @@ -14,6 +14,8 @@ namespace Calamari.Aws.Kubernetes.Discovery; public class AwsKubernetesDiscoverer(ILog log) : KubernetesDiscovererBase(log) { + readonly ILog log = log; + /// /// This type value here must be the same as in Octopus.Server.Orchestration.ServerTasks.Deploy.TargetDiscovery.AwsAuthenticationContext /// This value is hardcoded because: @@ -58,7 +60,7 @@ public override IEnumerable DiscoverClusters(string contextJs Log.Verbose(" Role: No IAM Role provided."); } - if (!authenticationDetails.TryGetCredentials(Log, out var credentials)) + if (!authenticationDetails.TryGetCredentials(log, out var credentials)) yield break; foreach (var region in authenticationDetails.Regions) @@ -174,4 +176,4 @@ bool TryGetAwsAuthenticationDetails( return true; } -} \ No newline at end of file +} diff --git a/source/Calamari.Common/Features/Discovery/KubernetesDiscovererBase.cs b/source/Calamari.Common/Features/Discovery/KubernetesDiscovererBase.cs index dbd21942c..39b057107 100644 --- a/source/Calamari.Common/Features/Discovery/KubernetesDiscovererBase.cs +++ b/source/Calamari.Common/Features/Discovery/KubernetesDiscovererBase.cs @@ -9,10 +9,6 @@ namespace Calamari.Common.Features.Discovery; public abstract class KubernetesDiscovererBase(ILog log) : IKubernetesDiscoverer { - protected readonly ILog Log = log; - - - protected bool TryGetDiscoveryContext(string json, [NotNullWhen(returnValue: true)] out TAuthenticationDetails? authenticationDetails, out string? workerPoolId) where TAuthenticationDetails : class, ITargetDiscoveryAuthenticationDetails @@ -63,4 +59,4 @@ void LogDeserialisationError(string? detail = null, Exception? exception = null) public abstract string Type { get; } public abstract IEnumerable DiscoverClusters(string contextJson); -} \ No newline at end of file +}