Extract ExoCmd into own file

This commit is contained in:
ig 2023-07-05 15:09:28 +02:00
parent 395d5a89b2
commit 25450aecee
1 changed files with 48 additions and 0 deletions

View File

@ -0,0 +1,48 @@
using CliWrap;
using CliWrap.Buffered;
using InnovEnergy.Lib.Utils;
namespace InnovEnergy.App.Backend.DataTypes.Methods;
public static class ExoCmd
{
private static readonly Command Exo = Cli.Wrap("exo");
private const String ConfigFile = "./exoscale.toml";
public static async Task<(String key, String secret)> CreateKey(this Installation installation)
{
//if (installation.Id != 1) return "help"; //Todo remove me I am for debugging
var preParse = await Exo
.WithArguments("iam access-key create " + installation.BucketName()
+ " --operation get-sos-object"
+ " --resource sos/bucket:" + installation.BucketName()
+ " -C " + ConfigFile
+ " -O text")
.ExecuteBufferedAsync();
var key = preParse.StandardOutput.Split("\t")[2];
var secret = preParse.StandardOutput.Split("\t")[3];
return (key, secret);
//return $"{key};{secret}";
}
public static async void RevokeKey(this Installation installation)
{
try
{
await Exo
.WithArguments("iam access-key revoke " + installation.S3Key + " -f " + " -C " + ConfigFile)
.ExecuteAsync();
}
catch
{
// TODO
("Failed to revoke key for installation " + installation.Name).WriteLine();
}
}
}