diff --git a/csharp/App/Backend/DataTypes/Installation.cs b/csharp/App/Backend/DataTypes/Installation.cs index c4e625646..4a01de8dc 100644 --- a/csharp/App/Backend/DataTypes/Installation.cs +++ b/csharp/App/Backend/DataTypes/Installation.cs @@ -16,7 +16,7 @@ public class Installation : TreeNode public Double Long { get; set; } public String S3Bucket { get; set; } = ""; - public String S3Url { get; set; } = ""; + public String S3KeySecret { get; set; } = ""; } \ No newline at end of file diff --git a/csharp/App/Backend/DataTypes/Methods/Installation.cs b/csharp/App/Backend/DataTypes/Methods/Installation.cs index 8319daa1f..f3c89995d 100644 --- a/csharp/App/Backend/DataTypes/Methods/Installation.cs +++ b/csharp/App/Backend/DataTypes/Methods/Installation.cs @@ -1,3 +1,5 @@ +using CliWrap; +using CliWrap.Buffered; using InnovEnergy.App.Backend.Database; using InnovEnergy.App.Backend.S3; using InnovEnergy.Lib.Utils; @@ -11,17 +13,13 @@ public static class InstallationMethods public static String BucketName(this Installation installation) { - return $"s3://{installation.Id}-{BucketNameSalt}"; - } - - public static async Task RenewS3BucketUrl(this Installation installation) - { - return await RenewS3BucketUrl(installation, TimeSpan.FromDays(1)); + return $"{installation.Id}-{BucketNameSalt}"; } - public static async Task RenewS3BucketUrl(this Installation installation, TimeSpan validity) + public static async Task RenewS3BucketUrl(this Installation installation) { - installation.S3Url = await S3Access.ReadOnly.SignUrl(installation.BucketName(), validity); + installation.RevokeKey(); + installation.S3KeySecret = await installation.CreateKey(); return Db.Update(installation); } @@ -128,3 +126,39 @@ public static class InstallationMethods } +public static class ExoCmd +{ + private static readonly Command Exo = Cli.Wrap("exo"); + private static String ConfigFile = "./exoscale.toml"; + + public static async Task 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(); + + return preParse.StandardOutput.Split("\t")[2] + ";" + preParse.StandardOutput.Split("\t")[3]; + } + + public static async void RevokeKey(this Installation installation) + { + try + { + await Exo + .WithArguments("iam access-key revoke " + installation.S3KeySecret.Split(";", 2)[0] + " -f " + " -C " + ConfigFile) + .ExecuteAsync(); + + } + catch + { + // todo Fill me there is no key for this installation + } + } + +} + diff --git a/csharp/App/Backend/Resources/s3ReadOnlyKey.json b/csharp/App/Backend/Resources/s3ReadOnlyKey.json index b9f1df236..a55ff349c 100644 --- a/csharp/App/Backend/Resources/s3ReadOnlyKey.json +++ b/csharp/App/Backend/Resources/s3ReadOnlyKey.json @@ -1,4 +1,4 @@ { - "Key": "EXO44d2979c8e570eae81ead564", - "Secret": "55MAqyO_FqUmh7O64VIO0egq50ERn_WIAWuc2QC44QU" + "Key": "EXOb6d6dc1880cdd51f1ebc6692", + "Secret": "kpIey4QJlQFuWG_WoTazcY7kBEjN2f_ll2cDBeg64m4" } \ No newline at end of file diff --git a/csharp/App/Backend/S3/S3Access.cs b/csharp/App/Backend/S3/S3Access.cs index 0084807c3..d509ae460 100644 --- a/csharp/App/Backend/S3/S3Access.cs +++ b/csharp/App/Backend/S3/S3Access.cs @@ -9,4 +9,9 @@ public static class S3Access { public static S3Cmd ReadOnly => Deserialize(OpenRead("./Resources/s3ReadOnlyKey.json"))!; public static S3Cmd ReadWrite => Deserialize(OpenRead("./Resources/s3ReadWriteKey.json"))!; + + public static async Task CreateKey(String bucketName) + { + throw new NotImplementedException(); + } } \ No newline at end of file diff --git a/csharp/App/Backend/db.sqlite b/csharp/App/Backend/db.sqlite index c2a26b55c..55cc83a84 100644 Binary files a/csharp/App/Backend/db.sqlite and b/csharp/App/Backend/db.sqlite differ