2023-02-16 12:57:06 +00:00
|
|
|
using CliWrap;
|
|
|
|
using InnovEnergy.Lib.Utils.Net;
|
|
|
|
|
|
|
|
namespace InnovEnergy.Lib.Utils;
|
|
|
|
|
|
|
|
public class SshHost
|
|
|
|
{
|
|
|
|
private static Command Ssh { get; } = new Command("ssh");
|
|
|
|
|
|
|
|
public String HostName { get; }
|
|
|
|
public String User { get; }
|
|
|
|
public String? IdentityFile { get; }
|
|
|
|
public Command Command { get; }
|
|
|
|
|
|
|
|
public SshHost(String hostName, String? user = null, String? identityFile = null)
|
|
|
|
{
|
|
|
|
HostName = hostName;
|
|
|
|
User = user ?? "root";
|
|
|
|
IdentityFile = identityFile;
|
|
|
|
|
|
|
|
var identity = identityFile is not null
|
|
|
|
? $" -i {identityFile}"
|
|
|
|
: "";
|
|
|
|
|
|
|
|
Command = Ssh.WithArguments($"{User}@{HostName}{identity}");
|
|
|
|
}
|
|
|
|
|
|
|
|
public Task<Boolean> Ping() => HostName.Ping();
|
2023-05-04 07:43:42 +00:00
|
|
|
|
|
|
|
public static implicit operator SshHost(String hostname) => new SshHost(hostname);
|
|
|
|
|
|
|
|
public override String ToString() => Command.ToString();
|
2023-02-16 12:57:06 +00:00
|
|
|
}
|