feat: trocar configurações de certificado
Agora a emissão e renovação de certificado é automática.
This commit is contained in:
@@ -1,2 +1,3 @@
|
|||||||
dist
|
dist
|
||||||
config.toml
|
config.toml
|
||||||
|
main
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ func GenerateConfigTOML(cv ConfigValues) (string, error) {
|
|||||||
// [server]
|
// [server]
|
||||||
sb.WriteString("# Server Configuration\n")
|
sb.WriteString("# Server Configuration\n")
|
||||||
sb.WriteString("[server]\n")
|
sb.WriteString("[server]\n")
|
||||||
sb.WriteString("port = 8080\n")
|
sb.WriteString(fmt.Sprintf("port = %s\n", cv.Server["port"]))
|
||||||
sb.WriteString(fmt.Sprintf("timeout_seconds = %s\n", cv.Server["timeout"]))
|
sb.WriteString(fmt.Sprintf("timeout_seconds = %s\n", cv.Server["timeout"]))
|
||||||
sb.WriteString(fmt.Sprintf("environment = %q\n", cv.Server["environment"]))
|
sb.WriteString(fmt.Sprintf("environment = %q\n", cv.Server["environment"]))
|
||||||
sb.WriteString("\n")
|
sb.WriteString("\n")
|
||||||
@@ -31,18 +31,16 @@ func GenerateConfigTOML(cv ConfigValues) (string, error) {
|
|||||||
sb.WriteString("# Certificate Options\n")
|
sb.WriteString("# Certificate Options\n")
|
||||||
sb.WriteString("[certificate]\n")
|
sb.WriteString("[certificate]\n")
|
||||||
sb.WriteString(fmt.Sprintf("mapped_dir = %q\n", cv.Cert["cert_dir_path"]))
|
sb.WriteString(fmt.Sprintf("mapped_dir = %q\n", cv.Cert["cert_dir_path"]))
|
||||||
sb.WriteString(fmt.Sprintf("cert_path = %q\n", "/app/certs/"+cv.Cert["cert_name"]))
|
sb.WriteString("cert_path = \"/app/certs/client.crt\"\n")
|
||||||
sb.WriteString(fmt.Sprintf("key_path = %q\n", "/app/certs/"+cv.Cert["key_name"]))
|
sb.WriteString("key_path = \"/app/certs/client.key\"\n")
|
||||||
sb.WriteString(fmt.Sprintf("ca_path = %q\n", "/app/certs/"+cv.Cert["ca_name"]))
|
sb.WriteString("ca_path = \"/app/certs/ca.crt\"\n")
|
||||||
sb.WriteString(fmt.Sprintf("server_name = %q\n", cv.Cert["server_name"]))
|
|
||||||
sb.WriteString("\n")
|
sb.WriteString("\n")
|
||||||
|
|
||||||
// [application] — hardcoded / pre-defined
|
// [application]
|
||||||
sb.WriteString("# Pre-defined options\n")
|
|
||||||
sb.WriteString("[application]\n")
|
sb.WriteString("[application]\n")
|
||||||
sb.WriteString("erp = \"TOTVS\"\n")
|
sb.WriteString("erp = \"TOTVS\"\n")
|
||||||
sb.WriteString("central_server_url = \"https://warden:8080\"\n")
|
sb.WriteString(fmt.Sprintf("central_server_url = %q\n", cv.Application["central_server_url"]))
|
||||||
sb.WriteString("api_key = \"super secreto\"\n")
|
sb.WriteString(fmt.Sprintf("enrollment_token = %q\n", cv.Application["enrollment_token"]))
|
||||||
sb.WriteString("\n")
|
sb.WriteString("\n")
|
||||||
|
|
||||||
// [log] — hardcoded defaults
|
// [log] — hardcoded defaults
|
||||||
|
|||||||
+31
-46
@@ -3,7 +3,6 @@ package tui
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"charm.land/bubbles/v2/spinner"
|
"charm.land/bubbles/v2/spinner"
|
||||||
@@ -31,6 +30,7 @@ type Model struct {
|
|||||||
|
|
||||||
loginForm FormStep
|
loginForm FormStep
|
||||||
wireguardForm FormStep
|
wireguardForm FormStep
|
||||||
|
appForm FormStep
|
||||||
serverForm FormStep
|
serverForm FormStep
|
||||||
dbForm FormStep
|
dbForm FormStep
|
||||||
certForm FormStep
|
certForm FormStep
|
||||||
@@ -50,11 +50,12 @@ type DockerLoginData struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ConfigValues struct {
|
type ConfigValues struct {
|
||||||
Login map[string]string
|
Login map[string]string
|
||||||
Wireguard map[string]string
|
Wireguard map[string]string
|
||||||
Server map[string]string
|
Server map[string]string
|
||||||
Database map[string]string
|
Database map[string]string
|
||||||
Cert map[string]string
|
Cert map[string]string
|
||||||
|
Application map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
type AppConfig struct {
|
type AppConfig struct {
|
||||||
@@ -70,12 +71,12 @@ type AppConfig struct {
|
|||||||
MinConns int64 `toml:"min_conns"`
|
MinConns int64 `toml:"min_conns"`
|
||||||
} `toml:"database"`
|
} `toml:"database"`
|
||||||
Certificates struct {
|
Certificates struct {
|
||||||
DirPath string `toml:"mapped_dir"`
|
DirPath string `toml:"mapped_dir"`
|
||||||
CertName string `toml:"cert_path"`
|
|
||||||
KeyName string `toml:"key_path"`
|
|
||||||
CAName string `toml:"ca_path"`
|
|
||||||
ServerName string `toml:"server_name"`
|
|
||||||
} `toml:"certificate"`
|
} `toml:"certificate"`
|
||||||
|
Application struct {
|
||||||
|
CentralServerURL string `toml:"central_server_url"`
|
||||||
|
EnrollmentToken string `toml:"enrollment_token"`
|
||||||
|
} `toml:"application"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadConfig() AppConfig {
|
func loadConfig() AppConfig {
|
||||||
@@ -91,10 +92,8 @@ func loadConfig() AppConfig {
|
|||||||
config.Database.MinConns = 2
|
config.Database.MinConns = 2
|
||||||
|
|
||||||
config.Certificates.DirPath = "/caminho/para/diretorio"
|
config.Certificates.DirPath = "/caminho/para/diretorio"
|
||||||
config.Certificates.CertName = "certificado.crt"
|
|
||||||
config.Certificates.KeyName = "chave.key"
|
config.Application.CentralServerURL = "https://servidor:8443"
|
||||||
config.Certificates.CAName = "chaveCA.crt"
|
|
||||||
config.Certificates.ServerName = "client"
|
|
||||||
|
|
||||||
_, err := os.Stat("config.toml")
|
_, err := os.Stat("config.toml")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@@ -103,12 +102,6 @@ func loadConfig() AppConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
config.Certificates.CertName = filepath.Base(config.Certificates.CertName)
|
|
||||||
config.Certificates.KeyName = filepath.Base(config.Certificates.KeyName)
|
|
||||||
config.Certificates.CAName = filepath.Base(config.Certificates.CAName)
|
|
||||||
}
|
|
||||||
|
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,37 +224,29 @@ func InitialModel() Model {
|
|||||||
Type: FieldTypeNumber,
|
Type: FieldTypeNumber,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
certForm: NewFormStep("Certificado", []FormField{
|
appForm: NewFormStep("Aplicação", []FormField{
|
||||||
{
|
{
|
||||||
Id: "cert_dir_path",
|
Id: "central_server_url",
|
||||||
Label: "Caminho para o diretório dos certificados",
|
Label: "URL do Servidor Central",
|
||||||
Placeholder: "/caminho/para/diretorio",
|
Placeholder: "https://servidor:8443",
|
||||||
Default: cfg.Certificates.DirPath,
|
Default: cfg.Application.CentralServerURL,
|
||||||
Type: FieldTypeText,
|
Type: FieldTypeText,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Id: "cert_name",
|
Id: "enrollment_token",
|
||||||
Label: "Nome do arquivo do certificado",
|
Label: "Token de Inscrição",
|
||||||
Default: cfg.Certificates.CertName,
|
Placeholder: "token gerado no painel web",
|
||||||
Type: FieldTypeText,
|
Default: cfg.Application.EnrollmentToken,
|
||||||
|
Type: FieldTypeText,
|
||||||
},
|
},
|
||||||
|
}),
|
||||||
|
certForm: NewFormStep("Certificado", []FormField{
|
||||||
{
|
{
|
||||||
Id: "key_name",
|
Id: "cert_dir_path",
|
||||||
Label: "Nome do arquivo da chave",
|
Label: "Diretório para armazenar certificados",
|
||||||
Default: cfg.Certificates.KeyName,
|
Placeholder: "/caminho/para/diretorio",
|
||||||
Type: FieldTypeText,
|
Default: cfg.Certificates.DirPath,
|
||||||
},
|
Type: FieldTypeText,
|
||||||
{
|
|
||||||
Id: "ca_name",
|
|
||||||
Label: "Nome do arquivo da autoridade certificadora",
|
|
||||||
Default: cfg.Certificates.CAName,
|
|
||||||
Type: FieldTypeText,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Id: "server_name",
|
|
||||||
Label: "Nome do servidor",
|
|
||||||
Default: cfg.Certificates.ServerName,
|
|
||||||
Type: FieldTypeText,
|
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
spinner: s,
|
spinner: s,
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ const (
|
|||||||
StepRunWireguard
|
StepRunWireguard
|
||||||
|
|
||||||
// Docker Config
|
// Docker Config
|
||||||
|
StepAppConfig
|
||||||
StepServerConfig
|
StepServerConfig
|
||||||
StepDatabaseConfig
|
StepDatabaseConfig
|
||||||
StepCertConfig
|
StepCertConfig
|
||||||
|
|||||||
+11
-2
@@ -77,6 +77,15 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
case StepRunWireguard:
|
case StepRunWireguard:
|
||||||
return m.updateRunWireguardDocker(msg)
|
return m.updateRunWireguardDocker(msg)
|
||||||
|
|
||||||
|
case StepAppConfig:
|
||||||
|
done, cmd := m.appForm.Update(msg)
|
||||||
|
|
||||||
|
if done {
|
||||||
|
m.configValues.Application = m.appForm.Values()
|
||||||
|
m.currentStep = StepServerConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
return m, cmd
|
||||||
case StepServerConfig:
|
case StepServerConfig:
|
||||||
done, cmd := m.serverForm.Update(msg)
|
done, cmd := m.serverForm.Update(msg)
|
||||||
|
|
||||||
@@ -192,7 +201,7 @@ func (m Model) updateIPQuestion(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
case "enter":
|
case "enter":
|
||||||
// Yes
|
// Yes
|
||||||
if m.cursor == 0 {
|
if m.cursor == 0 {
|
||||||
m.currentStep = StepServerConfig
|
m.currentStep = StepAppConfig
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,7 +271,7 @@ func (m Model) updateRunWireguardDocker(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
if m.finishedDockerRun && m.dockerRunError != nil {
|
if m.finishedDockerRun && m.dockerRunError != nil {
|
||||||
return m, tea.Quit
|
return m, tea.Quit
|
||||||
} else if m.finishedDockerRun && m.dockerRunError == nil {
|
} else if m.finishedDockerRun && m.dockerRunError == nil {
|
||||||
m.currentStep = StepServerConfig
|
m.currentStep = StepAppConfig
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,9 @@ func (m Model) View() tea.View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// App Config Stuff
|
// App Config Stuff
|
||||||
|
case StepAppConfig:
|
||||||
|
body = m.appForm.View()
|
||||||
|
helpMsg = formMsg
|
||||||
case StepServerConfig:
|
case StepServerConfig:
|
||||||
body = m.serverForm.View()
|
body = m.serverForm.View()
|
||||||
helpMsg = formMsg
|
helpMsg = formMsg
|
||||||
|
|||||||
Reference in New Issue
Block a user