working commit

This commit is contained in:
2026-01-30 00:15:20 +02:00
parent 1efa93804d
commit 95aa086327
5 changed files with 221 additions and 19 deletions
+63
View File
@@ -7,6 +7,8 @@ import (
"os"
"path/filepath"
"mstore/pkg/auxx509"
"sigs.k8s.io/yaml"
)
@@ -31,6 +33,10 @@ type Config struct {
Logpath string `json:"logpath" yaml:"logpath"`
Runpath string `json:"runpath" yaml:"runpath"`
Version string `json:"version" yaml:"version"`
Certpath string `json:"certpath" yaml:"certath"`
Keypath string `json:"keypath" yaml:"keypath"`
X509Cert string `json:"X509cert" yaml:"X509cert"`
X509Key string `json:"X509key" yaml:"X509key"`
}
func NewConfig() *Config {
@@ -40,6 +46,12 @@ func NewConfig() *Config {
runfile := fmt.Sprintf("%s.run", srvname)
runpath := filepath.Join(rundir, runfile)
certpath := fmt.Sprintf("%s.crt", srvname)
certpath = filepath.Join(confdir, certpath)
keypath := fmt.Sprintf("%s.crt", srvname)
keypath = filepath.Join(confdir, keypath)
return &Config{
Service: Service{
Address: "0.0.0.0",
@@ -55,6 +67,8 @@ func NewConfig() *Config {
Logpath: logpath,
Runpath: runpath,
Version: version,
Certpath: certpath,
Keypath: keypath,
}
}
@@ -98,3 +112,52 @@ func (conf *Config) ReadOptions() error {
return err
}
func (conf *Config) ReadX509Cert() error {
var err error
if conf.Certpath != "" && conf.Keypath != "" {
if !filepath.IsAbs(conf.Certpath) {
conf.Certpath = filepath.Join(confdir, conf.Certpath)
}
certBytes, err := os.ReadFile(conf.Certpath)
if err != nil {
return err
}
if !filepath.IsAbs(conf.Keypath) {
conf.Keypath = filepath.Join(confdir, conf.Keypath)
}
keyBytes, err := os.ReadFile(conf.Keypath)
if err != nil {
return err
}
conf.X509Cert = string(certBytes)
conf.X509Key = string(keyBytes)
return err
}
/*
if conf.X509Cert != "" && conf.X509Key != "" {
x509Cert, err := base64.StdEncoding.DecodeString(conf.X509Cert)
if err != nil {
return err
}
conf.X509Cert = string(x509Cert)
x509Key, err := base64.StdEncoding.DecodeString(conf.X509Key)
if err != nil {
return err
}
conf.X509Key = string(x509Key)
}
*/
if conf.X509Cert == "" || conf.X509Key == "" {
certBytes, keyBytes, err := auxx509.CreateSelfSignedCert("localhost")
if err != nil {
return err
}
conf.X509Cert = string(certBytes)
conf.X509Key = string(keyBytes)
return err
}
return err
}