Skip to content

Commit 5b66542

Browse files
leefine02leefine02
authored andcommitted
1 parent da527de commit 5b66542

File tree

11 files changed

+52
-224
lines changed

11 files changed

+52
-224
lines changed

RemoteFile.UnitTests/ApplicationSettingsTests.cs

Lines changed: 0 additions & 19 deletions
This file was deleted.

RemoteFile.UnitTests/PropertyUtilitiesTests.cs

Lines changed: 0 additions & 48 deletions
This file was deleted.

RemoteFile/ApplicationSettings.cs

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@ namespace Keyfactor.Extensions.Orchestrator.RemoteFile
1919
{
2020
public class ApplicationSettings
2121
{
22-
public enum FileTransferProtocolEnum
23-
{
24-
SCP,
25-
SFTP,
26-
Both
27-
}
28-
2922
private const string DEFAULT_LINUX_PERMISSION_SETTING = "";
3023
private const string DEFAULT_OWNER_SETTING = "";
3124
private const string DEFAULT_SUDO_IMPERSONATION_SETTING = "";
@@ -61,34 +54,6 @@ public static int SSHPort
6154
}
6255
}
6356
}
64-
public static FileTransferProtocolEnum FileTransferProtocol
65-
{
66-
get
67-
{
68-
ILogger logger = LogHandler.GetClassLogger<ApplicationSettings>();
69-
70-
string protocolNames = string.Empty;
71-
foreach (string protocolName in Enum.GetNames(typeof(FileTransferProtocolEnum)))
72-
{
73-
protocolNames += protocolName + ", ";
74-
}
75-
protocolNames = protocolNames.Substring(0, protocolNames.Length - 2);
76-
string? protocolValue = configuration["FileTransferProtocol"];
77-
78-
if (!PropertyUtilities.TryEnumParse(protocolValue, out bool isFlagCombination, out FileTransferProtocolEnum protocol))
79-
throw new RemoteFileException($"Invalid optional config.json FileTransferProtocol option of {protocolValue}. If present, must be one of these values: {protocolNames}.");
80-
81-
// 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)
82-
// If this happens, we want to default it to Both so it's resolved as a valid mapping.
83-
if (isFlagCombination)
84-
{
85-
logger.LogWarning($"FileTransferProtocol config value {protocolValue} mapped to a flag combination. Setting FileTransferProtocol explicitly to Both.");
86-
protocol = FileTransferProtocolEnum.Both;
87-
}
88-
89-
return protocol;
90-
}
91-
}
9257

9358
static ApplicationSettings()
9459
{
@@ -143,8 +108,6 @@ private static void ValidateConfiguration(ILogger logger)
143108
logger.LogDebug($"Missing configuration parameter - DefaultLinuxPermissionsOnStoreCreation. Will set to default value of '{DEFAULT_LINUX_PERMISSION_SETTING}'");
144109
if (!configuration.ContainsKey("DefaultOwnerOnStoreCreation"))
145110
logger.LogDebug($"Missing configuration parameter - DefaultOwnerOnStoreCreation. Will set to default value of '{DEFAULT_OWNER_SETTING}'");
146-
if (!configuration.ContainsKey("FileTransferProtocol"))
147-
logger.LogDebug($"Missing configuration parameter - FileTransferProtocol. Will set to default value of 'SCP'");
148111
}
149112

150113
private static string AddTrailingSlash(string path)

