From 06c4acf4fbb1cc048dc417f6d8efc95186697860 Mon Sep 17 00:00:00 2001 From: Malachy Byrne Date: Sat, 6 May 2023 21:31:11 +0100 Subject: [PATCH] Switched frontend urls to env variables and fixed bug in module creation --- src/PanoptesFrontend/Pages/DynamicChart.razor | 4 +++- src/PanoptesFrontend/Pages/DynamicTable.razor | 6 ++++-- src/PanoptesFrontend/Pages/ModConfig.razor | 6 ++++-- src/PanoptesFrontend/Pages/ModDisplay.razor | 6 ++++-- src/PanoptesFrontend/Pages/QueryInput.razor | 6 ++++-- src/PanoptesFrontend/Services/AccountService.cs | 12 ++++++++---- src/PanoptesFrontend/Shared/NavMenu.razor | 4 +++- src/backend/cmd/main.go | 2 ++ src/backend/go.mod | 1 + src/backend/go.sum | 2 ++ 10 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/PanoptesFrontend/Pages/DynamicChart.razor b/src/PanoptesFrontend/Pages/DynamicChart.razor index f8aa94b..cb35153 100644 --- a/src/PanoptesFrontend/Pages/DynamicChart.razor +++ b/src/PanoptesFrontend/Pages/DynamicChart.razor @@ -1,6 +1,7 @@ @using ApexCharts @using System.Collections.Generic @using PanoptesFrontend.Data; +@using System @using System.Timers @implements IDisposable @inject IHttpService httpService @@ -55,7 +56,8 @@ private async Task UpdateChartSeries() { - var response = await httpService.GetAsync($"http://localhost:10000/component/{module}/{ChartId}"); + var panoptesHost = Environment.GetEnvironmentVariable("PANOPTESHOST"); + var response = await httpService.GetAsync($"http://{panoptesHost}/component/{module}/{ChartId}"); StatsList = response.Stats; await chart.UpdateSeriesAsync(true); await InvokeAsync(() => StateHasChanged()); diff --git a/src/PanoptesFrontend/Pages/DynamicTable.razor b/src/PanoptesFrontend/Pages/DynamicTable.razor index 84f2e5b..bf4e69a 100644 --- a/src/PanoptesFrontend/Pages/DynamicTable.razor +++ b/src/PanoptesFrontend/Pages/DynamicTable.razor @@ -1,6 +1,7 @@ @using System.Linq.Dynamic.Core @inject IHttpService httpService @using PanoptesFrontend.Services +@using System @@ -65,7 +66,8 @@ private async Task Update() { - var response = await httpService.GetAsync($"http://localhost:10000/component/{module}/{TableId}"); + var panoptesHost = Environment.GetEnvironmentVariable("PANOPTESHOST"); + var response = await httpService.GetAsync($"http://{panoptesHost}/component/{module}/{TableId}"); if (response.Data != null) { @@ -74,4 +76,4 @@ } await InvokeAsync(() => StateHasChanged()); } -} \ No newline at end of file +} diff --git a/src/PanoptesFrontend/Pages/ModConfig.razor b/src/PanoptesFrontend/Pages/ModConfig.razor index bcfe846..6d8a380 100644 --- a/src/PanoptesFrontend/Pages/ModConfig.razor +++ b/src/PanoptesFrontend/Pages/ModConfig.razor @@ -4,7 +4,8 @@ @using Newtonsoft.Json @using Microsoft.AspNetCore.Components.Web @using Microsoft.JSInterop -@using System.Net; +@using System +@using System.Net @using PanoptesFrontend.Data @using PanoptesFrontend.Services @inject IHttpService httpService @@ -148,7 +149,8 @@ var config = JsonConvert.SerializeObject(ModuleConfig); Console.WriteLine(config); var payload = new StringContent(config, Encoding.UTF8, "application/json"); - await httpService.PostAsync("http://localhost:10000/create_module", ModuleConfig); + var panoptesHost = Environment.GetEnvironmentVariable("PANOPTESHOST"); + await httpService.PostAsync($"http://{panoptesHost}/create_module", ModuleConfig); } } } diff --git a/src/PanoptesFrontend/Pages/ModDisplay.razor b/src/PanoptesFrontend/Pages/ModDisplay.razor index 6f9a93f..8ba9edc 100644 --- a/src/PanoptesFrontend/Pages/ModDisplay.razor +++ b/src/PanoptesFrontend/Pages/ModDisplay.razor @@ -3,7 +3,8 @@ @using System.Net; @using PanoptesFrontend.Data @using PanoptesFrontend.Services -@using System.Text.Json; +@using System +@using System.Text.Json @using Microsoft.AspNetCore.Components.Web @inject IHttpService httpService @inject IJSRuntime JSRuntime @@ -77,7 +78,8 @@ protected async override Task OnInitializedAsync() { - var schema = await httpService.GetAsync("http://localhost:10000/" + moduleId + "/schema"); + var panoptesHost = Environment.GetEnvironmentVariable("PANOPTESHOST"); + var schema = await httpService.GetAsync($"http://{panoptesHost}/{moduleId}/schema"); tables = schema.tables; graphs = schema.graphs; } diff --git a/src/PanoptesFrontend/Pages/QueryInput.razor b/src/PanoptesFrontend/Pages/QueryInput.razor index 74bee37..7559c68 100644 --- a/src/PanoptesFrontend/Pages/QueryInput.razor +++ b/src/PanoptesFrontend/Pages/QueryInput.razor @@ -1,5 +1,6 @@ @inject IHttpService httpService @using PanoptesFrontend.Services +@using System @@ -10,7 +11,8 @@ private async Task ExecuteSqlQuery() { // Send the SQL query to your backend and handle the response - var response = await httpService.PostAsync($"http://localhost:10000/sqlquery", sqlQuery); + var panoptesHost = Environment.GetEnvironmentVariable("PANOPTESHOST"); + var response = await httpService.PostAsync($"http://{panoptesHost}/sqlquery", sqlQuery); } -} \ No newline at end of file +} diff --git a/src/PanoptesFrontend/Services/AccountService.cs b/src/PanoptesFrontend/Services/AccountService.cs index d2658cd..09feb43 100644 --- a/src/PanoptesFrontend/Services/AccountService.cs +++ b/src/PanoptesFrontend/Services/AccountService.cs @@ -2,6 +2,7 @@ using PanoptesFrontend.Data.Account; using PanoptesFrontend.Data; using Blazored.LocalStorage; using System.Text.Json; +using System; namespace PanoptesFrontend.Services; @@ -26,11 +27,13 @@ public class AccountService : IAccountService public async Task Register(AddUser model){ - await httpService.PostAsync("http://localhost:10000/user/register", model); + var panoptesHost = Environment.GetEnvironmentVariable("PANOPTESHOST"); + await httpService.PostAsync($"http://{panoptesHost}/user/register", model); } public async Task Login(LoginUser model){ - var response = await httpService.PostAsync("http://localhost:10000/user/login", model); + var panoptesHost = Environment.GetEnvironmentVariable("PANOPTESHOST"); + var response = await httpService.PostAsync($"http://panoptesHost/user/login", model); var jsonDoc = JsonDocument.Parse(response); var token = jsonDoc.RootElement.GetProperty("token").GetString(); @@ -43,7 +46,8 @@ public class AccountService : IAccountService var authtoken = await localStorage.GetItemAsStringAsync("authToken"); - await httpService.PostAsync("http://localhost:10000/user/logout", authtoken); + var panoptesHost = Environment.GetEnvironmentVariable("PANOPTESHOST"); + await httpService.PostAsync($"http://{panoptesHost}/user/logout", authtoken); await localStorage.RemoveItemAsync("authToken"); } @@ -51,4 +55,4 @@ public class AccountService : IAccountService { return await localStorage.GetItemAsStringAsync("authToken"); } -} \ No newline at end of file +} diff --git a/src/PanoptesFrontend/Shared/NavMenu.razor b/src/PanoptesFrontend/Shared/NavMenu.razor index 5ceb200..a2eb30f 100644 --- a/src/PanoptesFrontend/Shared/NavMenu.razor +++ b/src/PanoptesFrontend/Shared/NavMenu.razor @@ -1,5 +1,6 @@ @using PanoptesFrontend.Data; @using PanoptesFrontend.Services; +@using System @using System.Text.Json; @inject IHttpService httpService @@ -38,7 +39,8 @@ protected override async Task OnInitializedAsync() { - response = await httpService.GetAsync("http://localhost:10000/modules"); + var panoptesHost = Environment.GetEnvironmentVariable("PANOPTESHOST"); + response = await httpService.GetAsync($"http://{panoptesHost}/modules"); } private bool collapseNavMenu = true; diff --git a/src/backend/cmd/main.go b/src/backend/cmd/main.go index 79428f6..7b96e50 100644 --- a/src/backend/cmd/main.go +++ b/src/backend/cmd/main.go @@ -12,6 +12,7 @@ import ( "golang.org/x/crypto/bcrypt" "github.com/labstack/echo/v4" + "github.com/google/uuid" "gitlab.computing.dcu.ie/murphg62/2023-ca400-murphg62-byrnm257/src/backend/pkg/database" "gitlab.computing.dcu.ie/murphg62/2023-ca400-murphg62-byrnm257/src/backend/pkg/docker" _ "golang.org/x/mod/module" @@ -216,6 +217,7 @@ func CreateModule(c echo.Context) error { if err := c.Bind(&module); err != nil { panic(err) } + module.ID = uuid.New().String() s, _ := json.MarshalIndent(module, "", " ") fmt.Println(string(s)) mod_id := docker.CreateModule(module) diff --git a/src/backend/go.mod b/src/backend/go.mod index b727a28..5bd2a50 100644 --- a/src/backend/go.mod +++ b/src/backend/go.mod @@ -19,6 +19,7 @@ require ( github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-units v0.5.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect + github.com/google/uuid v1.3.0 // indirect github.com/labstack/gommon v0.4.0 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.17 // indirect diff --git a/src/backend/go.sum b/src/backend/go.sum index 9dd9be5..d60b189 100644 --- a/src/backend/go.sum +++ b/src/backend/go.sum @@ -17,6 +17,8 @@ github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4 github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= +github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=