45 lines
1.2 KiB
C#
45 lines
1.2 KiB
C#
|
using System;
|
||
|
using System.IO;
|
||
|
using System.Management.Automation;
|
||
|
using System.Management.Automation.Runspaces;
|
||
|
|
||
|
namespace FrostFS.Powershell.Connection
|
||
|
{
|
||
|
[Cmdlet(VerbsCommunications.Connect, "FrostFSNode")]
|
||
|
[OutputType(typeof(Connection))]
|
||
|
public class ConnectCmdlet : PSCmdlet
|
||
|
{
|
||
|
[Parameter(Mandatory = true)]
|
||
|
public string Endpoint { get; set; }
|
||
|
|
||
|
[Parameter(Mandatory = true)]
|
||
|
public string KeyPath { get; set; }
|
||
|
|
||
|
protected override void ProcessRecord()
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
var keyData = File.ReadAllText(KeyPath);
|
||
|
var client = FrostFS.SDK.ClientV2.Client.GetInstance(keyData, Endpoint);
|
||
|
WriteObject(new Connection
|
||
|
{
|
||
|
Client = client,
|
||
|
Host = Endpoint
|
||
|
});
|
||
|
}
|
||
|
catch (Exception e)
|
||
|
{
|
||
|
WriteError(new ErrorRecord(e, "", ErrorCategory.InvalidOperation, this));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
public class Connection
|
||
|
{
|
||
|
internal FrostFS.SDK.ClientV2.Interfaces.IFrostFSClient Client { get; set; }
|
||
|
|
||
|
public string Host { get; internal set; }
|
||
|
}
|
||
|
}
|