RemoteFile/InventoryBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public JobResult ProcessJob(InventoryJobConfiguration config, SubmitInventoryUpd
3939
{
4040
SetJobProperties(config, config.CertificateStoreDetails, logger);
4141

42-
certificateStore = new RemoteCertificateStore(config.CertificateStoreDetails.ClientMachine, UserName, UserPassword, config.CertificateStoreDetails.StorePath, StorePassword, FileTransferProtocol, SSHPort, IncludePortInSPN);
42+
certificateStore = new RemoteCertificateStore(config.CertificateStoreDetails.ClientMachine, UserName, UserPassword, config.CertificateStoreDetails.StorePath, StorePassword, SSHPort, IncludePortInSPN);
4343
certificateStore.Initialize(SudoImpersonatedUser, UseShellCommands);
4444
certificateStore.LoadCertificateStore(certificateStoreSerializer, true);
4545

RemoteFile/ManagementBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public JobResult ProcessJob(ManagementJobConfiguration config)
3535
{
3636
SetJobProperties(config, config.CertificateStoreDetails, logger);
3737

38-
certificateStore = new RemoteCertificateStore(config.CertificateStoreDetails.ClientMachine, UserName, UserPassword, config.CertificateStoreDetails.StorePath, StorePassword, FileTransferProtocol, SSHPort, IncludePortInSPN);
38+
certificateStore = new RemoteCertificateStore(config.CertificateStoreDetails.ClientMachine, UserName, UserPassword, config.CertificateStoreDetails.StorePath, StorePassword, SSHPort, IncludePortInSPN);
3939
certificateStore.Initialize(SudoImpersonatedUser, UseShellCommands);
4040

4141
PathFile storePathFile = RemoteCertificateStore.SplitStorePathFile(config.CertificateStoreDetails.StorePath);

RemoteFile/RemoteCertificateStore.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ internal enum ServerTypeEnum
5353
internal ServerTypeEnum ServerType { get; set; }
5454
internal List<string> DiscoveredStores { get; set; }
5555
internal string UploadFilePath { get; set; }
56-
internal ApplicationSettings.FileTransferProtocolEnum FileTransferProtocol { get; set; }
5756
internal bool IncludePortInSPN { get; set; }
5857
internal int SSHPort { get; set; }
5958

@@ -63,7 +62,7 @@ internal enum ServerTypeEnum
6362

6463
internal RemoteCertificateStore() { }
6564

66-
internal RemoteCertificateStore(string server, string serverId, string serverPassword, string storeFileAndPath, string storePassword, ApplicationSettings.FileTransferProtocolEnum fileTransferProtocol, int sshPort, bool includePortInSPN)
65+
internal RemoteCertificateStore(string server, string serverId, string serverPassword, string storeFileAndPath, string storePassword, int sshPort, bool includePortInSPN)
6766
{
6867
logger = LogHandler.GetClassLogger(this.GetType());
6968
logger.MethodEntry(LogLevel.Debug);
@@ -79,7 +78,6 @@ internal RemoteCertificateStore(string server, string serverId, string serverPas
7978
StorePassword = storePassword;
8079
ServerType = StorePath.Substring(0, 1) == "/" ? ServerTypeEnum.Linux : ServerTypeEnum.Windows;
8180
UploadFilePath = !string.IsNullOrEmpty(ApplicationSettings.SeparateUploadFilePath) && ServerType == ServerTypeEnum.Linux ? ApplicationSettings.SeparateUploadFilePath : StorePath;
82-
FileTransferProtocol = fileTransferProtocol;
8381
SSHPort = sshPort;
8482
IncludePortInSPN = includePortInSPN;
8583
logger.LogDebug($"UploadFilePath: {UploadFilePath}");
@@ -444,7 +442,7 @@ internal void Initialize(string sudoImpersonatedUser, bool useShellCommands)
444442
bool treatAsLocal = Server.ToLower().EndsWith(LOCAL_MACHINE_SUFFIX);
445443

446444
if (ServerType == ServerTypeEnum.Linux || RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
447-
RemoteHandler = treatAsLocal ? new LinuxLocalHandler() as IRemoteHandler : new SSHHandler(Server, ServerId, ServerPassword, ServerType == ServerTypeEnum.Linux, FileTransferProtocol, SSHPort, sudoImpersonatedUser, useShellCommands) as IRemoteHandler;
445+
RemoteHandler = treatAsLocal ? new LinuxLocalHandler() as IRemoteHandler : new SSHHandler(Server, ServerId, ServerPassword, ServerType == ServerTypeEnum.Linux, SSHPort, sudoImpersonatedUser, useShellCommands) as IRemoteHandler;
448446
else
449447
RemoteHandler = new WinRMHandler(Server, ServerId, ServerPassword, treatAsLocal, IncludePortInSPN);
450448

RemoteFile/RemoteFileJobTypeBase.cs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public abstract class RemoteFileJobTypeBase
2727
internal bool RemoveRootCertificate { get; set; }
2828
internal int SSHPort { get; set; }
2929
internal bool IncludePortInSPN { get; set; }
30-
internal ApplicationSettings.FileTransferProtocolEnum FileTransferProtocol { get; set; }
3130
internal bool CreateCSROnDevice { get; set; }
3231
internal bool UseShellCommands { get; set; }
3332
internal string KeyType { get; set; }
@@ -78,26 +77,6 @@ internal void SetJobProperties(JobConfiguration config, CertificateStore certifi
7877
ApplicationSettings.UseShellCommands :
7978
properties.UseShellCommands;
8079

81-
FileTransferProtocol = ApplicationSettings.FileTransferProtocol;
82-
if (properties.FileTransferProtocol != null && !string.IsNullOrEmpty(properties.FileTransferProtocol.Value))
83-
{
84-
logger.LogDebug($"Attempting to map file transfer protocol from properties. Current Value: {FileTransferProtocol}, Property Value: {properties.FileTransferProtocol.Value}");
85-
ApplicationSettings.FileTransferProtocolEnum fileTransferProtocol;
86-
if (PropertyUtilities.TryEnumParse(properties.FileTransferProtocol.Value, out bool isFlagCombination, out fileTransferProtocol))
87-
{
88-
logger.LogDebug($"Successfully mapped file transfer protocol from properties. Value: {fileTransferProtocol}");
89-
FileTransferProtocol = fileTransferProtocol;
90-
}
91-
92-
// 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)
93-
// If this happens, we want to default it to Both so it's resolved as a valid mapping.
94-
if (isFlagCombination)
95-
{
96-
logger.LogWarning($"FileTransferProtocol job property value {properties.FileTransferProtocol.Value} mapped to a flag combination. Setting FileTransferProtocol explicitly to Both.");
97-
FileTransferProtocol = ApplicationSettings.FileTransferProtocolEnum.Both;
98-
}
99-
}
100-
10180
if (config.JobProperties != null)
10281
{
10382
KeyType = !config.JobProperties.ContainsKey("keyType") || config.JobProperties["keyType"] == null || string.IsNullOrEmpty(config.JobProperties["keyType"].ToString()) ? string.Empty : config.JobProperties["keyType"].ToString();
@@ -113,7 +92,6 @@ internal void SetJobProperties(JobConfiguration config, CertificateStore certifi
11392
logger.LogDebug($"RemoveRootCertificate: {RemoveRootCertificate}");
11493
logger.LogDebug($"SSHPort: {SSHPort}");
11594
logger.LogDebug($"IncludePortInSPN: {IncludePortInSPN}");
116-
logger.LogDebug($"FileTransferProtocol: {FileTransferProtocol}");
11795
logger.LogDebug($"CreateCSROnDevice: {CreateCSROnDevice}");
11896
logger.LogDebug($"KeyType: {KeyType}");
11997
logger.LogDebug($"KeySize: {KeySize}");

0 commit comments

Comments
 (0)