diff --git a/csharp/App/Backend/DataTypes/DeletedFolder.cs b/csharp/App/Backend/DataTypes/DeletedFolder.cs index a0193ab42..5fb1e5951 100644 --- a/csharp/App/Backend/DataTypes/DeletedFolder.cs +++ b/csharp/App/Backend/DataTypes/DeletedFolder.cs @@ -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 \ No newline at end of file diff --git a/csharp/App/Backend/DataTypes/DeletedInstallation.cs b/csharp/App/Backend/DataTypes/DeletedInstallation.cs index eb0846056..9c7f3d4d4 100644 --- a/csharp/App/Backend/DataTypes/DeletedInstallation.cs +++ b/csharp/App/Backend/DataTypes/DeletedInstallation.cs @@ -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; } = ""; - } \ No newline at end of file diff --git a/csharp/App/Backend/DataTypes/DeletedUser.cs b/csharp/App/Backend/DataTypes/DeletedUser.cs index 4f82c06a8..7d7a5cad2 100644 --- a/csharp/App/Backend/DataTypes/DeletedUser.cs +++ b/csharp/App/Backend/DataTypes/DeletedUser.cs @@ -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 } \ No newline at end of file diff --git a/csharp/App/Backend/DataTypes/Methods/Installation.cs b/csharp/App/Backend/DataTypes/Methods/Installation.cs index 3dc908d09..e1a0c766f 100644 --- a/csharp/App/Backend/DataTypes/Methods/Installation.cs +++ b/csharp/App/Backend/DataTypes/Methods/Installation.cs @@ -20,8 +20,7 @@ public static class InstallationMethods } public static async Task RenewS3BucketUrl(this Installation installation, TimeSpan validity) - { - installation.S3Url = + { installation.S3Url = await S3Access.ReadOnly.SignUrl(installation.BucketName(), validity); return Db.Update(installation); } diff --git a/csharp/App/Backend/Database/Db.cs b/csharp/App/Backend/Database/Db.cs index ebdab555c..086ca0d20 100644 --- a/csharp/App/Backend/Database/Db.cs +++ b/csharp/App/Backend/Database/Db.cs @@ -16,14 +16,22 @@ public static partial class Db private static SQLiteConnection Connection { get; } = new SQLiteConnection(DbPath); - public static TableQuery Sessions => Connection.Table(); - public static TableQuery Folders => Connection.Table(); - public static TableQuery Installations => Connection.Table(); - public static TableQuery Users => Connection.Table(); - public static TableQuery FolderAccess => Connection.Table(); - public static TableQuery InstallationAccess => Connection.Table(); + public static TableQuery Sessions => Connection.Table(); + public static TableQuery Folders => Connection.Table(); + public static TableQuery DeletedFolders => Connection.Table(); + public static TableQuery Installations => Connection.Table(); + public static TableQuery DeletedInstallations => Connection.Table(); + public static TableQuery Users => Connection.Table(); + public static TableQuery DeletedUsers => Connection.Table(); + public static TableQuery FolderAccess => Connection.Table(); + public static TableQuery InstallationAccess => Connection.Table(); + public static void Init() + { + } + + static Db() { // on startup create/migrate tables @@ -31,7 +39,10 @@ public static partial class Db Connection.RunInTransaction(() => { Connection.CreateTable(); + Connection.CreateTable(); Connection.CreateTable(); + Connection.CreateTable(); + Connection.CreateTable(); Connection.CreateTable(); Connection.CreateTable(); Connection.CreateTable(); diff --git a/csharp/App/Backend/Mailer/Mailer.cs b/csharp/App/Backend/Mailer/Mailer.cs index b64a01a17..3d038fe2b 100644 --- a/csharp/App/Backend/Mailer/Mailer.cs +++ b/csharp/App/Backend/Mailer/Mailer.cs @@ -1,7 +1,5 @@ -using System; using InnovEnergy.App.Backend.DataTypes; using MailKit.Net.Smtp; -using MailKit; using MimeKit; namespace InnovEnergy.App.Backend.Mailer; diff --git a/csharp/App/Backend/Program.cs b/csharp/App/Backend/Program.cs index 4a24d1aa7..ca4cb8655 100644 --- a/csharp/App/Backend/Program.cs +++ b/csharp/App/Backend/Program.cs @@ -1,3 +1,4 @@ +using InnovEnergy.App.Backend.Database; using Microsoft.OpenApi.Models; namespace InnovEnergy.App.Backend; @@ -5,12 +6,13 @@ 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); builder.Services.AddControllers(); diff --git a/csharp/App/Backend/Resources/s3ReadOnlyKey.json b/csharp/App/Backend/Resources/s3ReadOnlyKey.json new file mode 100644 index 000000000..b9f1df236 --- /dev/null +++ b/csharp/App/Backend/Resources/s3ReadOnlyKey.json @@ -0,0 +1,4 @@ +{ + "Key": "EXO44d2979c8e570eae81ead564", + "Secret": "55MAqyO_FqUmh7O64VIO0egq50ERn_WIAWuc2QC44QU" +} \ No newline at end of file diff --git a/csharp/App/Backend/Resources/s3ReadWriteKey.json b/csharp/App/Backend/Resources/s3ReadWriteKey.json new file mode 100644 index 000000000..c93b2a7c0 --- /dev/null +++ b/csharp/App/Backend/Resources/s3ReadWriteKey.json @@ -0,0 +1,4 @@ +{ + "Key": "EXO87ca85e29dd412f1238f1cf0", + "Secret": "-T9TAqy9a3-0-xj7HKsFFJOCcxfRpcnL6OW5oOrOcWU" +} \ No newline at end of file diff --git a/csharp/App/Backend/S3/S3Access.cs b/csharp/App/Backend/S3/S3Access.cs index 912997a18..b9705ee81 100644 --- a/csharp/App/Backend/S3/S3Access.cs +++ b/csharp/App/Backend/S3/S3Access.cs @@ -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>(OpenRead("./Resources/urlAndKey.json"))?["ReadOnlyS3Key"], - secret: Deserialize>(OpenRead("./Resources/urlAndKey.json"))?["ReadOnlyS3Secret"] - ); - public static S3Cmd ReadWrite { get; } = new S3Cmd - ( - key : Deserialize>(OpenRead("./Resources/urlAndKey.json"))?["ReadWriteS3Key"], - secret: Deserialize>(OpenRead("./Resources/urlAndKey.json"))?["ReadWriteS3Secret"] - ); + public static S3Cmd ReadOnly => Deserialize(OpenRead("./Resources/s3ReadOnlyKey.json"))!; + + + public static S3Cmd ReadWrite => Deserialize(OpenRead("./Resources/s3ReadWriteKey.json"))!; } \ No newline at end of file diff --git a/csharp/App/Backend/S3/S3Cmd.cs b/csharp/App/Backend/S3/S3Cmd.cs index 8b2ad3e05..f3fd9160a 100644 --- a/csharp/App/Backend/S3/S3Cmd.cs +++ b/csharp/App/Backend/S3/S3Cmd.cs @@ -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,20 +13,26 @@ 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 SignUrl(String bucketName, TimeSpan validity) { @@ -50,13 +58,20 @@ public class S3Cmd private Task 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(); } } \ No newline at end of file diff --git a/csharp/App/Backend/db.sqlite b/csharp/App/Backend/db.sqlite index d79310ab5..ba4d77e62 100644 Binary files a/csharp/App/Backend/db.sqlite and b/csharp/App/Backend/db.sqlite differ