Merge branch 'main' of https://git.innov.energy/Innovenergy/git_trunk
This commit is contained in:
commit
bf63da1ffd
|
@ -1,6 +1,6 @@
|
||||||
namespace InnovEnergy.App.Backend.DataTypes;
|
namespace InnovEnergy.App.Backend.DataTypes;
|
||||||
|
|
||||||
public class DeletedFolder : TreeNode {}
|
public class DeletedFolder : Folder {}
|
||||||
|
|
||||||
//Deleted Things need to have AT LEAST every property that normal things have
|
//Deleted Things need to have AT LEAST every property that normal things have
|
||||||
//Todo "Restore" Function? -k
|
//Todo "Restore" Function? -k
|
|
@ -1,19 +1,7 @@
|
||||||
namespace InnovEnergy.App.Backend.DataTypes;
|
namespace InnovEnergy.App.Backend.DataTypes;
|
||||||
|
|
||||||
//Deleted Things need to have AT LEAST every property that normal things have
|
//Deleted Things need to have AT LEAST every property that normal things have
|
||||||
public class DeletedInstallation : TreeNode
|
public class DeletedInstallation : Installation
|
||||||
{
|
{
|
||||||
public String Location { get; set; } = "";
|
|
||||||
public String Region { get; set; } = "";
|
|
||||||
public String Country { get; set; } = "";
|
|
||||||
|
|
||||||
// TODO: make relation
|
|
||||||
public String OrderNumbers { get; set; } = "";
|
|
||||||
|
|
||||||
public Double Lat { get; set; }
|
|
||||||
public Double Long { get; set; }
|
|
||||||
|
|
||||||
public String S3Bucket { get; set; } = "";
|
|
||||||
public String S3Url { get; set; } = "";
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -2,21 +2,9 @@ using SQLite;
|
||||||
|
|
||||||
namespace InnovEnergy.App.Backend.DataTypes;
|
namespace InnovEnergy.App.Backend.DataTypes;
|
||||||
|
|
||||||
|
|
||||||
//Deleted Things need to have AT LEAST every property that normal things have
|
//Deleted Things need to have AT LEAST every property that normal things have
|
||||||
|
|
||||||
public class DeletedUser : TreeNode
|
public class DeletedUser : User
|
||||||
{
|
{
|
||||||
public String Email { get; set; } = null!;
|
|
||||||
public Boolean HasWriteAccess { get; set; } = false;
|
|
||||||
public Boolean MustResetPassword { get; set; } = false;
|
|
||||||
public String Language { get; set; } = null!;
|
|
||||||
public String Password { get; set; } = null!;
|
|
||||||
|
|
||||||
[Unique]
|
|
||||||
public override String Name { get; set; } = null!;
|
public override String Name { get; set; } = null!;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// TODO: must reset pwd
|
|
||||||
}
|
}
|
|
@ -20,8 +20,7 @@ public static class InstallationMethods
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<Boolean> RenewS3BucketUrl(this Installation installation, TimeSpan validity)
|
public static async Task<Boolean> RenewS3BucketUrl(this Installation installation, TimeSpan validity)
|
||||||
{
|
{
|
||||||
installation.S3Url =
|
|
||||||
installation.S3Url = await S3Access.ReadOnly.SignUrl(installation.BucketName(), validity);
|
installation.S3Url = await S3Access.ReadOnly.SignUrl(installation.BucketName(), validity);
|
||||||
return Db.Update(installation);
|
return Db.Update(installation);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,14 +16,22 @@ public static partial class Db
|
||||||
|
|
||||||
private static SQLiteConnection Connection { get; } = new SQLiteConnection(DbPath);
|
private static SQLiteConnection Connection { get; } = new SQLiteConnection(DbPath);
|
||||||
|
|
||||||
public static TableQuery<Session> Sessions => Connection.Table<Session>();
|
public static TableQuery<Session> Sessions => Connection.Table<Session>();
|
||||||
public static TableQuery<Folder> Folders => Connection.Table<Folder>();
|
public static TableQuery<Folder> Folders => Connection.Table<Folder>();
|
||||||
public static TableQuery<Installation> Installations => Connection.Table<Installation>();
|
public static TableQuery<DeletedFolder> DeletedFolders => Connection.Table<DeletedFolder>();
|
||||||
public static TableQuery<User> Users => Connection.Table<User>();
|
public static TableQuery<Installation> Installations => Connection.Table<Installation>();
|
||||||
public static TableQuery<FolderAccess> FolderAccess => Connection.Table<FolderAccess>();
|
public static TableQuery<DeletedInstallation> DeletedInstallations => Connection.Table<DeletedInstallation>();
|
||||||
public static TableQuery<InstallationAccess> InstallationAccess => Connection.Table<InstallationAccess>();
|
public static TableQuery<User> Users => Connection.Table<User>();
|
||||||
|
public static TableQuery<DeletedUser> DeletedUsers => Connection.Table<DeletedUser>();
|
||||||
|
public static TableQuery<FolderAccess> FolderAccess => Connection.Table<FolderAccess>();
|
||||||
|
public static TableQuery<InstallationAccess> InstallationAccess => Connection.Table<InstallationAccess>();
|
||||||
|
|
||||||
|
|
||||||
|
public static void Init()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static Db()
|
static Db()
|
||||||
{
|
{
|
||||||
// on startup create/migrate tables
|
// on startup create/migrate tables
|
||||||
|
@ -31,7 +39,10 @@ public static partial class Db
|
||||||
Connection.RunInTransaction(() =>
|
Connection.RunInTransaction(() =>
|
||||||
{
|
{
|
||||||
Connection.CreateTable<User>();
|
Connection.CreateTable<User>();
|
||||||
|
Connection.CreateTable<DeletedUser>();
|
||||||
Connection.CreateTable<Installation>();
|
Connection.CreateTable<Installation>();
|
||||||
|
Connection.CreateTable<DeletedInstallation>();
|
||||||
|
Connection.CreateTable<DeletedFolder>();
|
||||||
Connection.CreateTable<Folder>();
|
Connection.CreateTable<Folder>();
|
||||||
Connection.CreateTable<FolderAccess>();
|
Connection.CreateTable<FolderAccess>();
|
||||||
Connection.CreateTable<InstallationAccess>();
|
Connection.CreateTable<InstallationAccess>();
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
using System;
|
|
||||||
using InnovEnergy.App.Backend.DataTypes;
|
using InnovEnergy.App.Backend.DataTypes;
|
||||||
using MailKit.Net.Smtp;
|
using MailKit.Net.Smtp;
|
||||||
using MailKit;
|
|
||||||
using MimeKit;
|
using MimeKit;
|
||||||
|
|
||||||
namespace InnovEnergy.App.Backend.Mailer;
|
namespace InnovEnergy.App.Backend.Mailer;
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
using InnovEnergy.App.Backend.Database;
|
||||||
using Microsoft.OpenApi.Models;
|
using Microsoft.OpenApi.Models;
|
||||||
|
|
||||||
namespace InnovEnergy.App.Backend;
|
namespace InnovEnergy.App.Backend;
|
||||||
|
@ -5,12 +6,13 @@ namespace InnovEnergy.App.Backend;
|
||||||
public static class Program
|
public static class Program
|
||||||
{
|
{
|
||||||
|
|
||||||
// TODO: Trash
|
|
||||||
|
|
||||||
public static void Main(String[] args)
|
public static void Main(String[] args)
|
||||||
{
|
{
|
||||||
//Db.CreateFakeRelations();
|
//Db.CreateFakeRelations();
|
||||||
|
Db.Init();
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"Key": "EXO44d2979c8e570eae81ead564",
|
||||||
|
"Secret": "55MAqyO_FqUmh7O64VIO0egq50ERn_WIAWuc2QC44QU"
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"Key": "EXO87ca85e29dd412f1238f1cf0",
|
||||||
|
"Secret": "-T9TAqy9a3-0-xj7HKsFFJOCcxfRpcnL6OW5oOrOcWU"
|
||||||
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
|
using System.Text.Json;
|
||||||
using static System.IO.File;
|
using static System.IO.File;
|
||||||
using static System.Text.Json.JsonSerializer;
|
using static System.Text.Json.JsonSerializer;
|
||||||
|
|
||||||
|
@ -10,15 +11,9 @@ public static class S3Access
|
||||||
// they should be read from disk on each use,
|
// they should be read from disk on each use,
|
||||||
// so the backend does not need to be restarted on change
|
// so the backend does not need to be restarted on change
|
||||||
|
|
||||||
public static S3Cmd ReadOnly { get; } = new S3Cmd
|
|
||||||
(
|
|
||||||
key : Deserialize<Dictionary<String, String>>(OpenRead("./Resources/urlAndKey.json"))?["ReadOnlyS3Key"],
|
|
||||||
secret: Deserialize<Dictionary<String, String>>(OpenRead("./Resources/urlAndKey.json"))?["ReadOnlyS3Secret"]
|
|
||||||
);
|
|
||||||
|
|
||||||
public static S3Cmd ReadWrite { get; } = new S3Cmd
|
public static S3Cmd ReadOnly => Deserialize<S3Cmd>(OpenRead("./Resources/s3ReadOnlyKey.json"))!;
|
||||||
(
|
|
||||||
key : Deserialize<Dictionary<String, String>>(OpenRead("./Resources/urlAndKey.json"))?["ReadWriteS3Key"],
|
|
||||||
secret: Deserialize<Dictionary<String, String>>(OpenRead("./Resources/urlAndKey.json"))?["ReadWriteS3Secret"]
|
public static S3Cmd ReadWrite => Deserialize<S3Cmd>(OpenRead("./Resources/s3ReadWriteKey.json"))!;
|
||||||
);
|
|
||||||
}
|
}
|
|
@ -1,9 +1,11 @@
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using CliWrap;
|
using CliWrap;
|
||||||
using CliWrap.Buffered;
|
using CliWrap.Buffered;
|
||||||
using InnovEnergy.Lib.Utils;
|
using InnovEnergy.Lib.Utils;
|
||||||
|
|
||||||
namespace InnovEnergy.App.Backend.S3;
|
namespace InnovEnergy.App.Backend.S3;
|
||||||
|
|
||||||
|
[SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global")]
|
||||||
public class S3Cmd
|
public class S3Cmd
|
||||||
{
|
{
|
||||||
private static readonly Command Python = Cli.Wrap("python3");
|
private static readonly Command Python = Cli.Wrap("python3");
|
||||||
|
@ -11,20 +13,26 @@ public class S3Cmd
|
||||||
private const String? S3CmdPath = "Resources/s3cmd.py";
|
private const String? S3CmdPath = "Resources/s3cmd.py";
|
||||||
private const String S3Prefix = "s3://";
|
private const String S3Prefix = "s3://";
|
||||||
|
|
||||||
private String?[] DefaultArgs { get; }
|
public String Key { get; init;}
|
||||||
|
public String Secret { get; init;}
|
||||||
|
|
||||||
|
// private String?[] DefaultArgs { get; }
|
||||||
|
|
||||||
// ReSharper disable StringLiteralTypo
|
// ReSharper disable StringLiteralTypo
|
||||||
// ReSharper enable StringLiteralTypo
|
// ReSharper enable StringLiteralTypo
|
||||||
|
[Obsolete("Only to be used by Json-Deserializer")] public S3Cmd()
|
||||||
public S3Cmd(String? key, String? secret)
|
|
||||||
{
|
{
|
||||||
DefaultArgs = new[]
|
|
||||||
{
|
|
||||||
S3CmdPath,
|
|
||||||
"--access_key", key,
|
|
||||||
"--secret_key", secret,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public S3Cmd(String? key, String? secret)
|
||||||
|
// {
|
||||||
|
// DefaultArgs = new[]
|
||||||
|
// {
|
||||||
|
// S3CmdPath,
|
||||||
|
// "--access_key", key,
|
||||||
|
// "--secret_key", secret,
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
|
||||||
public async Task<String> SignUrl(String bucketName, TimeSpan validity)
|
public async Task<String> SignUrl(String bucketName, TimeSpan validity)
|
||||||
{
|
{
|
||||||
|
@ -50,13 +58,20 @@ public class S3Cmd
|
||||||
|
|
||||||
private Task<BufferedCommandResult> Run(String bucketName, String operation, params String[] optionalArgs)
|
private Task<BufferedCommandResult> Run(String bucketName, String operation, params String[] optionalArgs)
|
||||||
{
|
{
|
||||||
var args = DefaultArgs
|
var credentials = new String[]
|
||||||
|
{
|
||||||
|
S3CmdPath,
|
||||||
|
"--access_key", Key,
|
||||||
|
"--secret_key", Secret,
|
||||||
|
};
|
||||||
|
|
||||||
|
var args = credentials
|
||||||
.Append(operation)
|
.Append(operation)
|
||||||
.Append(bucketName.EnsureStartsWith(S3Prefix))
|
.Append(bucketName.EnsureStartsWith(S3Prefix))
|
||||||
.Concat(optionalArgs);
|
.Concat(optionalArgs);
|
||||||
|
|
||||||
return Python
|
return Python
|
||||||
.WithArguments(args)
|
.WithArguments(args)
|
||||||
.ExecuteBufferedAsync();
|
.ExecuteBufferedAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
Binary file not shown.
Loading…
Reference in New Issue