Checkpoint
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/hashicorp/hcl/v2/gohcl"
|
||||
"github.com/hashicorp/hcl/v2/hclsimple"
|
||||
|
||||
"git.maze.io/maze/styx/ca"
|
||||
"git.maze.io/maze/styx/dataset"
|
||||
"git.maze.io/maze/styx/internal/cryptutil"
|
||||
"git.maze.io/maze/styx/logger"
|
||||
@@ -18,6 +19,7 @@ import (
|
||||
type Config struct {
|
||||
Proxy ProxyConfig `hcl:"proxy,block"`
|
||||
Policy []PolicyConfig `hcl:"policy,block"`
|
||||
CA *CAConfig `hcl:"ca,block"`
|
||||
Data DataConfig `hcl:"data,block"`
|
||||
}
|
||||
|
||||
@@ -145,8 +147,18 @@ type PolicyConfig struct {
|
||||
Package string `hcl:"package,optional"`
|
||||
}
|
||||
|
||||
type CAConfig struct {
|
||||
Cert string `hcl:"cert"`
|
||||
Key string `hcl:"key,optional"`
|
||||
}
|
||||
|
||||
func (c CAConfig) CertificateAuthority() (ca.CertificateAuthority, error) {
|
||||
return ca.Open(c.Cert, c.Key)
|
||||
}
|
||||
|
||||
type DataConfig struct {
|
||||
Path string `hcl:"path,optional"`
|
||||
Storage DataStorageConfig `hcl:"storage,block"`
|
||||
Domains []DomainDataConfig `hcl:"domain,block"`
|
||||
Networks []NetworkDataConfig `hcl:"network,block"`
|
||||
}
|
||||
@@ -165,6 +177,39 @@ func (c DataConfig) Configure() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c DataConfig) OpenStorage() (dataset.Storage, error) {
|
||||
switch c.Storage.Type {
|
||||
case "", "bolt", "boltdb":
|
||||
var config struct {
|
||||
Path string `hcl:"path"`
|
||||
}
|
||||
if diag := gohcl.DecodeBody(c.Storage.Body, nil, &config); diag.HasErrors() {
|
||||
return nil, diag
|
||||
}
|
||||
//return dataset.OpenBolt(config.Path)
|
||||
return dataset.OpenBStore(config.Path)
|
||||
|
||||
/*
|
||||
case "sqlite", "sqlite3":
|
||||
var config struct {
|
||||
Path string `hcl:"path"`
|
||||
}
|
||||
if diag := gohcl.DecodeBody(c.Storage.Body, nil, &config); diag.HasErrors() {
|
||||
return nil, diag
|
||||
}
|
||||
return dataset.OpenSQLite(config.Path)
|
||||
*/
|
||||
|
||||
default:
|
||||
return nil, fmt.Errorf("storage: no %q driver", c.Storage.Type)
|
||||
}
|
||||
}
|
||||
|
||||
type DataStorageConfig struct {
|
||||
Type string `hcl:"type"`
|
||||
Body hcl.Body `hcl:",remain"`
|
||||
}
|
||||
|
||||
type DomainDataConfig struct {
|
||||
Name string `hcl:"name,label"`
|
||||
Type string `hcl:"type"`
|
||||
|
@@ -7,6 +7,9 @@ import (
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"git.maze.io/maze/styx/admin"
|
||||
"git.maze.io/maze/styx/ca"
|
||||
"git.maze.io/maze/styx/dataset"
|
||||
"git.maze.io/maze/styx/logger"
|
||||
"git.maze.io/maze/styx/proxy"
|
||||
)
|
||||
@@ -40,6 +43,22 @@ func main() {
|
||||
log.Err(err).Fatal("Invalid data configuration")
|
||||
}
|
||||
|
||||
var ca ca.CertificateAuthority
|
||||
if config.CA != nil {
|
||||
if ca, err = config.CA.CertificateAuthority(); err != nil {
|
||||
log.Err(err).Fatal("Invalid ca configuration")
|
||||
}
|
||||
}
|
||||
|
||||
var storage dataset.Storage
|
||||
if storage, err = config.Data.OpenStorage(); err != nil {
|
||||
log.Err(err).Fatal("Invalid data.storage configuration")
|
||||
}
|
||||
|
||||
admin := &admin.Admin{
|
||||
Storage: storage,
|
||||
}
|
||||
|
||||
proxies, err := config.Proxies(log)
|
||||
if err != nil {
|
||||
log.Err(err).Fatal("Error configuring proxy ports")
|
||||
@@ -52,6 +71,9 @@ func main() {
|
||||
)
|
||||
|
||||
for i, p := range proxies {
|
||||
p.CertificateAuthority = ca
|
||||
p.Storage = storage
|
||||
admin.Install(p)
|
||||
go run(config.Proxy.Port[i].Listen, p, errs)
|
||||
}
|
||||
|
||||
@@ -64,12 +86,18 @@ func main() {
|
||||
case syscall.SIGHUP:
|
||||
log.Value("signal", sig.String()).Warn("Ignored reload signal ¯\\_(ツ)_/¯")
|
||||
default:
|
||||
log.Value("signal", sig.String()).Info("Shutting down on signal")
|
||||
return
|
||||
log.Value("signal", sig.String()).Warn("Shutting down on signal")
|
||||
close(done)
|
||||
}
|
||||
|
||||
case <-done:
|
||||
log.Info("Shutting down gracefully")
|
||||
log.Warn("Shutting down gracefully")
|
||||
for i, p := range proxies {
|
||||
log.Value("port", config.Proxy.Port[i].Listen).Info("Proxy port closing")
|
||||
if err := p.Close(); err != nil {
|
||||
log.Err(err).Error("Error closing proxy")
|
||||
}
|
||||
}
|
||||
return
|
||||
|
||||
case err = <-errs:
|
||||
|
Reference in New Issue
Block a user