This commit is contained in:
Noe 2023-07-06 09:17:52 +02:00
commit 52d3208ec7
10 changed files with 346 additions and 57 deletions

View File

@ -5,7 +5,7 @@ using InnovEnergy.App.Backend.Relations;
using InnovEnergy.Lib.Utils; using InnovEnergy.Lib.Utils;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace InnovEnergy.App.Backend.Controllers; namespace InnovEnergy.App.Backend;
using Token = String; using Token = String;
@ -81,7 +81,9 @@ public class Controller : ControllerBase
if (installation is null || !user.HasAccessTo(installation)) if (installation is null || !user.HasAccessTo(installation))
return Unauthorized(); return Unauthorized();
return installation.FillOrderNumbers().HideParentIfUserHasNoAccessToParent(user); return installation
.FillOrderNumbers()
.HideParentIfUserHasNoAccessToParent(user);
} }
[HttpGet(nameof(GetUsersWithDirectAccessToInstallation))] [HttpGet(nameof(GetUsersWithDirectAccessToInstallation))]

View File

@ -15,8 +15,9 @@ public class Installation : TreeNode
public Double Lat { get; set; } public Double Lat { get; set; }
public Double Long { get; set; } public Double Long { get; set; }
public String S3Bucket { get; set; } = ""; public String S3Bucket { get; set; } = "";
public String S3KeySecret { get; set; } = ""; public String S3Region { get; set; } = "";
public String S3Provider { get; set; } = "";
public String S3Key { get; set; } = "";
public String S3Secret { get; set; } = "";
} }

View File

@ -0,0 +1,48 @@
using CliWrap;
using CliWrap.Buffered;
using InnovEnergy.Lib.Utils;
namespace InnovEnergy.App.Backend.DataTypes.Methods;
public static class ExoCmd
{
private static readonly Command Exo = Cli.Wrap("exo");
private const String ConfigFile = "./exoscale.toml";
public static async Task<(String key, String secret)> CreateKey(this Installation installation)
{
//if (installation.Id != 1) return "help"; //Todo remove me I am for debugging
var preParse = await Exo
.WithArguments("iam access-key create " + installation.BucketName()
+ " --operation get-sos-object"
+ " --resource sos/bucket:" + installation.BucketName()
+ " -C " + ConfigFile
+ " -O text")
.ExecuteBufferedAsync();
var key = preParse.StandardOutput.Split("\t")[2];
var secret = preParse.StandardOutput.Split("\t")[3];
return (key, secret);
//return $"{key};{secret}";
}
public static async void RevokeKey(this Installation installation)
{
try
{
await Exo
.WithArguments("iam access-key revoke " + installation.S3Key + " -f " + " -C " + ConfigFile)
.ExecuteAsync();
}
catch
{
// TODO
("Failed to revoke key for installation " + installation.Name).WriteLine();
}
}
}

View File

@ -1,5 +1,3 @@
using CliWrap;
using CliWrap.Buffered;
using InnovEnergy.App.Backend.Database; using InnovEnergy.App.Backend.Database;
using InnovEnergy.App.Backend.S3; using InnovEnergy.App.Backend.S3;
using InnovEnergy.Lib.Utils; using InnovEnergy.Lib.Utils;
@ -19,7 +17,11 @@ public static class InstallationMethods
public static async Task<Boolean> RenewS3BucketUrl(this Installation installation) public static async Task<Boolean> RenewS3BucketUrl(this Installation installation)
{ {
installation.RevokeKey(); installation.RevokeKey();
installation.S3KeySecret = await installation.CreateKey(); var (key, secret) = await installation.CreateKey();
installation.S3Key = key;
installation.S3Secret = secret;
return Db.Update(installation); return Db.Update(installation);
} }
@ -124,41 +126,4 @@ public static class InstallationMethods
return installation; return installation;
} }
} }
public static class ExoCmd
{
private static readonly Command Exo = Cli.Wrap("exo");
private static String ConfigFile = "./exoscale.toml";
public static async Task<String> CreateKey(this Installation installation)
{
if (installation.Id != 1) return "help"; //Todo remove me I am for debugging
var preParse = await Exo
.WithArguments("iam access-key create " + installation.BucketName()
+ " --operation get-sos-object"
+ " --resource sos/bucket:" + installation.BucketName()
+ " -C " + ConfigFile
+ " -O text")
.ExecuteBufferedAsync();
return preParse.StandardOutput.Split("\t")[2] + ";" + preParse.StandardOutput.Split("\t")[3];
}
public static async void RevokeKey(this Installation installation)
{
try
{
await Exo
.WithArguments("iam access-key revoke " + installation.S3KeySecret.Split(";", 2)[0] + " -f " + " -C " + ConfigFile)
.ExecuteAsync();
}
catch
{
// todo Fill me there is no key for this installation
}
}
}

