changed signed urls for keysecret pairs in installations
This commit is contained in:
parent
5682d2893f
commit
f5515c110a
|
@ -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; } = "";
|
||||
|
||||
|
||||
}
|
|
@ -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<Boolean> RenewS3BucketUrl(this Installation installation)
|
||||
{
|
||||
return await RenewS3BucketUrl(installation, TimeSpan.FromDays(1));
|
||||
return $"{installation.Id}-{BucketNameSalt}";
|
||||
}
|
||||
|
||||
public static async Task<Boolean> RenewS3BucketUrl(this Installation installation, TimeSpan validity)
|
||||
public static async Task<Boolean> 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<String> 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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"Key": "EXO44d2979c8e570eae81ead564",
|
||||
"Secret": "55MAqyO_FqUmh7O64VIO0egq50ERn_WIAWuc2QC44QU"
|
||||
"Key": "EXOb6d6dc1880cdd51f1ebc6692",
|
||||
"Secret": "kpIey4QJlQFuWG_WoTazcY7kBEjN2f_ll2cDBeg64m4"
|
||||
}
|
|
@ -9,4 +9,9 @@ public static class S3Access
|
|||
{
|
||||
public static S3Cmd ReadOnly => Deserialize<S3Cmd>(OpenRead("./Resources/s3ReadOnlyKey.json"))!;
|
||||
public static S3Cmd ReadWrite => Deserialize<S3Cmd>(OpenRead("./Resources/s3ReadWriteKey.json"))!;
|
||||
|
||||
public static async Task<String> CreateKey(String bucketName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
Binary file not shown.
Loading…
Reference in New Issue