New Buckets now have cors

This commit is contained in:
Kim 2023-11-13 09:40:34 +01:00
parent 6c71b77482
commit 9a2990f750
2 changed files with 14 additions and 5 deletions

View File

@ -6,7 +6,9 @@ using System.Net;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json.Nodes;
using Amazon.S3.Model;
using InnovEnergy.App.Backend.Database;
using InnovEnergy.Lib.Utils;
namespace InnovEnergy.App.Backend.DataTypes.Methods;
@ -242,11 +244,17 @@ public static class ExoCmd
return id;
}
public static async Task<Boolean> CreateBucket(this Installation installation)
{
var cors = new CORSConfiguration();
cors.Rules.Add(new CORSRule());
cors.Rules[0].AllowedHeaders = new List<string> { "*" };
cors.Rules[0].AllowedOrigins = new List<string> { "*" };
cors.Rules[0].AllowedMethods = new List<string> { "Get", "Head" };
var s3Region = new S3Region($"https://{installation.S3Region}.{installation.S3Provider}", S3Creds!);
return await s3Region.PutBucket(installation.BucketName()) != null;
var a = await s3Region.PutBucket(installation.BucketName());
return a != null && await a.PutCors(cors);
}
public static async Task<Boolean> SendConfig(this Installation installation, String config)

View File

@ -99,10 +99,11 @@ public static class SessionMethods
&& user.HasWriteAccess
&& user.HasAccessToParentOf(installation)
&& Db.Create(installation) // TODO: these two in a transaction
&& installation.SetOrderNumbers()
&& installation.SetOrderNumbers()
&& Db.Create(new InstallationAccess { UserId = user.Id, InstallationId = installation.Id })
&& await installation.CreateBucket()
&& await installation.RenewS3Credentials(); // generation of access _after_ generation of
&& await installation.CreateBucket()
&& await installation.RenewS3Credentials();
// generation of access _after_ generation of
// bucket to prevent "zombie" access-rights.
// This might ** us over if the creation of access rights fails,
// as bucket-names are unique and bound to the installation id... -K