Binary file not shown.

View File

@ -0,0 +1,136 @@
{
"Information": {
"defaultMessage": "Information"
},
"addNewChild": {
"defaultMessage": "Neues Kind hinzufügen"
},
"addNewDialogButton": {
"defaultMessage": "Neue Dialogschaltfläche hinzufügen"
},
"addUser": {
"defaultMessage": "Nutzer erstellen"
},
"alarms": {
"defaultMessage": "Alarme"
},
"applyChanges": {
"defaultMessage": "Änderungen speichern"
},
"country": {
"defaultMessage": "Land"
},
"createNewFolder": {
"defaultMessage": "Neuen Ordner erstellen"
},
"createNewUser": {
"defaultMessage": "Neuen Nutzer erstellen"
},
"customerName": {
"defaultMessage": "Kundenname"
},
"email": {
"defaultMessage": "Email"
},
"english": {
"defaultMessage": "Englisch"
},
"error": {
},
"folder": {
"defaultMessage": "Ordner"
},
"german": {
"defaultMessage": "Deutsch"
},
"groupTabs": {
"defaultMessage": "Gruppen"
},
"groupTree": {
"defaultMessage": "Gruppenbaum"
},
"information": {
"defaultMessage": "Information"
},
"inheritedAccess": {
"defaultMessage": "Vererbter Zugriff von"
},
"installation": {
"defaultMessage": "Installation"
},
"installationTabs": {
"defaultMessage": "Installationen"
},
"installations": {
"defaultMessage": "Installationen"
},
"lastWeek": {
"defaultMessage": "Letzte Woche"
},
"location": {
"defaultMessage": "Standort"
},
"log": {
"defaultMessage": "Logbuch"
},
"logout": {
"defaultMessage": "Abmelden"
},
"makeASelection": {
"defaultMessage": "Bitte wählen Sie links eine Auswahl"
},
"manageAccess": {
"defaultMessage": "Zugriff verwalten"
},
"move": {
"defaultMessage": "Verschieben"
},
"moveTo": {
"defaultMessage": "Verschieben zu"
},
"moveTree": {
"defaultMessage": "Baum verschieben"
},
"name": {
"defaultMessage": "Name"
},
"navigationTabs": {
"defaultMessage": "Navigation"
},
"orderNumbers": {
"defaultMessage": "Bestellnummer"
},
"region": {
"defaultMessage": "Region"
},
"requiredLocation": {
"defaultMessage": "Standort ist erforderlich"
},
"requiredName": {
"defaultMessage": "Name ist erforderlich"
},
"requiredRegion": {
"defaultMessage": "Region ist erforderlich"
},
"search": {
"defaultMessage": "Suche"
},
"submit": {
"defaultMessage": "Senden"
},
"updateFolderErrorMessage": {
"defaultMessage": "Fehler, Ordner kann nicht aktualisiert werden"
},
"updatedSuccessfully": {
"defaultMessage": "Erfolgreich aktualisiert"
},
"user": {
"defaultMessage": "Nutzer"
},
"userTabs": {
"defaultMessage": "Nutzer"
},
"users": {
"defaultMessage": "Nutzer"
}
}

View File

