-
Notifications
You must be signed in to change notification settings - Fork 5
Zd#144472 #85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Zd#144472 #85
Conversation
Merge 2.11.0 to main
Release 2.11.1
Release 2.11.2
Signed-off-by: Matthew H. Irby <matt.irby@outlook.com>
Signed-off-by: Matthew H. Irby <matt.irby@outlook.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR addresses a bug where invalid FileTransferProtocol values could result in empty certificate store inventory. The fix implements a fallback mechanism that defaults to 'Both' when invalid or problematic values are detected, and adds comprehensive logging and warning capabilities to track these scenarios.
- Implements a new
PropertyUtilitiesclass to detect flag combination parsing issues in enum values - Adds fallback logic to default
FileTransferProtocolto 'Both' when invalid values are detected - Introduces a warnings system to capture and report configuration issues through job results
Reviewed Changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| SSHHandler.cs | Adds retry logic and warnings collection for failed download attempts |
| IRemoteHandler.cs | Adds Warnings property to interface definition |
| BaseRemoteHandler.cs | Implements Warnings property with empty array initialization |
| RemoteFileJobTypeBase.cs | Enhanced logging and flag combination detection for FileTransferProtocol |
| RemoteCertificateStore.cs | Adds debug logging for certificate addition parameters |
| PropertyUtilities.cs | New utility class for detecting enum flag combination parsing issues |
| InventoryBase.cs | Integrates warnings into job results with Warning status |
| PEMCertificateStoreSerializer.cs | Adds debug logging for custom properties |
| ApplicationSettings.cs | Implements flag combination detection and fallback logic |
| Test files | Unit tests for new PropertyUtilities functionality |
| Documentation | Updates README and CHANGELOG with Store Password descriptions and bug fix notes |
| var warningMsg = "No download attempted. Setting FileTransferProtocol to 'Both' and retrying download."; | ||
| _logger.LogWarning(warningMsg); | ||
| // append to Warnings global array | ||
| Warnings = Warnings.Length == 0 ? new[] { warningMsg } : Warnings.Append(warningMsg).ToArray(); |
Copilot
AI
Jul 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentation is inconsistent with the surrounding code. This line should be aligned with the preceding lines in the same block.
| Warnings = Warnings.Length == 0 ? new[] { warningMsg } : Warnings.Append(warningMsg).ToArray(); | |
| Warnings = Warnings.Length == 0 ? new[] { warningMsg } : Warnings.Append(warningMsg).ToArray(); |
| FileTransferProtocol = ApplicationSettings.FileTransferProtocolEnum.Both; | ||
| var warningMsg = "No download attempted. Setting FileTransferProtocol to 'Both' and retrying download."; | ||
| _logger.LogWarning(warningMsg); | ||
| // append to Warnings global array | ||
| Warnings = Warnings.Length == 0 ? new[] { warningMsg } : Warnings.Append(warningMsg).ToArray(); | ||
|
|
||
| return DownloadCertificateFile(path); |
Copilot
AI
Jul 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition will trigger a recursive call if neither SCP nor SFTP protocols are attempted, but there's no guard against infinite recursion. If the FileTransferProtocol enum remains in an invalid state after being set to 'Both', this could cause a stack overflow.
| FileTransferProtocol = ApplicationSettings.FileTransferProtocolEnum.Both; | |
| var warningMsg = "No download attempted. Setting FileTransferProtocol to 'Both' and retrying download."; | |
| _logger.LogWarning(warningMsg); | |
| // append to Warnings global array | |
| Warnings = Warnings.Length == 0 ? new[] { warningMsg } : Warnings.Append(warningMsg).ToArray(); | |
| return DownloadCertificateFile(path); | |
| if (retryCount >= 3) | |
| { | |
| var errorMsg = "Retry limit reached. Unable to download the file."; | |
| _logger.LogError(errorMsg); | |
| throw new RemoteFileException(errorMsg); | |
| } | |
| FileTransferProtocol = ApplicationSettings.FileTransferProtocolEnum.Both; | |
| var warningMsg = "No download attempted. Setting FileTransferProtocol to 'Both' and retrying download."; | |
| _logger.LogWarning(warningMsg); | |
| // append to Warnings global array | |
| Warnings = Warnings.Length == 0 ? new[] { warningMsg } : Warnings.Append(warningMsg).ToArray(); | |
| return DownloadCertificateFile(path, retryCount + 1); |
| public static bool TryEnumParse<T>(string value, out bool isFlagCombination, out T result) where T : struct, Enum | ||
| { | ||
| isFlagCombination = false; | ||
| result = default(T); |
Copilot
AI
Jul 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Use default instead of default(T) for better readability and consistency with modern C# conventions.
| result = default(T); | |
| result = default; |
| if (certificateStore.RemoteHandler != null && certificateStore.RemoteHandler.Warnings.Length > 0) | ||
| { | ||
| jobResultStatus = OrchestratorJobStatusJobResult.Warning; | ||
| jobMsg = certificateStore.RemoteHandler.Warnings.Aggregate(jobMsg, (current, warning) => current + (warning + Environment.NewLine)); |
Copilot
AI
Jul 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String concatenation in a loop using Aggregate creates multiple intermediate string objects. Consider using string.Join(Environment.NewLine, certificateStore.RemoteHandler.Warnings) for better performance.
| jobMsg = certificateStore.RemoteHandler.Warnings.Aggregate(jobMsg, (current, warning) => current + (warning + Environment.NewLine)); | |
| jobMsg = string.Join(Environment.NewLine, certificateStore.RemoteHandler.Warnings); |
| string? protocolValue = configuration["FileTransferProtocol"]; | ||
|
|
||
| if (!Enum.TryParse(configuration["FileTransferProtocol"], out FileTransferProtocolEnum protocol)) | ||
| throw new RemoteFileException($"Invalid optional config.json FileTransferProtocol option of {configuration["FileTransferProtocol"]}. If present, must be one of these values: {protocolNames}."); | ||
| if (!PropertyUtilities.TryEnumParse(protocolValue, out bool isFlagCombination, out FileTransferProtocolEnum protocol)) | ||
| throw new RemoteFileException($"Invalid optional config.json FileTransferProtocol option of {protocolValue}. If present, must be one of these values: {protocolNames}."); | ||
|
|
||
| // Issue: If received a comma-delimited list ("SCP,SFTP,Both"), it's treating it as a flag combination (i.e. mapping it to 0+1+2=3) | ||
| // If this happens, we want to default it to Both so it's resolved as a valid mapping. | ||
| if (isFlagCombination) | ||
| { | ||
| logger.LogWarning($"FileTransferProtocol config value {protocolValue} mapped to a flag combination. Setting FileTransferProtocol explicitly to Both."); |
Copilot
AI
Jul 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The variable name protocolValue could be more descriptive. Consider renaming it to configProtocolValue to clearly indicate it comes from configuration.
| string? protocolValue = configuration["FileTransferProtocol"]; | |
| if (!Enum.TryParse(configuration["FileTransferProtocol"], out FileTransferProtocolEnum protocol)) | |
| throw new RemoteFileException($"Invalid optional config.json FileTransferProtocol option of {configuration["FileTransferProtocol"]}. If present, must be one of these values: {protocolNames}."); | |
| if (!PropertyUtilities.TryEnumParse(protocolValue, out bool isFlagCombination, out FileTransferProtocolEnum protocol)) | |
| throw new RemoteFileException($"Invalid optional config.json FileTransferProtocol option of {protocolValue}. If present, must be one of these values: {protocolNames}."); | |
| // Issue: If received a comma-delimited list ("SCP,SFTP,Both"), it's treating it as a flag combination (i.e. mapping it to 0+1+2=3) | |
| // If this happens, we want to default it to Both so it's resolved as a valid mapping. | |
| if (isFlagCombination) | |
| { | |
| logger.LogWarning($"FileTransferProtocol config value {protocolValue} mapped to a flag combination. Setting FileTransferProtocol explicitly to Both."); | |
| string? configProtocolValue = configuration["FileTransferProtocol"]; | |
| if (!PropertyUtilities.TryEnumParse(configProtocolValue, out bool isFlagCombination, out FileTransferProtocolEnum protocol)) | |
| throw new RemoteFileException($"Invalid optional config.json FileTransferProtocol option of {configProtocolValue}. If present, must be one of these values: {protocolNames}."); | |
| // Issue: If received a comma-delimited list ("SCP,SFTP,Both"), it's treating it as a flag combination (i.e. mapping it to 0+1+2=3) | |
| // If this happens, we want to default it to Both so it's resolved as a valid mapping. | |
| if (isFlagCombination) | |
| { | |
| logger.LogWarning($"FileTransferProtocol config value {configProtocolValue} mapped to a flag combination. Setting FileTransferProtocol explicitly to Both."); |
…r returning warning messages to job results.
No description provided.