Modified docker config format sent by frontend
This commit is contained in:
parent
50d73cbd71
commit
68aebf085e
2
src/PanoptesFrontend/.gitignore
vendored
Normal file
2
src/PanoptesFrontend/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*.dll
|
||||||
|
*.cache
|
||||||
@ -1,5 +1,10 @@
|
|||||||
public class ModuleConfig {
|
public class ModuleConfig {
|
||||||
public string ImageName {get; set;}
|
public string id {get; set;}
|
||||||
public Dictionary<string, string> Environment {get; set;} = new Dictionary<string, string>();
|
public string image {get; set;}
|
||||||
public Dictionary<string, string> Volumes {get; set;} = new Dictionary<string, string>();
|
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;
|
||||||
}
|
}
|
||||||
@ -1,5 +1,7 @@
|
|||||||
@page "/module-config"
|
@page "/module-config"
|
||||||
@using System.Text.Json
|
@using System.Text.Json
|
||||||
|
@using System.Text
|
||||||
|
@using Newtonsoft.Json
|
||||||
@using Microsoft.AspNetCore.Components.Web
|
@using Microsoft.AspNetCore.Components.Web
|
||||||
@using Microsoft.JSInterop
|
@using Microsoft.JSInterop
|
||||||
@using System.Net;
|
@using System.Net;
|
||||||
@ -12,8 +14,14 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="imageName">Image Name</label>
|
<label for="name">Name</label>
|
||||||
<input type="text" class="form-control" id="imageName" name="ImageName" @bind="ModuleConfig.ImageName" />
|
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -44,11 +52,11 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@foreach (var kvp in ModuleConfig.Environment)
|
@for (int i = 0; i < ModuleConfig.env.Count; i++)
|
||||||
{
|
{
|
||||||
<tr>
|
<tr>
|
||||||
<td>@kvp.Key</td>
|
<td>@ModuleConfig.env[i]["var"]</td>
|
||||||
<td>@kvp.Value</td>
|
<td>@ModuleConfig.env[i]["val"]</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
</tbody>
|
</tbody>
|
||||||
@ -79,11 +87,11 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@foreach (var kvp in ModuleConfig.Volumes)
|
@foreach (Dictionary<string, string> kvp in ModuleConfig.volumes)
|
||||||
{
|
{
|
||||||
<tr>
|
<tr>
|
||||||
<td>@kvp.Key</td>
|
<td>@kvp["val"]</td>
|
||||||
<td>@kvp.Value</td>
|
<td>@kvp["var"]</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
</tbody>
|
</tbody>
|
||||||
@ -112,14 +120,24 @@
|
|||||||
|
|
||||||
private void AddKeyValuePair1()
|
private void AddKeyValuePair1()
|
||||||
{
|
{
|
||||||
ModuleConfig.Environment.Add(Key1, Value1);
|
var envs = new Dictionary<string, string>()
|
||||||
|
{
|
||||||
|
{ "var", Key1 },
|
||||||
|
{ "val", Value1 }
|
||||||
|
};
|
||||||
|
ModuleConfig.env.Add(envs);
|
||||||
Key1 = "";
|
Key1 = "";
|
||||||
Value1 = "";
|
Value1 = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddKeyValuePair2()
|
private void AddKeyValuePair2()
|
||||||
{
|
{
|
||||||
ModuleConfig.Volumes.Add(Key2, Value2);
|
var vols = new Dictionary<string, string>()
|
||||||
|
{
|
||||||
|
{ "var", Key2 },
|
||||||
|
{ "val", Value2 }
|
||||||
|
};
|
||||||
|
ModuleConfig.volumes.Add(vols);
|
||||||
Key2 = "";
|
Key2 = "";
|
||||||
Value2 = "";
|
Value2 = "";
|
||||||
}
|
}
|
||||||
@ -127,9 +145,10 @@
|
|||||||
private async void SubmitForm()
|
private async void SubmitForm()
|
||||||
{
|
{
|
||||||
// Log ModuleConfig object to console and send to backend
|
// Log ModuleConfig object to console and send to backend
|
||||||
var config = JsonSerializer.Serialize(ModuleConfig);
|
var config = JsonConvert.SerializeObject(ModuleConfig);
|
||||||
Console.WriteLine(config);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -6,7 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"bytes"
|
//"bytes"
|
||||||
"net/http"
|
"net/http"
|
||||||
"github.com/dgrijalva/jwt-go"
|
"github.com/dgrijalva/jwt-go"
|
||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
@ -192,10 +192,12 @@ func LogoutUser() echo.HandlerFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func CreateModule(c echo.Context) error {
|
func CreateModule(c echo.Context) error {
|
||||||
buf := new(bytes.Buffer)
|
|
||||||
buf.ReadFrom(c.Request().Body)
|
|
||||||
var module docker.Module
|
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)
|
mod_id := docker.CreateModule(module)
|
||||||
stmt, err := db.Prepare(`INSERT INTO Module (name, container_name) VALUES ($1, $2);`)
|
stmt, err := db.Prepare(`INSERT INTO Module (name, container_name) VALUES ($1, $2);`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user