diff --git a/.gitignore b/.gitignore index 8c2b884..8938829 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,7 @@ # Built Visual Studio Code Extensions *.vsix +[Dd]ebug/ +[Rr]elease/ +[Bb]in/ +[Oo]bj/ \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..b2cdec7 --- /dev/null +++ b/.vscode/launch.json @@ -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" + } + ] +} \ No newline at end of file diff --git a/Connection/Connect.cs b/Connection/Connect.cs new file mode 100644 index 0000000..d41da3d --- /dev/null +++ b/Connection/Connect.cs @@ -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; } + } +} diff --git a/Container/Get.cs b/Container/Get.cs new file mode 100644 index 0000000..9c40928 --- /dev/null +++ b/Container/Get.cs @@ -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); + } + } +} \ No newline at end of file diff --git a/FrostFS.Powershell.csproj b/FrostFS.Powershell.csproj new file mode 100644 index 0000000..b7b677f --- /dev/null +++ b/FrostFS.Powershell.csproj @@ -0,0 +1,18 @@ + + + + net8 + FrostFS.Powershell + true + + + + + All + + + + + + + diff --git a/frostfs-powershell.sln b/frostfs-powershell.sln new file mode 100644 index 0000000..5199e62 --- /dev/null +++ b/frostfs-powershell.sln @@ -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 diff --git a/private_key b/private_key new file mode 100644 index 0000000..bf627b8 --- /dev/null +++ b/private_key @@ -0,0 +1 @@ +KxDgvEKzgSBPPfuVfw67oPQBSjidEiqTHURKSDL1R7yGaGYAeYnr \ No newline at end of file