Added daily deletion of Installation s3 keys

This commit is contained in:
Kim 2023-03-09 13:20:37 +01:00
parent f1394e4755
commit fd10522786
5 changed files with 24 additions and 5 deletions

View File

@ -216,5 +216,14 @@ public partial class Db : IDisposable
.Where(installation => installation.Id == installationId) .Where(installation => installation.Id == installationId)
.Select(installation => installation.S3Key); .Select(installation => installation.S3Key);
} }
public void DeleteS3KeysDaily()
{
foreach (var installation in Installations.ToList())
{
installation.S3Key = null;
Update(installation);
}
}
} }

View File

@ -152,7 +152,7 @@ public partial class Db
// //
// } // }
public Object CreateAndSaveInstallationS3ApiKey(Installation installation) public Object? CreateAndSaveInstallationS3ApiKey(Installation installation)
{ {
//EXOSCALE API URL //EXOSCALE API URL
const String url = "https://api-ch-dk-2.exoscale.com/v2/"; const String url = "https://api-ch-dk-2.exoscale.com/v2/";

View File

@ -14,7 +14,7 @@ public class Installation : TreeNode
public Double Long { get; set; } public Double Long { get; set; }
public String S3Bucket { get; set; } = ""; public String S3Bucket { get; set; } = "";
public String S3Key { get; set; } public String? S3Key { get; set; }
} }

View File

@ -1,3 +1,4 @@
using System.Reactive.Linq;
using InnovEnergy.App.Backend.Database; using InnovEnergy.App.Backend.Database;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
@ -10,11 +11,13 @@ public static class Program
using (var db = Db.Connect()) using (var db = Db.Connect())
db.CreateFakeRelations(); db.CreateFakeRelations();
Observable.Interval(TimeSpan.FromDays(1)).Subscribe((_) => deleteInstallationS3KeysDaily());
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers(); // TODO: remove magic, specify controllers explicitly builder.Services.AddControllers(); // TODO: remove magic, specify controllers explicitly
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddHttpContextAccessor(); builder.Services.AddHttpContextAccessor();
builder.Services.AddEndpointsApiExplorer(); builder.Services.AddEndpointsApiExplorer();
builder.Services.AddCors(o => o.AddDefaultPolicy(p => p.WithOrigins("*").AllowAnyHeader().AllowAnyMethod())); builder.Services.AddCors(o => o.AddDefaultPolicy(p => p.WithOrigins("*").AllowAnyHeader().AllowAnyMethod()));
@ -34,7 +37,7 @@ public static class Program
app.UseSwagger(); app.UseSwagger();
app.UseSwaggerUI(cfg => cfg.EnableFilter()); app.UseSwaggerUI(cfg => cfg.EnableFilter());
} }
app.UseCors(); app.UseCors();
app.UseHttpsRedirection(); app.UseHttpsRedirection();
app.UseAuthorization(); app.UseAuthorization();
@ -44,6 +47,13 @@ public static class Program
app.Run(); app.Run();
} }
private static void deleteInstallationS3KeysDaily()
{
using var db = Db.Connect();
db.DeleteS3KeysDaily();
}
private static async Task SetSessionUser(HttpContext ctx, RequestDelegate next) private static async Task SetSessionUser(HttpContext ctx, RequestDelegate next)
{ {
var headers = ctx.Request.Headers; var headers = ctx.Request.Headers;

Binary file not shown.