Modified docker config format sent by frontend

This commit is contained in:
Malachy Byrne 2023-05-05 14:13:46 +01:00
parent 50d73cbd71
commit 68aebf085e
Signed by: malmal200
GPG Key ID: EC21443030A655D9
4 changed files with 49 additions and 21 deletions

2
src/PanoptesFrontend/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.dll
*.cache

View File

@ -1,5 +1,10 @@
public class ModuleConfig {
public string ImageName {get; set;}
public Dictionary<string, string> Environment {get; set;} = new Dictionary<string, string>();
public Dictionary<string, string> Volumes {get; set;} = new Dictionary<string, string>();
}
public string id {get; set;}
public string image {get; set;}
public string name {get; set;}
public string user {get; set;} = "1000:1000";
public List<Dictionary<string, string>> env {get; set;} = new List<Dictionary<string, string>>{};
public List<Dictionary<string, string>> volumes {get; set;} = new List<Dictionary<string, string>>{};
public string urls_allowed {get; set;} = "*";
public bool internal_access {get; set;} = true;
}

View File

@ -1,5 +1,7 @@
@page "/module-config"
@using System.Text.Json
@using System.Text
@using Newtonsoft.Json
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.JSInterop
@using System.Net;
@ -12,8 +14,14 @@
<div class="row">
<div class="col-12">
<div class="form-group">
<label for="imageName">Image Name</label>
<input type="text" class="form-control" id="imageName" name="ImageName" @bind="ModuleConfig.ImageName" />
<label for="name">Name</label>
<input type="text" class="form-control" id="name" name="name" @bind="ModuleConfig.name" />
<label for="image">Image</label>
<input type="text" class="form-control" id="image" name="image" @bind="ModuleConfig.image" />
<label for="user">User</label>
<input type="text" class="form-control" id="user" name="user" @bind="ModuleConfig.user" />
<label for="internal">Internal Only</label>
<input type="checkbox" id="internal" name="internal" @bind="ModuleConfig.internal_access" />
</div>
</div>
</div>
@ -44,11 +52,11 @@
</tr>
</thead>
<tbody>
@foreach (var kvp in ModuleConfig.Environment)
@for (int i = 0; i < ModuleConfig.env.Count; i++)
{
<tr>
<td>@kvp.Key</td>
<td>@kvp.Value</td>
<td>@ModuleConfig.env[i]["var"]</td>
<td>@ModuleConfig.env[i]["val"]</td>
</tr>
}
</tbody>
@ -79,11 +87,11 @@
</tr>
</thead>
<tbody>
@foreach (var kvp in ModuleConfig.Volumes)
@foreach (Dictionary<string, string> kvp in ModuleConfig.volumes)
{
<tr>
<td>@kvp.Key</td>
<td>@kvp.Value</td>
<td>@kvp["val"]</td>
<td>@kvp["var"]</td>
</tr>
}
</tbody>
@ -112,14 +120,24 @@
private void AddKeyValuePair1()
{
ModuleConfig.Environment.Add(Key1, Value1);
var envs = new Dictionary<string, string>()
{
{ "var", Key1 },
{ "val", Value1 }
};
ModuleConfig.env.Add(envs);
Key1 = "";
Value1 = "";
}
private void AddKeyValuePair2()
{
ModuleConfig.Volumes.Add(Key2, Value2);
var vols = new Dictionary<string, string>()
{
{ "var", Key2 },
{ "val", Value2 }
};
ModuleConfig.volumes.Add(vols);
Key2 = "";
Value2 = "";
}
@ -127,9 +145,10 @@
private async void SubmitForm()
{
// Log ModuleConfig object to console and send to backend
var config = JsonSerializer.Serialize(ModuleConfig);
var config = JsonConvert.SerializeObject(ModuleConfig);
Console.WriteLine(config);
await httpService.PostAsync("http://localhost:8080/config_module", config);
var payload = new StringContent(config, Encoding.UTF8, "application/json");
await httpService.PostAsync("http://localhost:10000/create_module", ModuleConfig);
}
}
}
}

View File

@ -6,7 +6,7 @@ import (
"fmt"
"io/ioutil"
"log"
"bytes"
//"bytes"
"net/http"
"github.com/dgrijalva/jwt-go"
"golang.org/x/crypto/bcrypt"
@ -192,10 +192,12 @@ func LogoutUser() echo.HandlerFunc {
}
func CreateModule(c echo.Context) error {
buf := new(bytes.Buffer)
buf.ReadFrom(c.Request().Body)
var module docker.Module
json.Unmarshal(buf.Bytes(), &module)
if err := c.Bind(&module); err != nil {
panic(err)
}
s, _ := json.MarshalIndent(module, "", " ")
fmt.Println(string(s))
mod_id := docker.CreateModule(module)
stmt, err := db.Prepare(`INSERT INTO Module (name, container_name) VALUES ($1, $2);`)
if err != nil {