Allows putting config.json onto buckets automatically

This commit is contained in:
Kim 2023-10-30 15:58:56 +01:00
parent 41f93ebde8
commit 1d6aafec60
3 changed files with 31 additions and 24 deletions

View File

@ -249,4 +249,34 @@ public static class ExoCmd
return await s3Region.PutBucket(installation.BucketName()) != null;
}
public static async Task<Boolean> SendConfig(this Installation installation, String config)
{
// This looks hacky but here we grab the vpn-Ip of the installation by its installation Name (e.g. Salimax0001)
// From the vpn server (here salidomo, but we use the vpn home ip for future-proofing)
// using var client = new HttpClient();
// var webRequest = client.GetAsync("10.2.0.1/vpnstatus.txt");
// var text = webRequest.ToString();
// var lines = text!.Split(new [] { Environment.NewLine }, StringSplitOptions.None);
// var vpnIp = lines.First(l => l.Contains(installation.InstallationName)).Split(",")[1];
//
// // Writing the config to a file and then sending that file with rsync sounds inefficient
// // We should find a better solution...
// // TODO The VPN server should do this not the backend!!!
// await File.WriteAllTextAsync("./config.json", config);
// var result = await Cli.Wrap("rsync")
// .WithArguments("./config.json")
// .AppendArgument($@"root@{vpnIp}:/salimax")
// .ExecuteAsync();
// return result.ExitCode == 200;
var s3Region = new S3Region($"https://{installation.S3Region}.{installation.S3Provider}", S3Creds!);
var url = s3Region.Bucket(installation.BucketName()).Path("config.json");
return await url.PutObject(config);
}
}

View File

@ -47,29 +47,6 @@ public static class InstallationMethods
return true;
}
public static async Task<Boolean> SendConfig(this Installation installation, String config)
{
// This looks hacky but here we grab the vpn-Ip of the installation by its installation Name (e.g. Salimax0001)
// From the vpn server (here salidomo, but we use the vpn home ip for future-proofing)
using var client = new HttpClient();
var webRequest = client.GetAsync("10.2.0.1/vpnstatus.txt");
var text = webRequest.ToString();
var lines = text!.Split(new [] { Environment.NewLine }, StringSplitOptions.None);
var vpnIp = lines.First(l => l.Contains(installation.InstallationName)).Split(",")[1];
// Writing the config to a file and then sending that file with rsync sounds inefficient
// We should find a better solution...
// TODO The VPN server should do this not the backend!!!
await File.WriteAllTextAsync("./config.json", config);
var result = await Cli.Wrap("rsync")
.WithArguments("./config.json")
.AppendArgument($@"root@{vpnIp}:/salimax")
.ExecuteAsync();
return result.ExitCode == 200;
}
public static IEnumerable<User> UsersWithAccess(this Installation installation)
{
return installation