Skip to content

Commit

Permalink
Package HTTP Client:
Browse files Browse the repository at this point in the history
- Add DNS Mapper to force destination for a fqdn source
- Allow wildcard and multi wildcard for fqdn source
- DNS Mapper create Transport, Dialer & http client
- DNS Mapper allow a config input to customize timeout, limit and TLS config
- DNS Mapper use a gloabl transport connection poller
- DNS Mapper implement DialContext & Dial method for transport
- DNS Mapper use cache to accelerate process
- DNS Mapper cache is only dnsmapper, not DNS cache
- Replace old helper for http client with DNSMapper
- Add default DNSMapper into the main lib of http client
- Allow to overide the default DNS Mapper with a new one
- Add ticker to force clean idle connection every given duration
- "Compatible" with old config, as the default config will be used instead of old client build
- Clean code and fix minor bugs
- Add config component to allow use a global config
- Config Component httpcli can overide default httpcli dns mapper when updated

Package Certificates
- Add function type to impose function that return a slice of rootCA string
- update config/component/tls by replacing mutex with atomic
- optimize some code

Package Config
- expand errors code index to add component httpcli

Package Config/component:
- database: add new validation, that config key existing into viper
- head: add new validation, that config key existing into viper
- http: add new validation, that config key existing into viper
- ldap: add new validation, that config key existing into viper
- log: add new validation, that config key existing into viper
- mail: add new validation, that config key existing into viper
- smtp: add new validation, that config key existing into viper

Package AWS:
- update package following update of httpcli
- use interface for http cli that implement the Do function
- update following the config/component/aws
- rework config/component/aws to use atomic instead of mutex
- update test unit following change

Package Request:
- update following http client update
- use interface of HTTP Client that implement DO function, instead of http client struct pointer
- update config & code following
- apply same modification into config/component/request
- update config/component/request by replacing mutex to atomic

Package Server
- add function Uptime to model to expose the duration since last start

Package Semaphore
- apply change name of constant following bump of lib associated

Package Crypt
- fix bug into reader to remove suffix of EOF if prevent

Package Errors:
- expand index module to add DNS Mapper client

Package HTTP Server:
- update monitor to apply changes

Package Socket:
- add additional check if reading error: if buffer has data, send it to handler before break run

Other:
- bump dependencies
  • Loading branch information
