mirror of
https://github.com/nabbar/golib.git
synced 2025-12-24 11:51:02 +08:00
Package certificates:
- rework package to allow convert config to model and retrive config from model - add sub package to manage cipher, curves, auth client, tls version, certificates, root ca... - add some small test (can be expande to having more coverage) - optimize some code Package httpcli: - update code following change in certificates Package httpserver: - update code following change in certificates Package Config/Components: - update code following change in certificates Package FTPClient: - update code following change in certificates Package Nats: - update code following change in certificates
This commit is contained in:
@@ -37,7 +37,6 @@ import (
|
||||
libtls "github.com/nabbar/golib/certificates"
|
||||
libctx "github.com/nabbar/golib/context"
|
||||
libdur "github.com/nabbar/golib/duration"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
srvtps "github.com/nabbar/golib/httpserver/types"
|
||||
liblog "github.com/nabbar/golib/logger"
|
||||
logcfg "github.com/nabbar/golib/logger/config"
|
||||
@@ -210,12 +209,9 @@ func (c *Config) Clone() Config {
|
||||
TLS: libtls.Config{
|
||||
CurveList: c.TLS.CurveList,
|
||||
CipherList: c.TLS.CipherList,
|
||||
RootCAString: c.TLS.RootCAString,
|
||||
RootCAFile: c.TLS.RootCAFile,
|
||||
ClientCAString: c.TLS.ClientCAString,
|
||||
ClientCAFiles: c.TLS.ClientCAFiles,
|
||||
CertPairString: c.TLS.CertPairString,
|
||||
CertPairFile: c.TLS.CertPairFile,
|
||||
RootCA: c.TLS.RootCA,
|
||||
ClientCA: c.TLS.ClientCA,
|
||||
Certs: c.TLS.Certs,
|
||||
VersionMin: c.TLS.VersionMin,
|
||||
VersionMax: c.TLS.VersionMax,
|
||||
AuthClient: c.TLS.AuthClient,
|
||||
@@ -239,17 +235,21 @@ func (c *Config) SetContext(f libctx.FuncContext) {
|
||||
c.getParentContext = f
|
||||
}
|
||||
|
||||
func (c *Config) GetTLS() (libtls.TLSConfig, liberr.Error) {
|
||||
func (c *Config) GetTLS() (libtls.TLSConfig, error) {
|
||||
var def libtls.TLSConfig
|
||||
|
||||
if c.TLS.InheritDefault && c.getTLSDefault != nil {
|
||||
def = c.getTLSDefault()
|
||||
}
|
||||
|
||||
return c.TLS.NewFrom(def)
|
||||
if cfg := c.TLS.NewFrom(def); cfg != nil {
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("no tls configuration found")
|
||||
}
|
||||
|
||||
func (c *Config) CheckTLS() (libtls.TLSConfig, liberr.Error) {
|
||||
func (c *Config) CheckTLS() (libtls.TLSConfig, error) {
|
||||
if ssl, err := c.GetTLS(); err != nil {
|
||||
return nil, err
|
||||
} else if ssl == nil || ssl.LenCertificatePair() < 1 {
|
||||
@@ -337,7 +337,7 @@ func (c *Config) GetHandlerKey() string {
|
||||
return c.HandlerKey
|
||||
}
|
||||
|
||||
func (c *Config) Validate() liberr.Error {
|
||||
func (c *Config) Validate() error {
|
||||
err := ErrorServerValidate.Error(nil)
|
||||
|
||||
if er := libval.New().Struct(c); er != nil {
|
||||
|
||||
@@ -91,11 +91,11 @@ func (p Config) Walk(fct FuncWalkConfig) {
|
||||
}
|
||||
}
|
||||
|
||||
func (p Config) Validate() liberr.Error {
|
||||
func (p Config) Validate() error {
|
||||
var e = ErrorPoolValidate.Error(nil)
|
||||
|
||||
p.Walk(func(cfg libhtp.Config) bool {
|
||||
var err liberr.Error
|
||||
var err error
|
||||
|
||||
if err = cfg.Validate(); err != nil {
|
||||
e.Add(err)
|
||||
|
||||
Reference in New Issue
Block a user