This commit is contained in:
Zeeshaun
2026-03-24 15:28:37 -05:00
parent 9cc87337b8
commit 73d62efb39
58 changed files with 2952 additions and 0 deletions
@@ -0,0 +1,17 @@
using LCU.Api.Internal.FTPLib.Models.Enums;
using LCU.Api.Internal.FTPLib.Models;
namespace LCU.Api.Internal.FTP.Helpers;
public class FtpRequestResponseHelper
{
public static FtpRequestResponse ExceptionUpdateRequestResponse(FtpRequestResponse requestResponse,
FtpType ftpType,
string exception)
{
requestResponse.IsSuccessful = false;
requestResponse.MessageStack.Add($"Failure to execute ftp action. " +
$"FtpType: {ftpType}, " +
$"Exception: {exception} ");
return requestResponse;
}
}
@@ -0,0 +1,30 @@
using System;
using LCU.Api.Internal.FTPLib.Models;
namespace LCU.Api.Internal.FTP.Helpers;
[Obsolete("01/04/2022 - After the SftpController endpoints are no longer using this validation it can be removed. The model validation covers validation enough.")]
public static class WinScpSessionOptionValidators
{
public static bool IsValidSessionOptions(SftpRequest sftpRequest)
{
if (!IsValidHostInfo(sftpRequest) || !IsValidFileInfo(sftpRequest))
{
return false;
}
return WinScpSessionOptionsHelper.CreateSessionOptions(sftpRequest) != null;
}
private static bool IsValidFileInfo(SftpRequest sftpRequest)
{
return !string.IsNullOrWhiteSpace(sftpRequest.RemoteFilePath) &&
(!string.IsNullOrWhiteSpace(sftpRequest.LocalFilePath) || sftpRequest.LocalFileData != null);
}
private static bool IsValidHostInfo(SftpRequest sftpRequest)
{
return !string.IsNullOrWhiteSpace(sftpRequest.Password) &&
!string.IsNullOrWhiteSpace(sftpRequest.UserName) &&
!string.IsNullOrWhiteSpace(sftpRequest.HostName) && sftpRequest.PortNumber > 0;
}
}
@@ -0,0 +1,74 @@
using System;
using Serilog;
using WinSCP;
using LCU.Api.Internal.FTPLib.Models;
namespace LCU.Api.Internal.FTP.Helpers;
public static class WinScpSessionOptionsHelper
{
public static SessionOptions CreateSessionOptions(SftpRequest sftpRequest)
{
try
{
var protocol = FindWinScpProtocol(sftpRequest.Protocol);
SessionOptions sessionOptions = new SessionOptions
{
Protocol = protocol,
HostName = sftpRequest.HostName,
PortNumber = sftpRequest.PortNumber,
UserName = sftpRequest.UserName,
Password = sftpRequest.Password,
SshHostKeyFingerprint = sftpRequest.SshHostKeyFingerprint
};
return sessionOptions;
}
catch (Exception exception)
{
Log.Error(exception, "Error creating SessionOptions for Sftp Request");
return null;
}
}
public static SessionOptions CreateSessionOptions(SessionInformation sessionInformation)
{
try
{
var protocol = FindWinScpProtocol(sessionInformation.Protocol);
SessionOptions sessionOptions = new SessionOptions
{
Protocol = protocol,
HostName = sessionInformation.HostName,
PortNumber = sessionInformation.PortNumber,
UserName = sessionInformation.UserName,
Password = sessionInformation.Password,
SshHostKeyFingerprint = sessionInformation.SshHostKeyFingerprint
};
if (!string.IsNullOrWhiteSpace(sessionInformation.SshKeyFilePath))
{
sessionOptions.SshPrivateKeyPath = sessionInformation.SshKeyFilePath;
}
return sessionOptions;
}
catch (Exception exception)
{
Log.Error(exception, "Error creating SessionOptions for Sftp Request");
return null;
}
}
public static Protocol FindWinScpProtocol(ProtocolType protocolType)
{
switch (protocolType)
{
case ProtocolType.Sftp:
return Protocol.Sftp;
default:
return Protocol.Sftp;
}
}
}