nabbar committed Feb 16, 2024
1 parent eaf88e0 commit ae0a6b6
Show file tree
Hide file tree
Showing 84 changed files with 2,091 additions and 804 deletions.
6 changes: 3 additions & 3 deletions aws/aws_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ var _ = BeforeSuite(func() {
secretKey = libpwd.Generate(64)
)

htp, err = libhtc.GetClient(libhtc.GetTransport(false, false, false), true, libhtc.ClientTimeout30Sec)
Expect(err).NotTo(HaveOccurred())
htp = libhtc.GetClient()
Expect(htp).NotTo(BeNil())

cfg = awscfg.NewConfig("", accessKey, secretKey, uri, "us-east-1")
Expand All @@ -119,7 +118,8 @@ var _ = BeforeSuite(func() {
Expect(err).NotTo(HaveOccurred())
Expect(cli).NotTo(BeNil())

cli.ForcePathStyle(ctx, true)
err = cli.ForcePathStyle(ctx, true)
Expect(err).NotTo(HaveOccurred())

name, err = lbuuid.GenerateUUID()
Expect(err).ToNot(HaveOccurred())
Expand Down
5 changes: 2 additions & 3 deletions aws/configAws/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ type Model struct {
}

type ModelStatus struct {
Config Model `json:"config" yaml:"config" toml:"config" mapstructure:"config" validate:"required"`
HTTPClient libhtc.Options `json:"http-client" yaml:"http-client" toml:"http-client" mapstructure:"http-client" validate:""`
Monitor libreq.OptionsHealth `json:"health" yaml:"health" toml:"health" mapstructure:"health" validate:""`
Config Model `json:"config" yaml:"config" toml:"config" mapstructure:"config" validate:"required"`
Monitor libreq.OptionsHealth `json:"health" yaml:"health" toml:"health" mapstructure:"health" validate:""`
}

type awsModel struct {
Expand Down
5 changes: 2 additions & 3 deletions aws/configCustom/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ type Model struct {
}

type ModelStatus struct {
Config Model `json:"config" yaml:"config" toml:"config" mapstructure:"config" validate:"required"`
HTTPClient libhtc.Options `json:"http-client" yaml:"http-client" toml:"http-client" mapstructure:"http-client" validate:""`
Monitor libreq.OptionsHealth `json:"health" yaml:"health" toml:"health" mapstructure:"health" validate:""`
Config Model `json:"config" yaml:"config" toml:"config" mapstructure:"config" validate:"required"`
Monitor libreq.OptionsHealth `json:"health" yaml:"health" toml:"health" mapstructure:"health" validate:""`
}

type awsModel struct {
Expand Down
1 change: 1 addition & 0 deletions certificates/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (

type FctHttpClient func(def TLSConfig, servername string) *http.Client
type FctTLSDefault func() TLSConfig
type FctRootCA func() []string

type TLSConfig interface {
AddRootCAString(rootCA string) bool
Expand Down
82 changes: 10 additions & 72 deletions config/components/aws/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,15 @@
package aws

import (
"net/http"

libaws "github.com/nabbar/golib/aws"
libtls "github.com/nabbar/golib/certificates"
cfgtps "github.com/nabbar/golib/config/types"
libhtc "github.com/nabbar/golib/httpcli"
libreq "github.com/nabbar/golib/request"
libver "github.com/nabbar/golib/version"
libvpr "github.com/nabbar/golib/viper"
spfvbr "github.com/spf13/viper"
)

func (o *componentAws) _getKey() string {
o.m.RLock()
defer o.m.RUnlock()

if i, l := o.x.Load(keyCptKey); !l {
return ""
} else if i == nil {
Expand All @@ -54,32 +47,7 @@ func (o *componentAws) _getKey() string {
}
}

func (o *componentAws) _getTLS() libtls.TLSConfig {
o.m.RLock()
defer o.m.RUnlock()

if o.t == nil {
return nil
}

return o.t()
}

func (o *componentAws) _getHttpClient() *http.Client {
o.m.RLock()
defer o.m.RUnlock()

if o.c == nil {
return &http.Client{}
}

return o.c()
}

func (o *componentAws) _getFctVpr() libvpr.FuncViper {
o.m.RLock()
defer o.m.RUnlock()

if i, l := o.x.Load(keyFctViper); !l {
return nil
} else if i == nil {
Expand Down Expand Up @@ -112,9 +80,6 @@ func (o *componentAws) _getSPFViper() *spfvbr.Viper {
}

func (o *componentAws) _getFctCpt() cfgtps.FuncCptGet {
o.m.RLock()
defer o.m.RUnlock()

if i, l := o.x.Load(keyFctGetCpt); !l {
return nil
} else if i == nil {
Expand All @@ -127,9 +92,6 @@ func (o *componentAws) _getFctCpt() cfgtps.FuncCptGet {
}

func (o *componentAws) _getVersion() libver.Version {
o.m.RLock()
defer o.m.RUnlock()

if i, l := o.x.Load(keyCptVersion); !l {
return nil
} else if i == nil {
Expand All @@ -150,9 +112,6 @@ func (o *componentAws) _getFct() (cfgtps.FuncCptEvent, cfgtps.FuncCptEvent) {
}

func (o *componentAws) _getFctEvt(key uint8) cfgtps.FuncCptEvent {
o.m.RLock()
defer o.m.RUnlock()

if i, l := o.x.Load(key); !l {
return nil
} else if i == nil {
Expand All @@ -178,7 +137,6 @@ func (o *componentAws) _runCli() error {
cli libaws.AWS
cfg libaws.Config
mon *libreq.OptionsHealth
htc *libhtc.Options
opt *libreq.Options
req libreq.Request
prt = ErrorComponentReload
Expand All @@ -188,51 +146,33 @@ func (o *componentAws) _runCli() error {
prt = ErrorComponentStart
}

if cfg, mon, htc, err = o._getConfig(); err != nil {
if cfg, mon, err = o._getConfig(); err != nil {
return prt.Error(err)
}

if htc != nil {
var h = *htc
o.RegisterHTTPClient(func() *http.Client {
if cl, er := h.GetClient(o._getTLS(), ""); er == nil {
return cl
}

return &http.Client{}
})
}

if cli, err = libaws.New(o.x.GetContext(), cfg, o._getHttpClient()); err != nil {
if cli, err = libaws.New(o.x.GetContext(), cfg, o.getClient()); err != nil {
return prt.Error(err)
}

if mon != nil && mon.Enable {
opt = &libreq.Options{
Endpoint: "",
HttpClient: *htc,
Auth: libreq.OptionsAuth{},
Health: *mon,
Endpoint: "",
Auth: libreq.OptionsAuth{},
Health: *mon,
}

opt.SetDefaultTLS(o._getTLS)
opt.SetDefaultLog(o.getLogger)

o.m.Lock()
req = o.r
o.m.Unlock()

if req != nil {
if req = o.getRequest(); req != nil {
if req, err = opt.Update(o.x.GetContext, req); err != nil {
return prt.Error(err)
}
} else if req, err = opt.New(o.x.GetContext); err != nil {
req.RegisterHTTPClient(o.getClient())
} else if req, err = opt.New(o.x.GetContext, o.getClient()); err != nil {
return prt.Error(err)
}

o.m.Lock()
o.r = req
o.m.Unlock()
o.setRequest(req)
}

if mon != nil {
Expand All @@ -241,9 +181,7 @@ func (o *componentAws) _runCli() error {
}
}

o.m.Lock()
o.a = cli
o.m.Unlock()
o.SetAws(cli)

return nil
}
Expand Down
30 changes: 6 additions & 24 deletions config/components/aws/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,6 @@ func (o *componentAws) Type() string {
}

func (o *componentAws) Init(key string, ctx libctx.FuncContext, get cfgtps.FuncCptGet, vpr libvpr.FuncViper, vrs libver.Version, log liblog.FuncLog) {
o.m.Lock()
defer o.m.Unlock()

if o.x == nil {
o.x = libctx.NewConfig[uint8](ctx)
} else {
x := libctx.NewConfig[uint8](ctx)
x.Merge(o.x)
o.x = x
}

o.x.Store(keyCptKey, key)
o.x.Store(keyFctGetCpt, get)
o.x.Store(keyFctViper, vpr)
Expand All @@ -84,17 +73,19 @@ func (o *componentAws) RegisterFuncReload(before, after cfgtps.FuncCptEvent) {
}

func (o *componentAws) IsStarted() bool {
o.m.RLock()
defer o.m.RUnlock()
if o.s.Load() {
return o.getAws() != nil
}

return o.a != nil
return false
}

func (o *componentAws) IsRunning() bool {
return o.IsStarted()
}

func (o *componentAws) Start() error {
o.s.Store(true)
return o._run()
}

Expand All @@ -103,17 +94,11 @@ func (o *componentAws) Reload() error {
}

func (o *componentAws) Stop() {
o.m.Lock()
defer o.m.Unlock()

o.a = nil
o.s.Store(false)
return
}

func (o *componentAws) Dependencies() []string {
o.m.RLock()
defer o.m.RUnlock()

var def = make([]string, 0)

if o == nil {
Expand All @@ -132,9 +117,6 @@ func (o *componentAws) Dependencies() []string {
}

func (o *componentAws) SetDependencies(d []string) error {
o.m.RLock()
defer o.m.RUnlock()

if o.x == nil {
return ErrorComponentNotInitialized.Error(nil)
} else {
Expand Down
Loading

0 comments on commit ae0a6b6

Please sign in to comment.