get container

This commit is contained in:
Dmitrii Stepanov 2024-06-13 11:32:48 +03:00
parent 57ba7f9148
commit ae9b826c45
7 changed files with 141 additions and 0 deletions

4
.gitignore vendored
View file

@ -12,3 +12,7 @@
# Built Visual Studio Code Extensions
*.vsix
[Dd]ebug/
[Rr]elease/
[Bb]in/
[Oo]bj/

24
.vscode/launch.json vendored Normal file
View file

@ -0,0 +1,24 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "PowerShell cmdlets: pwsh",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "dotnet: build",
"program": "pwsh",
"args": [
"-NoExit",
"-NoProfile",
"-Command",
"Import-Module ${workspaceFolder}/bin/Debug/net8/FrostFS.Powershell.dll",
],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"console": "integratedTerminal"
}
]
}

44
Connection/Connect.cs Normal file
View file

@ -0,0 +1,44 @@
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; }
}
}

25
Container/Get.cs Normal file
View file

@ -0,0 +1,25 @@
using System;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
namespace FrostFS.Powershell.Container
{
[Cmdlet(VerbsCommon.Get, "FrostFSNodeContainer")]
[OutputType(typeof(FrostFS.SDK.ModelsV2.Container))]
public class GetContainerCmdlet : PSCmdlet
{
[Parameter(Mandatory = true)]
public FrostFS.Powershell.Connection.Connection Connection { get; set; }
[Parameter(Mandatory = true)]
public string ID { get; set; }
protected override void ProcessRecord()
{
var hash = FrostFS.SDK.Cryptography.Base58.Decode(ID);
var containerID = new FrostFS.SDK.ModelsV2.ContainerId(FrostFS.SDK.Cryptography.Base58.Encode(hash));
var container = Connection.Client.GetContainerAsync(containerID).GetAwaiter().GetResult();
WriteObject(container);
}
}
}

18
FrostFS.Powershell.csproj Normal file
View file

@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8</TargetFramework>
<AssemblyName>FrostFS.Powershell</AssemblyName>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="PowerShellStandard.Library" Version="5.1.1">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include = "../frostfs-sdk-csharp/src/FrostFS.SDK.ClientV2/FrostFS.SDK.ClientV2.csproj" />
</ItemGroup>
</Project>

25
frostfs-powershell.sln Normal file
View file

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FrostFS.Powershell", "FrostFS.Powershell.csproj", "{BAE430C3-A07F-466A-8A3E-872572FDEDB5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BAE430C3-A07F-466A-8A3E-872572FDEDB5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BAE430C3-A07F-466A-8A3E-872572FDEDB5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BAE430C3-A07F-466A-8A3E-872572FDEDB5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BAE430C3-A07F-466A-8A3E-872572FDEDB5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2DD0F26C-0877-4B66-8F67-C7FF193F1CE9}
EndGlobalSection
EndGlobal

1
private_key Normal file
View file

@ -0,0 +1 @@
KxDgvEKzgSBPPfuVfw67oPQBSjidEiqTHURKSDL1R7yGaGYAeYnr