Skip to content

Commit 520f134

Browse files
committed
feat(handlers): Add Warnings array to IRemoteHandler interface for returning warning messages to job results.
1 parent 57271cb commit 520f134

File tree

5 files changed

+51
-5
lines changed

5 files changed

+51
-5
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
v2.11.4
2+
- Bug Fix: Handle condition where a certificate store definition that contains an invalid value for `FileTransferProtocol`
3+
would return empty inventory. If no value is set or an invalid value is set, the default value of `Both` will be used
4+
and a warning status will be returned for the job.
5+
6+
> [!IMPORTANT]
7+
> Due to an issue in Keyfactor Command versions through 25.2.1, when adding multiple choice store properties to exiting
8+
> certificate store types, existing certificate stores receive incorrect initialization data for the new property.
9+
> If you have upgraded your store type from something prior to version 2.10.0, ensure that each existing certificate
10+
> store has a valid value for `FileTransferProtocol`. Valid values are `SCP`, `SFTP`, `Both`, otherwise inventory jobs **may report
11+
> empty certificate store inventories**. Extension version 2.11.4 compensates for this, but upgrading customers should
12+
> check their store’s configuration for proper `FileTransferProtocol` values.
13+
114
v2.11.3
215
- Change returned result of a Management-Create job for a store that already exists from 'Failure' to 'Warning'
316

RemoteFile/InventoryBase.cs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
using System;
99
using System.Collections.Generic;
10+
using System.Linq;
1011
using System.Security.Cryptography.X509Certificates;
1112

1213
using Keyfactor.Orchestrators.Extensions;
@@ -73,7 +74,12 @@ public JobResult ProcessJob(InventoryJobConfiguration config, SubmitInventoryUpd
7374
catch (Exception ex)
7475
{
7576
logger.LogError($"Exception for {config.Capability}: {RemoteFileException.FlattenExceptionMessages(ex, string.Empty)} for job id {config.JobId}");
76-
return new JobResult() { Result = OrchestratorJobStatusJobResult.Failure, JobHistoryId = config.JobHistoryId, FailureMessage = RemoteFileException.FlattenExceptionMessages(ex, $"Site {config.CertificateStoreDetails.StorePath} on server {config.CertificateStoreDetails.ClientMachine}:") };
77+
return new JobResult
78+
{
79+
Result = OrchestratorJobStatusJobResult.Failure,
80+
JobHistoryId = config.JobHistoryId,
81+
FailureMessage = RemoteFileException.FlattenExceptionMessages(ex, $"Site {config.CertificateStoreDetails.StorePath} on server {config.CertificateStoreDetails.ClientMachine}:")
82+
};
7783
}
7884
finally
7985
{
@@ -84,14 +90,31 @@ public JobResult ProcessJob(InventoryJobConfiguration config, SubmitInventoryUpd
8490
try
8591
{
8692
submitInventory.Invoke(inventoryItems);
87-
logger.LogDebug($"...End {config.Capability} job for job id {config.JobId}");
88-
return new JobResult() { Result = OrchestratorJobStatusJobResult.Success, JobHistoryId = config.JobHistoryId };
93+
logger.LogDebug("...End {ConfigCapability} job for job id {ConfigJobId}", config.Capability, config.JobId);
94+
var jobResultStatus = OrchestratorJobStatusJobResult.Success;
95+
var jobMsg = string.Empty;
96+
if (certificateStore.RemoteHandler != null && certificateStore.RemoteHandler.Warnings.Length > 0)
97+
{
98+
jobResultStatus = OrchestratorJobStatusJobResult.Warning;
99+
jobMsg = certificateStore.RemoteHandler.Warnings.Aggregate(jobMsg, (current, warning) => current + (warning + Environment.NewLine));
100+
}
101+
return new JobResult
102+
{
103+
Result = jobResultStatus,
104+
JobHistoryId = config.JobHistoryId,
105+
FailureMessage = jobMsg
106+
};
89107
}
90108
catch (Exception ex)
91109
{
92110
string errorMessage = RemoteFileException.FlattenExceptionMessages(ex, string.Empty);
93111
logger.LogError($"Exception returning certificates for {config.Capability}: {errorMessage} for job id {config.JobId}");
94-
return new JobResult() { Result = OrchestratorJobStatusJobResult.Failure, JobHistoryId = config.JobHistoryId, FailureMessage = RemoteFileException.FlattenExceptionMessages(ex, $"Site {config.CertificateStoreDetails.StorePath} on server {config.CertificateStoreDetails.ClientMachine}:") };
112+
return new JobResult
113+
{
114+
Result = OrchestratorJobStatusJobResult.Failure,
115+
JobHistoryId = config.JobHistoryId,
116+
FailureMessage = RemoteFileException.FlattenExceptionMessages(ex, $"Site {config.CertificateStoreDetails.StorePath} on server {config.CertificateStoreDetails.ClientMachine}:")
117+
};
95118
}
96119
}
97120
}

RemoteFile/RemoteHandlers/BaseRemoteHandler.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
66
// and limitations under the License.
77

8+
using System;
89
using Keyfactor.Logging;
910

1011
using Microsoft.Extensions.Logging;
@@ -18,6 +19,8 @@ abstract class BaseRemoteHandler : IRemoteHandler
1819
internal const string PASSWORD_MASK_VALUE = "[PASSWORD]";
1920
internal const int PASSWORD_LENGTH_MAX = 100;
2021
internal const string LINUX_PERMISSION_REGEXP = "^[0-7]{3}$";
22+
23+
public string[] Warnings { get; set; } = Array.Empty<string>();
2124

2225
public string Server { get; set; }
2326

RemoteFile/RemoteHandlers/IRemoteHandler.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ namespace Keyfactor.Extensions.Orchestrator.RemoteFile.RemoteHandlers
1313
/// </summary>
1414
interface IRemoteHandler
1515
{
16+
17+
string [] Warnings { get; set; }
1618
void Terminate();
1719

1820
string RunCommand(string commandText, object[] arguments, bool withSudo, string[] passwordsToMaskInLog);

RemoteFile/RemoteHandlers/SSHHandler.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System;
99
using System.Collections.Generic;
1010
using System.IO;
11+
using System.Linq;
1112
using System.Security.Cryptography;
1213
using System.Text;
1314

@@ -334,7 +335,11 @@ public override byte[] DownloadCertificateFile(string path)
334335
if (!attemptedDownload)
335336
{
336337
FileTransferProtocol = ApplicationSettings.FileTransferProtocolEnum.Both;
337-
_logger.LogDebug($"No download attempted. Setting FileTransferProtocol to Both and retrying download.");
338+
var warningMsg = "No download attempted. Setting FileTransferProtocol to 'Both' and retrying download.";
339+
_logger.LogWarning(warningMsg);
340+
// append to Warnings global array
341+
Warnings = Warnings.Length == 0 ? new[] { warningMsg } : Warnings.Append(warningMsg).ToArray();
342+
338343
return DownloadCertificateFile(path);
339344
}
340345

0 commit comments

Comments
 (0)