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;
|
||||
|
||||
public class DeletedFolder : TreeNode {}
|
||||
public class DeletedFolder : Folder {}
|
||||
|
||||
//Deleted Things need to have AT LEAST every property that normal things have
|
||||
//Todo "Restore" Function? -k
|
|
@ -1,19 +1,7 @@
|
|||
namespace InnovEnergy.App.Backend.DataTypes;
|
||||
|
||||
//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;
|
||||
|
||||
|
||||
//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!;
|
||||
|
||||
|
||||
|
||||
// TODO: must reset pwd
|
||||
}
|
|
@ -21,7 +21,6 @@ public static class InstallationMethods
|
|||
|
||||
public static async Task<Boolean> RenewS3BucketUrl(this Installation installation, TimeSpan validity)
|
||||
{
|
||||
installation.S3Url =
|
||||
installation.S3Url = await S3Access.ReadOnly.SignUrl(installation.BucketName(), validity);
|
||||
return Db.Update(installation);
|
||||
}
|
||||
|
|
|
@ -16,12 +16,20 @@ public static partial class Db
|
|||
|
||||
private static SQLiteConnection Connection { get; } = new SQLiteConnection(DbPath);
|
||||
|
||||
public static TableQuery<Session> Sessions => Connection.Table<Session>();
|
||||
public static TableQuery<Folder> Folders => Connection.Table<Folder>();
|
||||
public static TableQuery<Installation> Installations => Connection.Table<Installation>();
|
||||
public static TableQuery<User> Users => Connection.Table<User>();
|
||||
public static TableQuery<FolderAccess> FolderAccess => Connection.Table<FolderAccess>();
|
||||
public static TableQuery<InstallationAccess> InstallationAccess => Connection.Table<InstallationAccess>();
|
||||
public static TableQuery<Session> Sessions => Connection.Table<Session>();
|
||||
public static TableQuery<Folder> Folders => Connection.Table<Folder>();
|
||||
public static TableQuery<DeletedFolder> DeletedFolders => Connection.Table<DeletedFolder>();
|
||||
public static TableQuery<Installation> Installations => Connection.Table<Installation>();
|
||||
public static TableQuery<DeletedInstallation> DeletedInstallations => Connection.Table<DeletedInstallation>();
|
||||
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()
|
||||
|
@ -31,7 +39,10 @@ public static partial class Db
|
|||
Connection.RunInTransaction(() =>
|
||||
{
|
||||
Connection.CreateTable<User>();
|
||||
Connection.CreateTable<DeletedUser>();
|
||||
Connection.CreateTable<Installation>();
|
||||
Connection.CreateTable<DeletedInstallation>();
|
||||
Connection.CreateTable<DeletedFolder>();
|
||||
Connection.CreateTable<Folder>();
|
||||
Connection.CreateTable<FolderAccess>();
|
||||
Connection.CreateTable<InstallationAccess>();
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
using System;
|
||||
using InnovEnergy.App.Backend.DataTypes;
|
||||
using MailKit.Net.Smtp;
|
||||
using MailKit;
|
||||
using MimeKit;
|
||||
|
||||
namespace InnovEnergy.App.Backend.Mailer;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
using InnovEnergy.App.Backend.Database;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace InnovEnergy.App.Backend;
|
||||
|
@ -5,11 +6,12 @@ namespace InnovEnergy.App.Backend;
|
|||
public static class Program
|
||||
{
|
||||
|
||||
// TODO: Trash
|
||||
|
||||
|
||||
public static void Main(String[] args)
|
||||
{
|
||||
//Db.CreateFakeRelations();
|
||||
Db.Init();
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
|
|
|
@ -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.Text.Json.JsonSerializer;
|
||||
|
||||
|
@ -10,15 +11,9 @@ public static class S3Access
|
|||
// they should be read from disk on each use,
|
||||
// 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
|
||||
(
|
||||
key : Deserialize<Dictionary<String, String>>(OpenRead("./Resources/urlAndKey.json"))?["ReadWriteS3Key"],
|
||||
secret: Deserialize<Dictionary<String, String>>(OpenRead("./Resources/urlAndKey.json"))?["ReadWriteS3Secret"]
|
||||
);
|
||||
public static S3Cmd ReadOnly => Deserialize<S3Cmd>(OpenRead("./Resources/s3ReadOnlyKey.json"))!;
|
||||
|
||||
|
||||
public static S3Cmd ReadWrite => Deserialize<S3Cmd>(OpenRead("./Resources/s3ReadWriteKey.json"))!;
|
||||
}
|
|
@ -1,9 +1,11 @@
|
|||
using System.Diagnostics.CodeAnalysis;
|
||||
using CliWrap;
|
||||
using CliWrap.Buffered;
|
||||
using InnovEnergy.Lib.Utils;
|
||||
|
||||
namespace InnovEnergy.App.Backend.S3;
|
||||
|
||||
[SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global")]
|
||||
public class S3Cmd
|
||||
{
|
||||
private static readonly Command Python = Cli.Wrap("python3");
|
||||
|
@ -11,21 +13,27 @@ public class S3Cmd
|
|||
private const String? S3CmdPath = "Resources/s3cmd.py";
|
||||
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 enable StringLiteralTypo
|
||||
|
||||
public S3Cmd(String? key, String? secret)
|
||||
[Obsolete("Only to be used by Json-Deserializer")] public S3Cmd()
|
||||
{
|
||||
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)
|
||||
{
|
||||
var result = await Run(bucketName, "signurl", $"+{validity.TotalSeconds}");
|
||||
|
@ -50,13 +58,20 @@ public class S3Cmd
|
|||
|
||||
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(bucketName.EnsureStartsWith(S3Prefix))
|
||||
.Concat(optionalArgs);
|
||||
|
||||
return Python
|
||||
.WithArguments(args)
|
||||
.ExecuteBufferedAsync();
|
||||
.WithArguments(args)
|
||||
.ExecuteBufferedAsync();
|
||||
}
|
||||
}
|
Binary file not shown.
Loading…
Reference in New Issue