From 25450aecee4e397d3d8352854716720e145d8b30 Mon Sep 17 00:00:00 2001 From: ig Date: Wed, 5 Jul 2023 15:09:28 +0200 Subject: [PATCH] Extract ExoCmd into own file --- .../App/Backend/DataTypes/Methods/ExoCmd.cs | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 csharp/App/Backend/DataTypes/Methods/ExoCmd.cs diff --git a/csharp/App/Backend/DataTypes/Methods/ExoCmd.cs b/csharp/App/Backend/DataTypes/Methods/ExoCmd.cs new file mode 100644 index 000000000..50be5aafb --- /dev/null +++ b/csharp/App/Backend/DataTypes/Methods/ExoCmd.cs @@ -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(); + } + } + +} \ No newline at end of file