diff --git a/csharp/App/Backend/Database/Db.cs b/csharp/App/Backend/Database/Db.cs index 95afb8bc2..06bdbd2e7 100644 --- a/csharp/App/Backend/Database/Db.cs +++ b/csharp/App/Backend/Database/Db.cs @@ -216,5 +216,14 @@ public partial class Db : IDisposable .Where(installation => installation.Id == installationId) .Select(installation => installation.S3Key); } + + public void DeleteS3KeysDaily() + { + foreach (var installation in Installations.ToList()) + { + installation.S3Key = null; + Update(installation); + } + } } diff --git a/csharp/App/Backend/Database/User.cs b/csharp/App/Backend/Database/User.cs index 28c159508..b07bc6b62 100644 --- a/csharp/App/Backend/Database/User.cs +++ b/csharp/App/Backend/Database/User.cs @@ -152,7 +152,7 @@ public partial class Db // // } - public Object CreateAndSaveInstallationS3ApiKey(Installation installation) + public Object? CreateAndSaveInstallationS3ApiKey(Installation installation) { //EXOSCALE API URL const String url = "https://api-ch-dk-2.exoscale.com/v2/"; diff --git a/csharp/App/Backend/Model/Installation.cs b/csharp/App/Backend/Model/Installation.cs index b04885b40..b6c4b7968 100644 --- a/csharp/App/Backend/Model/Installation.cs +++ b/csharp/App/Backend/Model/Installation.cs @@ -14,7 +14,7 @@ public class Installation : TreeNode public Double Long { get; set; } public String S3Bucket { get; set; } = ""; - public String S3Key { get; set; } + public String? S3Key { get; set; } } diff --git a/csharp/App/Backend/Program.cs b/csharp/App/Backend/Program.cs index ae662b779..7b6df34b9 100644 --- a/csharp/App/Backend/Program.cs +++ b/csharp/App/Backend/Program.cs @@ -1,3 +1,4 @@ +using System.Reactive.Linq; using InnovEnergy.App.Backend.Database; using Microsoft.OpenApi.Models; @@ -10,11 +11,13 @@ public static class Program using (var db = Db.Connect()) db.CreateFakeRelations(); + Observable.Interval(TimeSpan.FromDays(1)).Subscribe((_) => deleteInstallationS3KeysDaily()); + var builder = WebApplication.CreateBuilder(args); - + builder.Services.AddControllers(); // TODO: remove magic, specify controllers explicitly // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle - + builder.Services.AddHttpContextAccessor(); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddCors(o => o.AddDefaultPolicy(p => p.WithOrigins("*").AllowAnyHeader().AllowAnyMethod())); @@ -34,7 +37,7 @@ public static class Program app.UseSwagger(); app.UseSwaggerUI(cfg => cfg.EnableFilter()); } - + app.UseCors(); app.UseHttpsRedirection(); app.UseAuthorization(); @@ -44,6 +47,13 @@ public static class Program app.Run(); } + private static void deleteInstallationS3KeysDaily() + { + using var db = Db.Connect(); + db.DeleteS3KeysDaily(); + + } + private static async Task SetSessionUser(HttpContext ctx, RequestDelegate next) { var headers = ctx.Request.Headers; diff --git a/csharp/App/Backend/db.sqlite b/csharp/App/Backend/db.sqlite index 92600a486..6b0d2d492 100644 Binary files a/csharp/App/Backend/db.sqlite and b/csharp/App/Backend/db.sqlite differ