@ -0,0 +1,136 @@
{
"Information": {
"defaultMessage": "Informations"
},
"addNewChild": {
"defaultMessage": "Ajouter un nouvel enfant"
},
"addNewDialogButton": {
"defaultMessage": "Ajouter un nouveau bouton de dialogue"
},
"addUser": {
"defaultMessage": "Créer un utilisateur"
},
"alarms": {
"defaultMessage": "Alarmes"
},
"applyChanges": {
"defaultMessage": "Appliquer les modifications"
},
"country": {
"defaultMessage": "Pays"
},
"createNewFolder": {
"defaultMessage": "Créer un nouveau dossier"
},
"createNewUser": {
"defaultMessage": "Créer un nouvel utilisateur"
},
"customerName": {
"defaultMessage": "Nom du client"
},
"email": {
"defaultMessage": "E-mail"
},
"english": {
"defaultMessage": "Anglais"
},
"error": {
},
"folder": {
"defaultMessage": "Dossier"
},
"german": {
"defaultMessage": "Allemand"
},
"groupTabs": {
"defaultMessage": "Onglets de groupe"
},
"groupTree": {
"defaultMessage": "Arbre de groupe"
},
"information": {
"defaultMessage": "Informations"
},
"inheritedAccess": {
"defaultMessage": "Accès hérité de"
},
"installation": {
"defaultMessage": "Installation"
},
"installationTabs": {
"defaultMessage": "Onglets d'installation"
},
"installations": {
"defaultMessage": "Installations"
},
"lastWeek": {
"defaultMessage": "La semaine dernière"
},
"location": {
"defaultMessage": "Localisation"
},
"log": {
"defaultMessage": "Journal"
},
"logout": {
"defaultMessage": "Déconnexion"
},
"makeASelection": {
"defaultMessage": "Veuillez faire une sélection à gauche"
},
"manageAccess": {
"defaultMessage": "Gérer l'accès"
},
"move": {
"defaultMessage": "Déplacer"
},
"moveTo": {
"defaultMessage": "Déplacer à"
},
"moveTree": {
"defaultMessage": "Déplacer l'arbre"
},
"name": {
"defaultMessage": "Nom"
},
"navigationTabs": {
"defaultMessage": "Onglets de navigation"
},
"orderNumbers": {
"defaultMessage": "Numéro de commande"
},
"region": {
"defaultMessage": "Région"
},
"requiredLocation": {
"defaultMessage": "L'emplacement est requis"
},
"requiredName": {
"defaultMessage": "Le nom est obligatoire"
},
"requiredRegion": {
"defaultMessage": "La région est obligatoire"
},
"search": {
"defaultMessage": "Recherche"
},
"submit": {
"defaultMessage": "Soumettre"
},
"updateFolderErrorMessage": {
"defaultMessage": "Une erreur s'est produite, impossible de mettre à jour le dossier."
},
"updatedSuccessfully": {
"defaultMessage": "Mise à jour réussie"
},
"user": {
"defaultMessage": "Utilisateur"
},
"userTabs": {
"defaultMessage": "Onglets utilisateurs"
},
"users": {
"defaultMessage": "Utilisateurs"
}
}

View File

@ -29,9 +29,8 @@ const s3Access = new S3Access(
"saliomameiringen", "saliomameiringen",
"sos-ch-dk-2", "sos-ch-dk-2",
"exo.io", "exo.io",
"EXO464a9ff62fdfa407aa742855", "EXO464a9ff62fdfa407aa742855", // key
"f2KtCWN4EHFqtvH2kotdyI0w5SjjdHVPAADdcD3ik8g", "f2KtCWN4EHFqtvH2kotdyI0w5SjjdHVPAADdcD3ik8g" // secret
""
); );
export const fetchData = ( export const fetchData = (

View File

@ -10,8 +10,7 @@ export class S3Access
readonly region: string, readonly region: string,
readonly provider: string, readonly provider: string,
readonly key: string, readonly key: string,
readonly secret: string, readonly secret: string
readonly contentType: string
) )
{} {}
@ -46,8 +45,7 @@ export class S3Access
s3Path, s3Path,
date, date,
this.key, this.key,
this.secret, this.secret
this.contentType
); );
} }
} }
@ -58,7 +56,7 @@ function createAuthorizationHeader(method: string,
date: string, date: string,
s3Key: string, s3Key: string,
s3Secret: string, s3Secret: string,
contentType: string, contentType: string = "",
md5Hash: string = "") md5Hash: string = "")
{ {
// StringToSign = HTTP-Verb + "\n" + // StringToSign = HTTP-Verb + "\n" +

View File

@ -11,12 +11,16 @@ export interface I_Installation {
orderNumbers: string; orderNumbers: string;
lat: number; lat: number;
long: number; long: number;
s3Bucket: string;
id: number; id: number;
name: string; name: string;
information: string; information: string;
parentId: number; parentId: number;
s3Url: string;
s3Bucket: string;
s3Region: string;
s3Provider: string;
s3Key: string;
s3Secret: string;
} }
export interface I_Folder { export interface I_Folder {