Package AWS :

- Fix issue #136 :
  - add function ForceSignerOptions to pass options funct to signer
  - if not option exist, use default signer v4, else specify the options function list to the new signer
- fix error with multiple ptr identifier on model
- add function to list and cancel multipart uploads
- add function to list, get and delete version object
- add function to delete all objects following the S3 API DeleteObjects function (to send array of object key / version) in one request

Package Config :
- modify component interface :
    - add cpt as custom function parameters to prevent new component still not stored when running custom function
    - re-order mutex on start / reload process

Change :
- Bump dependancies
This commit is contained in:
Nicolas JUHEL
2022-04-14 14:33:38 +02:00
parent 7db933b96e
commit f073bca2d3
19 changed files with 772 additions and 549 deletions

View File

@@ -32,25 +32,23 @@ import (
sdkaws "github.com/aws/aws-sdk-go-v2/aws"
sdksv4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4"
sdkiam "github.com/aws/aws-sdk-go-v2/service/iam"
sdksss "github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/nabbar/golib/aws/bucket"
"github.com/nabbar/golib/aws/group"
"github.com/nabbar/golib/aws/helper"
"github.com/nabbar/golib/aws/object"
"github.com/nabbar/golib/aws/policy"
"github.com/nabbar/golib/aws/role"
"github.com/nabbar/golib/aws/user"
"github.com/nabbar/golib/errors"
awsbck "github.com/nabbar/golib/aws/bucket"
awsgrp "github.com/nabbar/golib/aws/group"
awshlp "github.com/nabbar/golib/aws/helper"
awsobj "github.com/nabbar/golib/aws/object"
awspol "github.com/nabbar/golib/aws/policy"
awsrol "github.com/nabbar/golib/aws/role"
awsusr "github.com/nabbar/golib/aws/user"
liberr "github.com/nabbar/golib/errors"
)
type Config interface {
Check(ctx context.Context) errors.Error
Validate() errors.Error
Check(ctx context.Context) liberr.Error
Validate() liberr.Error
ResetRegionEndpoint()
RegisterRegionEndpoint(region string, endpoint *url.URL) errors.Error
RegisterRegionAws(endpoint *url.URL) errors.Error
RegisterRegionEndpoint(region string, endpoint *url.URL) liberr.Error
RegisterRegionAws(endpoint *url.URL) liberr.Error
SetRegion(region string)
GetRegion() string
SetEndpoint(endpoint *url.URL)
@@ -60,7 +58,7 @@ type Config interface {
ResolveEndpoint(service, region string) (sdkaws.Endpoint, error)
SetRetryer(retryer func() sdkaws.Retryer)
GetConfig(ctx context.Context, cli *http.Client) (*sdkaws.Config, errors.Error)
GetConfig(ctx context.Context, cli *http.Client) (*sdkaws.Config, liberr.Error)
JSON() ([]byte, error)
Clone() Config
@@ -69,33 +67,25 @@ type Config interface {
}
type AWS interface {
Bucket() bucket.Bucket
Group() group.Group
Object() object.Object
Policy() policy.Policy
Role() role.Role
User() user.User
Bucket() awsbck.Bucket
Group() awsgrp.Group
Object() awsobj.Object
Policy() awspol.Policy
Role() awsrol.Role
User() awsusr.User
Clone(ctx context.Context) (AWS, errors.Error)
Clone(ctx context.Context) (AWS, liberr.Error)
Config() Config
ForcePathStyle(ctx context.Context, enabled bool) errors.Error
ForcePathStyle(ctx context.Context, enabled bool) liberr.Error
ForceSignerOptions(ctx context.Context, fct ...func(signer *sdksv4.SignerOptions)) liberr.Error
GetBucketName() string
SetBucketName(bucket string)
}
type client struct {
p bool
x context.Context
c Config
i *sdkiam.Client
s *sdksss.Client
h *http.Client
}
func New(ctx context.Context, cfg Config, httpClient *http.Client) (AWS, errors.Error) {
func New(ctx context.Context, cfg Config, httpClient *http.Client) (AWS, liberr.Error) {
if cfg == nil {
return nil, helper.ErrorConfigEmpty.Error(nil)
return nil, awshlp.ErrorConfigEmpty.Error(nil)
}
if ctx == nil {
@@ -111,111 +101,13 @@ func New(ctx context.Context, cfg Config, httpClient *http.Client) (AWS, errors.
h: httpClient,
}
if i, e := cli.newClientIAM(ctx, httpClient); e != nil {
if i, e := cli._NewClientIAM(ctx, httpClient); e != nil {
return nil, e
} else {
cli.i = i
}
if s, e := cli.newClientS3(ctx, httpClient); e != nil {
return nil, e
} else {
cli.s = s
}
return cli, nil
}
func (cli *client) newClientIAM(ctx context.Context, httpClient *http.Client) (*sdkiam.Client, errors.Error) {
var (
c *sdkaws.Config
i *sdkiam.Client
e errors.Error
r sdkaws.Retryer
)
if httpClient == nil {
httpClient = cli.h
}
if c, e = cli.c.GetConfig(ctx, httpClient); e != nil {
return nil, e
}
if c.Retryer != nil {
r = c.Retryer()
}
i = sdkiam.New(sdkiam.Options{
APIOptions: c.APIOptions,
Credentials: c.Credentials,
EndpointOptions: sdkiam.EndpointResolverOptions{
DisableHTTPS: !cli.c.IsHTTPs(),
},
EndpointResolver: cli.newIAMResolver(c),
HTTPSignerV4: sdksv4.NewSigner(),
Region: c.Region,
Retryer: r,
HTTPClient: httpClient,
})
return i, nil
}
func (cli *client) newClientS3(ctx context.Context, httpClient *http.Client) (*sdksss.Client, errors.Error) {
var (
c *sdkaws.Config
s *sdksss.Client
e errors.Error
r sdkaws.Retryer
)
if httpClient == nil {
httpClient = cli.h
}
if c, e = cli.c.GetConfig(ctx, httpClient); e != nil {
return nil, e
}
if c.Retryer != nil {
r = c.Retryer()
}
s = sdksss.New(sdksss.Options{
APIOptions: c.APIOptions,
Credentials: c.Credentials,
EndpointOptions: sdksss.EndpointResolverOptions{
DisableHTTPS: !cli.c.IsHTTPs(),
},
EndpointResolver: cli.newS3Resolver(c),
HTTPSignerV4: sdksv4.NewSigner(),
Region: c.Region,
Retryer: r,
HTTPClient: httpClient,
UsePathStyle: cli.p,
})
return s, nil
}
func (c *client) Clone(ctx context.Context) (AWS, errors.Error) {
cli := &client{
p: false,
x: c.x,
c: c.c.Clone(),
i: nil,
s: nil,
h: c.h,
}
if i, e := cli.newClientIAM(ctx, c.h); e != nil {
return nil, e
} else {
cli.i = i
}
if s, e := cli.newClientS3(ctx, c.h); e != nil {
if s, e := cli._NewClientS3(ctx, httpClient); e != nil {
return nil, e
} else {
cli.s = s

View File

@@ -27,20 +27,165 @@ package aws
import (
"context"
"net/http"
"github.com/nabbar/golib/aws/bucket"
"github.com/nabbar/golib/aws/group"
"github.com/nabbar/golib/aws/object"
"github.com/nabbar/golib/aws/policy"
"github.com/nabbar/golib/aws/role"
"github.com/nabbar/golib/aws/user"
"github.com/nabbar/golib/errors"
sdkaws "github.com/aws/aws-sdk-go-v2/aws"
sdksv4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4"
sdkiam "github.com/aws/aws-sdk-go-v2/service/iam"
sdksss "github.com/aws/aws-sdk-go-v2/service/s3"
awsbck "github.com/nabbar/golib/aws/bucket"
awsgrp "github.com/nabbar/golib/aws/group"
awsobj "github.com/nabbar/golib/aws/object"
awspol "github.com/nabbar/golib/aws/policy"
awsrol "github.com/nabbar/golib/aws/role"
awsusr "github.com/nabbar/golib/aws/user"
liberr "github.com/nabbar/golib/errors"
)
func (c *client) ForcePathStyle(ctx context.Context, enabled bool) errors.Error {
type client struct {
p bool
o []func(signer *sdksv4.SignerOptions)
x context.Context
c Config
i *sdkiam.Client
s *sdksss.Client
h *http.Client
}
func (c *client) _NewClientIAM(ctx context.Context, httpClient *http.Client) (*sdkiam.Client, liberr.Error) {
var (
cfg *sdkaws.Config
iam *sdkiam.Client
err liberr.Error
ret sdkaws.Retryer
sig *sdksv4.Signer
)
if httpClient == nil {
httpClient = c.h
}
if cfg, err = c.c.GetConfig(ctx, httpClient); err != nil {
return nil, err
}
if cfg.Retryer != nil {
ret = cfg.Retryer()
}
if len(c.o) > 0 {
sig = sdksv4.NewSigner(c.o...)
} else {
sig = sdksv4.NewSigner()
}
iam = sdkiam.New(sdkiam.Options{
APIOptions: cfg.APIOptions,
Credentials: cfg.Credentials,
EndpointOptions: sdkiam.EndpointResolverOptions{
DisableHTTPS: !c.c.IsHTTPs(),
},
EndpointResolver: c._NewIAMResolver(cfg),
HTTPSignerV4: sig,
Region: cfg.Region,
Retryer: ret,
HTTPClient: httpClient,
})
return iam, nil
}
func (c *client) _NewClientS3(ctx context.Context, httpClient *http.Client) (*sdksss.Client, liberr.Error) {
var (
sss *sdksss.Client
err liberr.Error
ret sdkaws.Retryer
cfg *sdkaws.Config
sig *sdksv4.Signer
)
if httpClient == nil {
httpClient = c.h
}
if cfg, err = c.c.GetConfig(ctx, httpClient); err != nil {
return nil, err
}
if cfg.Retryer != nil {
ret = cfg.Retryer()
}
if len(c.o) > 0 {
sig = sdksv4.NewSigner(c.o...)
} else {
sig = sdksv4.NewSigner()
}
sss = sdksss.New(sdksss.Options{
APIOptions: cfg.APIOptions,
Credentials: cfg.Credentials,
EndpointOptions: sdksss.EndpointResolverOptions{
DisableHTTPS: !c.c.IsHTTPs(),
},
EndpointResolver: c._NewS3Resolver(cfg),
HTTPSignerV4: sig,
Region: cfg.Region,
Retryer: ret,
HTTPClient: httpClient,
UsePathStyle: c.p,
})
return sss, nil
}
func (c *client) Clone(ctx context.Context) (AWS, liberr.Error) {
n := &client{
p: false,
x: c.x,
c: c.c.Clone(),
i: nil,
s: nil,
h: c.h,
}
if i, e := n._NewClientIAM(ctx, c.h); e != nil {
return nil, e
} else {
n.i = i
}
if s, e := n._NewClientS3(ctx, c.h); e != nil {
return nil, e
} else {
n.s = s
}
return n, nil
}
func (c *client) ForcePathStyle(ctx context.Context, enabled bool) liberr.Error {
c.p = enabled
if s, e := c.newClientS3(ctx, nil); e != nil {
if s, e := c._NewClientS3(ctx, nil); e != nil {
return e
} else {
c.s = s
}
return nil
}
func (c *client) ForceSignerOptions(ctx context.Context, fct ...func(signer *sdksv4.SignerOptions)) liberr.Error {
c.o = fct
if i, e := c._NewClientIAM(ctx, nil); e != nil {
return e
} else {
c.i = i
}
if s, e := c._NewClientS3(ctx, nil); e != nil {
return e
} else {
c.s = s
@@ -53,28 +198,28 @@ func (c *client) Config() Config {
return c.c
}
func (c *client) Bucket() bucket.Bucket {
return bucket.New(c.x, c.c.GetBucketName(), c.c.GetRegion(), c.i, c.s)
func (c *client) Bucket() awsbck.Bucket {
return awsbck.New(c.x, c.c.GetBucketName(), c.c.GetRegion(), c.i, c.s)
}
func (c *client) Group() group.Group {
return group.New(c.x, c.c.GetBucketName(), c.c.GetRegion(), c.i, c.s)
func (c *client) Group() awsgrp.Group {
return awsgrp.New(c.x, c.c.GetBucketName(), c.c.GetRegion(), c.i, c.s)
}
func (c *client) Object() object.Object {
return object.New(c.x, c.c.GetBucketName(), c.c.GetRegion(), c.i, c.s)
func (c *client) Object() awsobj.Object {
return awsobj.New(c.x, c.c.GetBucketName(), c.c.GetRegion(), c.i, c.s)
}
func (c *client) Policy() policy.Policy {
return policy.New(c.x, c.c.GetBucketName(), c.c.GetRegion(), c.i, c.s)
func (c *client) Policy() awspol.Policy {
return awspol.New(c.x, c.c.GetBucketName(), c.c.GetRegion(), c.i, c.s)
}
func (c *client) Role() role.Role {
return role.New(c.x, c.c.GetBucketName(), c.c.GetRegion(), c.i, c.s)
func (c *client) Role() awsrol.Role {
return awsrol.New(c.x, c.c.GetBucketName(), c.c.GetRegion(), c.i, c.s)
}
func (c *client) User() user.User {
return user.New(c.x, c.c.GetBucketName(), c.c.GetRegion(), c.i, c.s)
func (c *client) User() awsusr.User {
return awsusr.New(c.x, c.c.GetBucketName(), c.c.GetRegion(), c.i, c.s)
}
func (c *client) GetBucketName() string {

View File

@@ -52,8 +52,10 @@ type Object interface {
Put(object string, body io.Reader) liberr.Error
Delete(check bool, object string) liberr.Error
MultipartList(keyMarker, markerId string) (uploads []sdktps.MultipartUpload, nextKeyMarker string, nextIdMarker string, count int64, e liberr.Error)
MultipartPut(object string, body io.Reader) liberr.Error
MultipartPutCustom(partSize libhlp.PartSize, object string, body io.Reader) liberr.Error
MultipartCancel(uploadId, key string) liberr.Error
UpdateMetadata(meta *sdksss.CopyObjectInput) liberr.Error
SetWebsite(object, redirect string) liberr.Error

View File

@@ -47,6 +47,30 @@ import (
const DefaultPartSize = 5 * libhlp.SizeMegaBytes
// MultipartList implement the ListMultipartUploads.
// See docs for more infos : https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListMultipartUploads.html
func (cli *client) MultipartList(keyMarker, markerId string) (uploads []sdktyp.MultipartUpload, nextKeyMarker string, nextIdMarker string, count int64, e liberr.Error) {
in := &sdksss.ListMultipartUploadsInput{
Bucket: sdkaws.String(cli.GetBucketName()),
MaxUploads: 1000,
}
if keyMarker != "" && markerId != "" {
in.KeyMarker = sdkaws.String(keyMarker)
in.UploadIdMarker = sdkaws.String(markerId)
}
out, err := cli.s3.ListMultipartUploads(cli.GetContext(), in)
if err != nil {
return nil, "", "", 0, cli.GetError(err)
} else if out.IsTruncated {
return out.Uploads, *out.NextKeyMarker, *out.NextUploadIdMarker, int64(out.MaxUploads), nil
} else {
return out.Uploads, "", "", int64(out.MaxUploads), nil
}
}
func (cli *client) MultipartPut(object string, body io.Reader) liberr.Error {
return cli.MultipartPutCustom(DefaultPartSize, object, body)
}
@@ -94,33 +118,33 @@ func (cli *client) MultipartPutCustom(partSize libhlp.PartSize, object string, b
tmp, err = libiou.NewFileProgressTemp()
if err != nil {
return cli.multipartCancel(err, upl.UploadId, object)
return cli._MultipartCancel(err, upl.UploadId, object)
}
_, err = io.Copy(tmp, rio)
if err != nil {
return cli.multipartCancel(err, upl.UploadId, object)
return cli._MultipartCancel(err, upl.UploadId, object)
}
_, err = tmp.Seek(0, io.SeekStart)
if err != nil {
return cli.multipartCancel(err, upl.UploadId, object)
return cli._MultipartCancel(err, upl.UploadId, object)
}
inf, err = tmp.FileStat()
if err != nil {
return cli.multipartCancel(err, upl.UploadId, object)
return cli._MultipartCancel(err, upl.UploadId, object)
}
/* #nosec */
h := md5.New()
if _, e := tmp.WriteTo(h); e != nil {
return cli.multipartCancel(e, upl.UploadId, object)
return cli._MultipartCancel(e, upl.UploadId, object)
}
_, err = tmp.Seek(0, io.SeekStart)
if err != nil {
return cli.multipartCancel(err, upl.UploadId, object)
return cli._MultipartCancel(err, upl.UploadId, object)
}
prt, err = cli.s3.UploadPart(cli.GetContext(), &sdksss.UploadPartInput{
@@ -138,9 +162,9 @@ func (cli *client) MultipartPutCustom(partSize libhlp.PartSize, object string, b
tmp = nil
if err != nil {
return cli.multipartCancel(err, upl.UploadId, object)
return cli._MultipartCancel(err, upl.UploadId, object)
} else if prt == nil || prt.ETag == nil || len(*prt.ETag) == 0 {
return cli.multipartCancel(libhlp.ErrorResponse.Error(nil), upl.UploadId, object)
return cli._MultipartCancel(libhlp.ErrorResponse.Error(nil), upl.UploadId, object)
}
rio.NextPart(prt.ETag)
@@ -156,15 +180,15 @@ func (cli *client) MultipartPutCustom(partSize libhlp.PartSize, object string, b
})
if err != nil {
return cli.multipartCancel(err, upl.UploadId, object)
return cli._MultipartCancel(err, upl.UploadId, object)
} else if prt == nil || prt.ETag == nil || len(*prt.ETag) == 0 {
return cli.multipartCancel(libhlp.ErrorResponse.Error(nil), upl.UploadId, object)
return cli._MultipartCancel(libhlp.ErrorResponse.Error(nil), upl.UploadId, object)
}
return nil
}
func (cli *client) multipartCancel(err error, updIp *string, object string) liberr.Error {
func (cli *client) _MultipartCancel(err error, updIp *string, object string) liberr.Error {
cnl, e := cli.s3.AbortMultipartUpload(cli.GetContext(), &sdksss.AbortMultipartUploadInput{
Bucket: sdkaws.String(cli.GetBucketName()),
UploadId: updIp,
@@ -175,8 +199,13 @@ func (cli *client) multipartCancel(err error, updIp *string, object string) libe
return cli.GetError(e, err)
} else if cnl == nil {
return libhlp.ErrorResponse.Error(cli.GetError(err))
} else {
} else if err != nil {
return cli.GetError(err)
} else {
return nil
}
}
func (cli *client) MultipartCancel(uploadId, key string) liberr.Error {
return cli._MultipartCancel(nil, sdkaws.String(uploadId), key)
}

View File

@@ -47,14 +47,14 @@ func (r *resolverS3) ResolveEndpoint(region string, options sdksss.EndpointResol
return r.r("s3", region)
}
func (cli *client) newIAMResolver(c *sdkaws.Config) sdkiam.EndpointResolver {
func (c *client) _NewIAMResolver(cfg *sdkaws.Config) sdkiam.EndpointResolver {
return &resolverIam{
r: c.EndpointResolver.ResolveEndpoint,
r: cfg.EndpointResolver.ResolveEndpoint,
}
}
func (cli *client) newS3Resolver(c *sdkaws.Config) sdksss.EndpointResolver {
func (c *client) _NewS3Resolver(cfg *sdkaws.Config) sdksss.EndpointResolver {
return &resolverS3{
r: c.EndpointResolver.ResolveEndpoint,
r: cfg.EndpointResolver.ResolveEndpoint,
}
}

View File

@@ -40,10 +40,10 @@ type Component interface {
Init(key string, ctx FuncContext, get FuncComponentGet, vpr FuncComponentViper)
// RegisterFuncStart is called to register the function to be called before and after the start function.
RegisterFuncStart(before, after func() liberr.Error)
RegisterFuncStart(before, after func(cpt Component) liberr.Error)
// RegisterFuncReload is called to register the function to be called before and after the reload function.
RegisterFuncReload(before, after func() liberr.Error)
RegisterFuncReload(before, after func(cpt Component) liberr.Error)
// RegisterFlag can be called to register flag to a spf cobra command and link it with viper
// to retrieve it into the config viper.

View File

@@ -41,10 +41,10 @@ type componentAws struct {
vpr libcfg.FuncComponentViper
key string
fsa func() liberr.Error
fsb func() liberr.Error
fra func() liberr.Error
frb func() liberr.Error
fsa func(cpt libcfg.Component) liberr.Error
fsb func(cpt libcfg.Component) liberr.Error
fra func(cpt libcfg.Component) liberr.Error
frb func(cpt libcfg.Component) liberr.Error
m sync.Mutex
d ConfigDriver
@@ -60,20 +60,28 @@ func (c *componentAws) _getHttpClient() *http.Client {
return c.c()
}
func (c *componentAws) _getClient(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
var (
isReload = c.a != nil
)
func (c *componentAws) _getFct() (func(cpt libcfg.Component) liberr.Error, func(cpt libcfg.Component) liberr.Error) {
c.m.Lock()
defer c.m.Unlock()
if !isReload && c.fsb != nil {
if err := c.fsb(); err != nil {
return err
}
} else if isReload && c.frb != nil {
if err := c.frb(); err != nil {
return err
}
if c.a != nil {
return c.frb, c.fra
} else {
return c.fsb, c.fsa
}
}
func (c *componentAws) _runFct(fct func(cpt libcfg.Component) liberr.Error) liberr.Error {
if fct != nil {
return fct(c)
}
return nil
}
func (c *componentAws) _runCli(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
c.m.Lock()
defer c.m.Unlock()
if cfg, err := c._getConfig(getCfg); err != nil {
return err
@@ -83,14 +91,18 @@ func (c *componentAws) _getClient(getCfg libcfg.FuncComponentConfigGet) liberr.E
c.a = cli
}
if !isReload && c.fsa != nil {
if err := c.fsa(); err != nil {
return err
}
} else if isReload && c.fra != nil {
if err := c.fra(); err != nil {
return err
}
return nil
}
func (c *componentAws) _run(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
fb, fa := c._getFct()
if err := c._runFct(fb); err != nil {
return err
} else if err = c._runCli(getCfg); err != nil {
return err
} else if err = c._runFct(fa); err != nil {
return err
}
return nil
@@ -110,7 +122,7 @@ func (c *componentAws) Init(key string, ctx libcfg.FuncContext, get libcfg.FuncC
c.vpr = vpr
}
func (c *componentAws) RegisterFuncStart(before, after func() liberr.Error) {
func (c *componentAws) RegisterFuncStart(before, after func(cpt libcfg.Component) liberr.Error) {
c.m.Lock()
defer c.m.Unlock()
@@ -118,7 +130,7 @@ func (c *componentAws) RegisterFuncStart(before, after func() liberr.Error) {
c.fsa = after
}
func (c *componentAws) RegisterFuncReload(before, after func() liberr.Error) {
func (c *componentAws) RegisterFuncReload(before, after func(cpt libcfg.Component) liberr.Error) {
c.m.Lock()
defer c.m.Unlock()
@@ -138,11 +150,11 @@ func (c *componentAws) IsRunning(atLeast bool) bool {
}
func (c *componentAws) Start(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
return c._getClient(getCfg)
return c._run(getCfg)
}
func (c *componentAws) Reload(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
return c._getClient(getCfg)
return c._run(getCfg)
}
func (c *componentAws) Stop() {

View File

@@ -43,10 +43,10 @@ type componentDatabase struct {
vpr libcfg.FuncComponentViper
key string
fsa func() liberr.Error
fsb func() liberr.Error
fra func() liberr.Error
frb func() liberr.Error
fsa func(cpt libcfg.Component) liberr.Error
fsb func(cpt libcfg.Component) liberr.Error
fra func(cpt libcfg.Component) liberr.Error
frb func(cpt libcfg.Component) liberr.Error
m sync.Mutex
l string
@@ -73,26 +73,35 @@ func (c *componentDatabase) _GetLogger() (liblog.Logger, liberr.Error) {
}
}
func (c *componentDatabase) _getClient(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
var (
err liberr.Error
cnf libdbs.Config
isReload = c.IsStarted()
)
func (c *componentDatabase) _getFct() (func(cpt libcfg.Component) liberr.Error, func(cpt libcfg.Component) liberr.Error) {
var isReload = c.IsStarted()
c.m.Lock()
defer c.m.Unlock()
if isReload && c.frb != nil {
if err = c.frb(); err != nil {
return err
}
} else if !isReload && c.fsb != nil {
if err = c.fsb(); err != nil {
return err
}
if isReload {
return c.frb, c.fra
} else {
return c.fsb, c.fsa
}
}
func (c *componentDatabase) _runFct(fct func(cpt libcfg.Component) liberr.Error) liberr.Error {
if fct != nil {
return fct(c)
}
return nil
}
func (c *componentDatabase) _runCli(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
c.m.Lock()
defer c.m.Unlock()
var (
err liberr.Error
cnf libdbs.Config
)
if cnf, err = c._getConfig(getCfg); err != nil {
return err
@@ -106,19 +115,26 @@ func (c *componentDatabase) _getClient(getCfg libcfg.FuncComponentConfigGet) lib
return ErrorStartDatabase.Error(err)
}
if isReload && c.fra != nil {
if err = c.fra(); err != nil {
return err
}
} else if !isReload && c.fsa != nil {
if err = c.fsa(); err != nil {
return err
}
return nil
}
func (c *componentDatabase) _run(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
if !c._CheckDep() {
return ErrorComponentNotInitialized.Error(nil)
}
fb, fa := c._getFct()
if err := c._runFct(fb); err != nil {
return err
} else if err = c._runCli(getCfg); err != nil {
return err
} else if err = c._runFct(fa); err != nil {
return err
}
return nil
}
func (c *componentDatabase) Type() string {
return ComponentType
}
@@ -133,7 +149,7 @@ func (c *componentDatabase) Init(key string, ctx libcfg.FuncContext, get libcfg.
c.vpr = vpr
}
func (c *componentDatabase) RegisterFuncStart(before, after func() liberr.Error) {
func (c *componentDatabase) RegisterFuncStart(before, after func(cpt libcfg.Component) liberr.Error) {
c.m.Lock()
defer c.m.Unlock()
@@ -141,7 +157,7 @@ func (c *componentDatabase) RegisterFuncStart(before, after func() liberr.Error)
c.fsa = after
}
func (c *componentDatabase) RegisterFuncReload(before, after func() liberr.Error) {
func (c *componentDatabase) RegisterFuncReload(before, after func(cpt libcfg.Component) liberr.Error) {
c.m.Lock()
defer c.m.Unlock()
@@ -171,11 +187,11 @@ func (c *componentDatabase) IsRunning(atLeast bool) bool {
}
func (c *componentDatabase) Start(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
return c._getClient(getCfg)
return c._run(getCfg)
}
func (c *componentDatabase) Reload(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
return c._getClient(getCfg)
return c._run(getCfg)
}
func (c *componentDatabase) Stop() {

View File

@@ -40,30 +40,37 @@ type componentHead struct {
vpr libcfg.FuncComponentViper
key string
fsa func() liberr.Error
fsb func() liberr.Error
fra func() liberr.Error
frb func() liberr.Error
fsa func(cpt libcfg.Component) liberr.Error
fsb func(cpt libcfg.Component) liberr.Error
fra func(cpt libcfg.Component) liberr.Error
frb func(cpt libcfg.Component) liberr.Error
m sync.Mutex
h librtr.Headers
}
func (c *componentHead) _run(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
func (c *componentHead) _getFct() (func(cpt libcfg.Component) liberr.Error, func(cpt libcfg.Component) liberr.Error) {
c.m.Lock()
defer c.m.Unlock()
var isReload = c.h != nil
if isReload && c.frb != nil {
if err := c.frb(); err != nil {
return err
}
} else if !isReload && c.fsb != nil {
if err := c.fsb(); err != nil {
return err
}
if c.h != nil {
return c.frb, c.fra
} else {
return c.fsb, c.fsa
}
}
func (c *componentHead) _runFct(fct func(cpt libcfg.Component) liberr.Error) liberr.Error {
if fct != nil {
return fct(c)
}
return nil
}
func (c *componentHead) _runCli(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
c.m.Lock()
defer c.m.Unlock()
cnf := librtr.HeadersConfig{}
if err := getCfg(c.key, &cnf); err != nil {
@@ -71,15 +78,18 @@ func (c *componentHead) _run(getCfg libcfg.FuncComponentConfigGet) liberr.Error
}
c.h = cnf.New()
return nil
}
if isReload && c.fra != nil {
if err := c.fra(); err != nil {
return err
}
} else if !isReload && c.fsa != nil {
if err := c.fsa(); err != nil {
return err
}
func (c *componentHead) _run(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
fb, fa := c._getFct()
if err := c._runFct(fb); err != nil {
return err
} else if err = c._runCli(getCfg); err != nil {
return err
} else if err = c._runFct(fa); err != nil {
return err
}
return nil
@@ -99,7 +109,7 @@ func (c *componentHead) Init(key string, ctx libcfg.FuncContext, get libcfg.Func
c.vpr = vpr
}
func (c *componentHead) RegisterFuncStart(before, after func() liberr.Error) {
func (c *componentHead) RegisterFuncStart(before, after func(cpt libcfg.Component) liberr.Error) {
c.m.Lock()
defer c.m.Unlock()
@@ -107,7 +117,7 @@ func (c *componentHead) RegisterFuncStart(before, after func() liberr.Error) {
c.fsa = after
}
func (c *componentHead) RegisterFuncReload(before, after func() liberr.Error) {
func (c *componentHead) RegisterFuncReload(before, after func(cpt libcfg.Component) liberr.Error) {
c.m.Lock()
defer c.m.Unlock()

View File

@@ -46,10 +46,10 @@ type componentHttp struct {
vpr libcfg.FuncComponentViper
key string
fsa func() liberr.Error
fsb func() liberr.Error
fra func() liberr.Error
frb func() liberr.Error
fsa func(cpt libcfg.Component) liberr.Error
fsb func(cpt libcfg.Component) liberr.Error
fra func(cpt libcfg.Component) liberr.Error
frb func(cpt libcfg.Component) liberr.Error
m sync.Mutex
@@ -131,26 +131,35 @@ func (c *componentHttp) _getPoolServerConfig(getCfg libcfg.FuncComponentConfigGe
return cnf, nil
}
func (c *componentHttp) _run(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
var (
err liberr.Error
cnf libhts.PoolServerConfig
isReload = c.IsStarted()
)
func (c *componentHttp) _getFct() (func(cpt libcfg.Component) liberr.Error, func(cpt libcfg.Component) liberr.Error) {
var isReload = c.IsStarted()
c.m.Lock()
defer c.m.Unlock()
if !isReload && c.fsb != nil {
if err = c.fsb(); err != nil {
return err
}
} else if isReload && c.frb != nil {
if err = c.frb(); err != nil {
return err
}
if isReload {
return c.frb, c.fra
} else {
return c.fsb, c.fsa
}
}
func (c *componentHttp) _runFct(fct func(cpt libcfg.Component) liberr.Error) liberr.Error {
if fct != nil {
return fct(c)
}
return nil
}
func (c *componentHttp) _runCli(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
c.m.Lock()
defer c.m.Unlock()
var (
err liberr.Error
cnf libhts.PoolServerConfig
)
if cnf, err = c._getPoolServerConfig(getCfg); err != nil {
return err
@@ -169,10 +178,14 @@ func (c *componentHttp) _run(getCfg libcfg.FuncComponentConfigGet) liberr.Error
}
c.pool.SetLogger(func() liblog.Logger {
if log, err := c._GetLogger(); err != nil {
var (
l liblog.Logger
e liberr.Error
)
if l, e = c._GetLogger(); e != nil {
return liblog.GetDefault()
} else {
return log
return l
}
})
@@ -180,14 +193,22 @@ func (c *componentHttp) _run(getCfg libcfg.FuncComponentConfigGet) liberr.Error
return ErrorStartComponent.Error(err)
}
if !isReload && c.fsa != nil {
if err = c.fsa(); err != nil {
return err
}
} else if isReload && c.fra != nil {
if err = c.fra(); err != nil {
return err
}
return nil
}
func (c *componentHttp) _run(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
if !c._CheckDep() {
return ErrorComponentNotInitialized.Error(nil)
}
fb, fa := c._getFct()
if err := c._runFct(fb); err != nil {
return err
} else if err = c._runCli(getCfg); err != nil {
return err
} else if err = c._runFct(fa); err != nil {
return err
}
return nil
@@ -207,7 +228,7 @@ func (c *componentHttp) Init(key string, ctx libcfg.FuncContext, get libcfg.Func
c.vpr = vpr
}
func (c *componentHttp) RegisterFuncStart(before, after func() liberr.Error) {
func (c *componentHttp) RegisterFuncStart(before, after func(cpt libcfg.Component) liberr.Error) {
c.m.Lock()
defer c.m.Unlock()
@@ -215,7 +236,7 @@ func (c *componentHttp) RegisterFuncStart(before, after func() liberr.Error) {
c.fsa = after
}
func (c *componentHttp) RegisterFuncReload(before, after func() liberr.Error) {
func (c *componentHttp) RegisterFuncReload(before, after func(cpt libcfg.Component) liberr.Error) {
c.m.Lock()
defer c.m.Unlock()

View File

@@ -41,10 +41,10 @@ type componentLDAP struct {
vpr libcfg.FuncComponentViper
key string
fsa func() liberr.Error
fsb func() liberr.Error
fra func() liberr.Error
frb func() liberr.Error
fsa func(cpt libcfg.Component) liberr.Error
fsb func(cpt libcfg.Component) liberr.Error
fra func(cpt libcfg.Component) liberr.Error
frb func(cpt libcfg.Component) liberr.Error
m sync.Mutex
l *lbldap.HelperLDAP
@@ -67,21 +67,28 @@ func (c *componentLDAP) _CheckInit() bool {
return c != nil && c.l != nil
}
func (c *componentLDAP) _run(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
func (c *componentLDAP) _getFct() (func(cpt libcfg.Component) liberr.Error, func(cpt libcfg.Component) liberr.Error) {
c.m.Lock()
defer c.m.Unlock()
var isReload = c.l != nil
if isReload && c.frb != nil {
if err := c.frb(); err != nil {
return err
}
} else if !isReload && c.fsb != nil {
if err := c.fsb(); err != nil {
return err
}
if c.l != nil {
return c.frb, c.fra
} else {
return c.fsb, c.fsa
}
}
func (c *componentLDAP) _runFct(fct func(cpt libcfg.Component) liberr.Error) liberr.Error {
if fct != nil {
return fct(c)
}
return nil
}
func (c *componentLDAP) _runCli(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
c.m.Lock()
defer c.m.Unlock()
cfg := lbldap.Config{}
if err := getCfg(c.key, &cfg); err != nil {
@@ -94,14 +101,18 @@ func (c *componentLDAP) _run(getCfg libcfg.FuncComponentConfigGet) liberr.Error
c.l = l
}
if isReload && c.fra != nil {
if err := c.fra(); err != nil {
return err
}
} else if !isReload && c.fsa != nil {
if err := c.fsa(); err != nil {
return err
}
return nil
}
func (c *componentLDAP) _run(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
fb, fa := c._getFct()
if err := c._runFct(fb); err != nil {
return err
} else if err = c._runCli(getCfg); err != nil {
return err
} else if err = c._runFct(fa); err != nil {
return err
}
return nil
@@ -121,7 +132,7 @@ func (c *componentLDAP) Init(key string, ctx libcfg.FuncContext, get libcfg.Func
c.vpr = vpr
}
func (c *componentLDAP) RegisterFuncStart(before, after func() liberr.Error) {
func (c *componentLDAP) RegisterFuncStart(before, after func(cpt libcfg.Component) liberr.Error) {
c.m.Lock()
defer c.m.Unlock()
@@ -129,7 +140,7 @@ func (c *componentLDAP) RegisterFuncStart(before, after func() liberr.Error) {
c.fsa = after
}
func (c *componentLDAP) RegisterFuncReload(before, after func() liberr.Error) {
func (c *componentLDAP) RegisterFuncReload(before, after func(cpt libcfg.Component) liberr.Error) {
c.m.Lock()
defer c.m.Unlock()

View File

@@ -40,10 +40,10 @@ type componentLog struct {
vpr libcfg.FuncComponentViper
key string
fsa func() liberr.Error
fsb func() liberr.Error
fra func() liberr.Error
frb func() liberr.Error
fsa func(cpt libcfg.Component) liberr.Error
fsb func(cpt libcfg.Component) liberr.Error
fra func(cpt libcfg.Component) liberr.Error
frb func(cpt libcfg.Component) liberr.Error
d func() liblog.Logger
@@ -52,52 +52,60 @@ type componentLog struct {
v liblog.Level
}
func (c *componentLog) _run(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
func (c *componentLog) _getFct() (func(cpt libcfg.Component) liberr.Error, func(cpt libcfg.Component) liberr.Error) {
c.m.Lock()
defer c.m.Unlock()
var (
isReload = c.l == nil
)
if c.l != nil {
return c.frb, c.fra
} else {
return c.fsb, c.fsa
}
}
if c.ctx == nil {
return ErrorComponentNotInitialized.Error(nil)
func (c *componentLog) _runFct(fct func(cpt libcfg.Component) liberr.Error) liberr.Error {
if fct != nil {
return fct(c)
}
if isReload && c.frb != nil {
if err := c.frb(); err != nil {
return err
}
} else if !isReload && c.fsb != nil {
if err := c.fsb(); err != nil {
return err
}
}
return nil
}
func (c *componentLog) _runCli(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
c.m.Lock()
defer c.m.Unlock()
if c.l == nil {
if c.ctx == nil {
return ErrorComponentNotInitialized.Error(nil)
}
c.l = liblog.New(c.ctx())
c.l.SetLevel(c.v)
}
if cnf, err := c._GetOptions(getCfg); err != nil {
return nil
}
func (c *componentLog) _run(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
var (
cnf *liblog.Options
)
fb, fa := c._getFct()
if err := c._runFct(fb); err != nil {
return err
} else if err = c._runCli(getCfg); err != nil {
return err
} else if cnf, err = c._GetOptions(getCfg); err != nil {
return err
} else if cnf == nil {
return ErrorConfigInvalid.Error(nil)
} else if e := c.l.SetOptions(cnf); e != nil {
if isReload {
return ErrorReloadLog.Error(err)
}
return ErrorStartLog.Error(err)
}
if isReload && c.fra != nil {
if err := c.fra(); err != nil {
return err
}
} else if !isReload && c.fsa != nil {
if err := c.fsa(); err != nil {
return err
}
return ErrorReloadLog.Error(err)
} else if err = c._runFct(fa); err != nil {
return err
}
return nil
@@ -117,7 +125,7 @@ func (c *componentLog) Init(key string, ctx libcfg.FuncContext, get libcfg.FuncC
c.vpr = vpr
}
func (c *componentLog) RegisterFuncStart(before, after func() liberr.Error) {
func (c *componentLog) RegisterFuncStart(before, after func(cpt libcfg.Component) liberr.Error) {
c.m.Lock()
defer c.m.Unlock()
@@ -125,7 +133,7 @@ func (c *componentLog) RegisterFuncStart(before, after func() liberr.Error) {
c.fsa = after
}
func (c *componentLog) RegisterFuncReload(before, after func() liberr.Error) {
func (c *componentLog) RegisterFuncReload(before, after func(cpt libcfg.Component) liberr.Error) {
c.m.Lock()
defer c.m.Unlock()

View File

@@ -40,10 +40,10 @@ type componentMail struct {
vpr libcfg.FuncComponentViper
key string
fsa func() liberr.Error
fsb func() liberr.Error
fra func() liberr.Error
frb func() liberr.Error
fsa func(cpt libcfg.Component) liberr.Error
fsb func(cpt libcfg.Component) liberr.Error
fra func(cpt libcfg.Component) liberr.Error
frb func(cpt libcfg.Component) liberr.Error
m sync.Mutex
e libmail.Mail
@@ -53,7 +53,26 @@ func (c *componentMail) _CheckDep() bool {
return c != nil
}
func (c *componentMail) _run(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
func (c *componentMail) _getFct() (func(cpt libcfg.Component) liberr.Error, func(cpt libcfg.Component) liberr.Error) {
c.m.Lock()
defer c.m.Unlock()
if c.e != nil {
return c.frb, c.fra
} else {
return c.fsb, c.fsa
}
}
func (c *componentMail) _runFct(fct func(cpt libcfg.Component) liberr.Error) liberr.Error {
if fct != nil {
return fct(c)
}
return nil
}
func (c *componentMail) _runCli(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
c.m.Lock()
defer c.m.Unlock()
@@ -61,24 +80,8 @@ func (c *componentMail) _run(getCfg libcfg.FuncComponentConfigGet) liberr.Error
err liberr.Error
mlr libmail.Mail
cfg libmail.Config
isReload = c.e != nil
)
if !c._CheckDep() {
return ErrorComponentNotInitialized.Error(nil)
}
if !isReload && c.fsb != nil {
if err = c.fsb(); err != nil {
return err
}
} else if isReload && c.frb != nil {
if err = c.frb(); err != nil {
return err
}
}
if cfg, err = c._getConfig(getCfg); err != nil {
return err
} else if mlr, err = cfg.NewMailer(); err != nil {
@@ -87,14 +90,22 @@ func (c *componentMail) _run(getCfg libcfg.FuncComponentConfigGet) liberr.Error
c.e = mlr
}
if !isReload && c.fsa != nil {
if err = c.fsa(); err != nil {
return err
}
} else if isReload && c.fra != nil {
if err = c.fra(); err != nil {
return err
}
return nil
}
func (c *componentMail) _run(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
if !c._CheckDep() {
return ErrorComponentNotInitialized.Error(nil)
}
fb, fa := c._getFct()
if err := c._runFct(fb); err != nil {
return err
} else if err = c._runCli(getCfg); err != nil {
return err
} else if err = c._runFct(fa); err != nil {
return err
}
return nil
@@ -114,7 +125,7 @@ func (c *componentMail) Init(key string, ctx libcfg.FuncContext, get libcfg.Func
c.vpr = vpr
}
func (c *componentMail) RegisterFuncStart(before, after func() liberr.Error) {
func (c *componentMail) RegisterFuncStart(before, after func(cpt libcfg.Component) liberr.Error) {
c.m.Lock()
defer c.m.Unlock()
@@ -122,7 +133,7 @@ func (c *componentMail) RegisterFuncStart(before, after func() liberr.Error) {
c.fsa = after
}
func (c *componentMail) RegisterFuncReload(before, after func() liberr.Error) {
func (c *componentMail) RegisterFuncReload(before, after func(cpt libcfg.Component) liberr.Error) {
c.m.Lock()
defer c.m.Unlock()

View File

@@ -44,10 +44,10 @@ type componentNats struct {
vpr libcfg.FuncComponentViper
key string
fsa func() liberr.Error
fsb func() liberr.Error
fra func() liberr.Error
frb func() liberr.Error
fsa func(cpt libcfg.Component) liberr.Error
fsb func(cpt libcfg.Component) liberr.Error
fra func(cpt libcfg.Component) liberr.Error
frb func(cpt libcfg.Component) liberr.Error
m sync.Mutex
t string
@@ -72,7 +72,26 @@ func (c *componentNats) _GetTLS() (libtls.TLSConfig, liberr.Error) {
}
}
func (c *componentNats) _run(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
func (c *componentNats) _getFct() (func(cpt libcfg.Component) liberr.Error, func(cpt libcfg.Component) liberr.Error) {
c.m.Lock()
defer c.m.Unlock()
if c.n != nil {
return c.frb, c.fra
} else {
return c.fsb, c.fsa
}
}
func (c *componentNats) _runFct(fct func(cpt libcfg.Component) liberr.Error) liberr.Error {
if fct != nil {
return fct(c)
}
return nil
}
func (c *componentNats) _runCli(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
c.m.Lock()
defer c.m.Unlock()
@@ -81,20 +100,8 @@ func (c *componentNats) _run(getCfg libcfg.FuncComponentConfigGet) liberr.Error
err liberr.Error
cfg libnat.Config
opt *natsrv.Options
isReload = c.n != nil
)
if !isReload && c.fsb != nil {
if err = c.fsb(); err != nil {
return err
}
} else if isReload && c.frb != nil {
if err = c.frb(); err != nil {
return err
}
}
if cfg, err = c._getConfig(getCfg); err != nil {
return err
}
@@ -119,14 +126,22 @@ func (c *componentNats) _run(getCfg libcfg.FuncComponentConfigGet) liberr.Error
}
}
if !isReload && c.fsa != nil {
if err = c.fsa(); err != nil {
return err
}
} else if isReload && c.fra != nil {
if err = c.fra(); err != nil {
return err
}
return nil
}
func (c *componentNats) _run(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
if !c._CheckDep() {
return ErrorComponentNotInitialized.Error(nil)
}
fb, fa := c._getFct()
if err := c._runFct(fb); err != nil {
return err
} else if err = c._runCli(getCfg); err != nil {
return err
} else if err = c._runFct(fa); err != nil {
return err
}
return nil
@@ -146,7 +161,7 @@ func (c *componentNats) Init(key string, ctx libcfg.FuncContext, get libcfg.Func
c.vpr = vpr
}
func (c *componentNats) RegisterFuncStart(before, after func() liberr.Error) {
func (c *componentNats) RegisterFuncStart(before, after func(cpt libcfg.Component) liberr.Error) {
c.m.Lock()
defer c.m.Unlock()
@@ -154,7 +169,7 @@ func (c *componentNats) RegisterFuncStart(before, after func() liberr.Error) {
c.fsa = after
}
func (c *componentNats) RegisterFuncReload(before, after func() liberr.Error) {
func (c *componentNats) RegisterFuncReload(before, after func(cpt libcfg.Component) liberr.Error) {
c.m.Lock()
defer c.m.Unlock()

View File

@@ -44,10 +44,10 @@ type componentNutsDB struct {
vpr libcfg.FuncComponentViper
key string
fsa func() liberr.Error
fsb func() liberr.Error
fra func() liberr.Error
frb func() liberr.Error
fsa func(cpt libcfg.Component) liberr.Error
fsb func(cpt libcfg.Component) liberr.Error
fra func(cpt libcfg.Component) liberr.Error
frb func(cpt libcfg.Component) liberr.Error
m sync.Mutex
l string
@@ -72,38 +72,46 @@ func (c *componentNutsDB) _GetLogger() (liblog.Logger, liberr.Error) {
}
}
func (c *componentNutsDB) _run(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
if !c._CheckDep() {
return ErrorComponentNotInitialized.Error(nil)
func (c *componentNutsDB) _getFct() (func(cpt libcfg.Component) liberr.Error, func(cpt libcfg.Component) liberr.Error) {
c.m.Lock()
defer c.m.Unlock()
if c.n != nil {
return c.frb, c.fra
} else {
return c.fsb, c.fsa
}
}
func (c *componentNutsDB) _runFct(fct func(cpt libcfg.Component) liberr.Error) liberr.Error {
if fct != nil {
return fct(c)
}
return nil
}
func (c *componentNutsDB) _runCli(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
c.m.Lock()
defer c.m.Unlock()
var (
err liberr.Error
cfg libndb.Config
isReload = c.n != nil
)
if !isReload && c.fsb != nil {
if err = c.fsb(); err != nil {
return err
}
} else if isReload && c.frb != nil {
if err = c.frb(); err != nil {
return err
}
}
if cfg, err = c._getConfig(getCfg); err != nil {
return err
}
srv := libndb.New(cfg)
srv.SetLogger(func() liblog.Logger {
if l, e := c._GetLogger(); e != nil {
var (
l liblog.Logger
e liberr.Error
)
if l, e = c._GetLogger(); e != nil {
return liblog.GetDefault()
} else {
return l
@@ -120,14 +128,22 @@ func (c *componentNutsDB) _run(getCfg libcfg.FuncComponentConfigGet) liberr.Erro
c.n = srv
if !isReload && c.fsa != nil {
if err = c.fsa(); err != nil {
return err
}
} else if isReload && c.fra != nil {
if err = c.fra(); err != nil {
return err
}
return nil
}
func (c *componentNutsDB) _run(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
if !c._CheckDep() {
return ErrorComponentNotInitialized.Error(nil)
}
fb, fa := c._getFct()
if err := c._runFct(fb); err != nil {
return err
} else if err = c._runCli(getCfg); err != nil {
return err
} else if err = c._runFct(fa); err != nil {
return err
}
return nil
@@ -147,7 +163,7 @@ func (c *componentNutsDB) Init(key string, ctx libcfg.FuncContext, get libcfg.Fu
c.vpr = vpr
}
func (c *componentNutsDB) RegisterFuncStart(before, after func() liberr.Error) {
func (c *componentNutsDB) RegisterFuncStart(before, after func(cpt libcfg.Component) liberr.Error) {
c.m.Lock()
defer c.m.Unlock()
@@ -155,7 +171,7 @@ func (c *componentNutsDB) RegisterFuncStart(before, after func() liberr.Error) {
c.fsa = after
}
func (c *componentNutsDB) RegisterFuncReload(before, after func() liberr.Error) {
func (c *componentNutsDB) RegisterFuncReload(before, after func(cpt libcfg.Component) liberr.Error) {
c.m.Lock()
defer c.m.Unlock()

View File

@@ -43,10 +43,10 @@ type componentRequest struct {
vpr libcfg.FuncComponentViper
key string
fsa func() liberr.Error
fsb func() liberr.Error
fra func() liberr.Error
frb func() liberr.Error
fsa func(cpt libcfg.Component) liberr.Error
fsb func(cpt libcfg.Component) liberr.Error
fra func(cpt libcfg.Component) liberr.Error
frb func(cpt libcfg.Component) liberr.Error
m sync.Mutex
r libreq.Request
@@ -85,21 +85,28 @@ func (c *componentRequest) _GetTLS() libtls.TLSConfig {
}
}
func (c *componentRequest) _run(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
func (c *componentRequest) _getFct() (func(cpt libcfg.Component) liberr.Error, func(cpt libcfg.Component) liberr.Error) {
c.m.Lock()
defer c.m.Unlock()
var isReload = c.r != nil
if isReload && c.frb != nil {
if err := c.frb(); err != nil {
return err
}
} else if !isReload && c.fsb != nil {
if err := c.fsb(); err != nil {
return err
}
if c.r != nil {
return c.frb, c.fra
} else {
return c.fsb, c.fsa
}
}
func (c *componentRequest) _runFct(fct func(cpt libcfg.Component) liberr.Error) liberr.Error {
if fct != nil {
return fct(c)
}
return nil
}
func (c *componentRequest) _runCli(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
c.m.Lock()
defer c.m.Unlock()
cfg := libreq.Options{}
cfg.SetDefaultTLS(c._GetTLS)
@@ -108,7 +115,7 @@ func (c *componentRequest) _run(getCfg libcfg.FuncComponentConfigGet) liberr.Err
return ErrorParamsInvalid.Error(err)
}
if !isReload {
if c.r == nil {
if r, e := cfg.New(c._GetContext, c.c, c._GetTLS); e != nil {
return ErrorConfigInvalid.ErrorParent(e)
} else {
@@ -122,14 +129,18 @@ func (c *componentRequest) _run(getCfg libcfg.FuncComponentConfigGet) liberr.Err
}
}
if isReload && c.fra != nil {
if err := c.fra(); err != nil {
return err
}
} else if !isReload && c.fsa != nil {
if err := c.fsa(); err != nil {
return err
}
return nil
}
func (c *componentRequest) _run(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
fb, fa := c._getFct()
if err := c._runFct(fb); err != nil {
return err
} else if err = c._runCli(getCfg); err != nil {
return err
} else if err = c._runFct(fa); err != nil {
return err
}
return nil
@@ -149,7 +160,7 @@ func (c *componentRequest) Init(key string, ctx libcfg.FuncContext, get libcfg.F
c.vpr = vpr
}
func (c *componentRequest) RegisterFuncStart(before, after func() liberr.Error) {
func (c *componentRequest) RegisterFuncStart(before, after func(cpt libcfg.Component) liberr.Error) {
c.m.Lock()
defer c.m.Unlock()
@@ -157,7 +168,7 @@ func (c *componentRequest) RegisterFuncStart(before, after func() liberr.Error)
c.fsa = after
}
func (c *componentRequest) RegisterFuncReload(before, after func() liberr.Error) {
func (c *componentRequest) RegisterFuncReload(before, after func(cpt libcfg.Component) liberr.Error) {
c.m.Lock()
defer c.m.Unlock()

View File

@@ -43,10 +43,10 @@ type componentSmtp struct {
vpr libcfg.FuncComponentViper
key string
fsa func() liberr.Error
fsb func() liberr.Error
fra func() liberr.Error
frb func() liberr.Error
fsa func(cpt libcfg.Component) liberr.Error
fsb func(cpt libcfg.Component) liberr.Error
fra func(cpt libcfg.Component) liberr.Error
frb func(cpt libcfg.Component) liberr.Error
m sync.Mutex
t string
@@ -71,11 +71,26 @@ func (c *componentSmtp) _GetTLS() (libtls.TLSConfig, liberr.Error) {
}
}
func (c *componentSmtp) _run(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
if !c._CheckDep() {
return ErrorComponentNotInitialized.Error(nil)
func (c *componentSmtp) _getFct() (func(cpt libcfg.Component) liberr.Error, func(cpt libcfg.Component) liberr.Error) {
c.m.Lock()
defer c.m.Unlock()
if c.s != nil {
return c.frb, c.fra
} else {
return c.fsb, c.fsa
}
}
func (c *componentSmtp) _runFct(fct func(cpt libcfg.Component) liberr.Error) liberr.Error {
if fct != nil {
return fct(c)
}
return nil
}
func (c *componentSmtp) _runCli(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
c.m.Lock()
defer c.m.Unlock()
@@ -83,45 +98,40 @@ func (c *componentSmtp) _run(getCfg libcfg.FuncComponentConfigGet) liberr.Error
err liberr.Error
cli libsmtp.SMTP
cfg libsmtp.ConfigModel
isReload = c.s != nil
)
if !isReload && c.fsb != nil {
if err = c.fsb(); err != nil {
return err
}
} else if isReload && c.frb != nil {
if err = c.frb(); err != nil {
return err
}
}
if cfg, err = c._getConfig(getCfg); err != nil {
return err
}
if cli, err = cfg.GetSMTP(); err != nil {
if isReload {
if c.s != nil {
return ErrorReloadComponent.Error(err)
}
return ErrorStartComponent.Error(err)
}
if isReload {
if c.s != nil {
_ = c.s.Close
}
c.s = cli
return nil
}
if !isReload && c.fsa != nil {
if err = c.fsa(); err != nil {
return err
}
} else if isReload && c.fra != nil {
if err = c.fra(); err != nil {
return err
}
func (c *componentSmtp) _run(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
if !c._CheckDep() {
return ErrorComponentNotInitialized.Error(nil)
}
fb, fa := c._getFct()
if err := c._runFct(fb); err != nil {
return err
} else if err = c._runCli(getCfg); err != nil {
return err
} else if err = c._runFct(fa); err != nil {
return err
}
return nil
@@ -141,7 +151,7 @@ func (c *componentSmtp) Init(key string, ctx libcfg.FuncContext, get libcfg.Func
c.vpr = vpr
}
func (c *componentSmtp) RegisterFuncStart(before, after func() liberr.Error) {
func (c *componentSmtp) RegisterFuncStart(before, after func(cpt libcfg.Component) liberr.Error) {
c.m.Lock()
defer c.m.Unlock()
@@ -149,7 +159,7 @@ func (c *componentSmtp) RegisterFuncStart(before, after func() liberr.Error) {
c.fsa = after
}
func (c *componentSmtp) RegisterFuncReload(before, after func() liberr.Error) {
func (c *componentSmtp) RegisterFuncReload(before, after func(cpt libcfg.Component) liberr.Error) {
c.m.Lock()
defer c.m.Unlock()

View File

@@ -40,16 +40,35 @@ type componentTls struct {
vpr libcfg.FuncComponentViper
key string
fsa func() liberr.Error
fsb func() liberr.Error
fra func() liberr.Error
frb func() liberr.Error
fsa func(cpt libcfg.Component) liberr.Error
fsb func(cpt libcfg.Component) liberr.Error
fra func(cpt libcfg.Component) liberr.Error
frb func(cpt libcfg.Component) liberr.Error
m sync.Mutex
t libtls.TLSConfig
}
func (c *componentTls) _run(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
func (c *componentTls) _getFct() (func(cpt libcfg.Component) liberr.Error, func(cpt libcfg.Component) liberr.Error) {
c.m.Lock()
defer c.m.Unlock()
if c.t != nil {
return c.frb, c.fra
} else {
return c.fsb, c.fsa
}
}
func (c *componentTls) _runFct(fct func(cpt libcfg.Component) liberr.Error) liberr.Error {
if fct != nil {
return fct(c)
}
return nil
}
func (c *componentTls) _runCli(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
c.m.Lock()
defer c.m.Unlock()
@@ -57,24 +76,12 @@ func (c *componentTls) _run(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
err liberr.Error
cfg *libtls.Config
tls libtls.TLSConfig
isReload = c.t != nil
)
if !isReload && c.fsb != nil {
if err = c.fsb(); err != nil {
return err
}
} else if isReload && c.frb != nil {
if err = c.frb(); err != nil {
return err
}
}
if cfg, err = c._getConfig(getCfg); err != nil {
return err
} else if tls, err = cfg.New(); err != nil {
if isReload {
if c.t != nil {
return ErrorComponentReload.Error(err)
}
return ErrorComponentStart.Error(err)
@@ -82,14 +89,18 @@ func (c *componentTls) _run(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
c.t = tls
}
if !isReload && c.fsa != nil {
if err = c.fsa(); err != nil {
return err
}
} else if isReload && c.fra != nil {
if err = c.fra(); err != nil {
return err
}
return nil
}
func (c *componentTls) _run(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
fb, fa := c._getFct()
if err := c._runFct(fb); err != nil {
return err
} else if err = c._runCli(getCfg); err != nil {
return err
} else if err = c._runFct(fa); err != nil {
return err
}
return nil
@@ -109,7 +120,7 @@ func (c *componentTls) Init(key string, ctx libcfg.FuncContext, get libcfg.FuncC
c.vpr = vpr
}
func (c *componentTls) RegisterFuncStart(before, after func() liberr.Error) {
func (c *componentTls) RegisterFuncStart(before, after func(cpt libcfg.Component) liberr.Error) {
c.m.Lock()
defer c.m.Unlock()
@@ -117,7 +128,7 @@ func (c *componentTls) RegisterFuncStart(before, after func() liberr.Error) {
c.fsa = after
}
func (c *componentTls) RegisterFuncReload(before, after func() liberr.Error) {
func (c *componentTls) RegisterFuncReload(before, after func(cpt libcfg.Component) liberr.Error) {
c.m.Lock()
defer c.m.Unlock()

53
go.mod
View File

@@ -7,28 +7,28 @@ require (
github.com/aws/aws-sdk-go-v2/config v1.15.3
github.com/aws/aws-sdk-go-v2/credentials v1.11.2
github.com/aws/aws-sdk-go-v2/service/iam v1.18.3
github.com/aws/aws-sdk-go-v2/service/s3 v1.26.3
github.com/aws/aws-sdk-go-v2/service/s3 v1.26.5
github.com/bits-and-blooms/bitset v1.2.2
github.com/c-bata/go-prompt v0.2.6
github.com/fatih/color v1.13.0
github.com/fsnotify/fsnotify v1.5.1
github.com/fxamacker/cbor/v2 v2.4.0
github.com/gin-gonic/gin v1.7.7
github.com/go-ldap/ldap/v3 v3.4.2
github.com/go-ldap/ldap/v3 v3.4.3
github.com/go-playground/validator/v10 v10.10.1
github.com/google/go-github/v33 v33.0.0
github.com/hashicorp/go-hclog v1.2.0
github.com/hashicorp/go-retryablehttp v0.7.0
github.com/hashicorp/go-uuid v1.0.2
github.com/hashicorp/go-retryablehttp v0.7.1
github.com/hashicorp/go-uuid v1.0.3
github.com/hashicorp/go-version v1.4.0
github.com/jlaffaye/ftp v0.0.0-20220310202011-d2c44e311e78
github.com/lni/dragonboat/v3 v3.3.5
github.com/matcornic/hermes/v2 v2.1.0
github.com/mattn/go-colorable v0.1.12
github.com/mitchellh/go-homedir v1.1.0
github.com/nats-io/jwt/v2 v2.2.1-0.20220113022732-58e87895b296
github.com/nats-io/nats-server/v2 v2.7.4
github.com/nats-io/nats.go v1.13.1-0.20220308171302-2f2f6968e98d
github.com/nats-io/jwt/v2 v2.2.1-0.20220330180145-442af02fd36a
github.com/nats-io/nats-server/v2 v2.8.0
github.com/nats-io/nats.go v1.14.0
github.com/onsi/ginkgo/v2 v2.1.3
github.com/onsi/gomega v1.19.0
github.com/pelletier/go-toml v1.9.4
@@ -38,28 +38,28 @@ require (
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.4.0
github.com/spf13/jwalterweatherman v1.1.0
github.com/spf13/viper v1.10.1
github.com/spf13/viper v1.11.0
github.com/vbauerster/mpb/v5 v5.4.0
github.com/xanzy/go-gitlab v0.62.0
github.com/xanzy/go-gitlab v0.63.0
github.com/xhit/go-simple-mail v2.2.2+incompatible
github.com/xujiajun/nutsdb v0.8.0
github.com/xujiajun/utils v0.0.0-20190123093513-8bf096c4f53b
golang.org/x/net v0.0.0-20220403103023-749bd193bc2b
golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a
golang.org/x/net v0.0.0-20220418201149-a630d4f3e7a2
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/sys v0.0.0-20220406163625-3f8b81556e12
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad
golang.org/x/term v0.0.0-20220411215600-e5f449aeb171
gopkg.in/yaml.v2 v2.4.0
gorm.io/driver/clickhouse v0.3.1
gorm.io/driver/mysql v1.3.3
gorm.io/driver/postgres v1.3.3
gorm.io/driver/postgres v1.3.4
gorm.io/driver/sqlite v1.3.1
gorm.io/driver/sqlserver v1.3.2
gorm.io/gorm v1.23.4
)
require (
github.com/Azure/go-ntlmssp v0.0.0-20200615164410-66371956d46c // indirect
github.com/Azure/go-ntlmssp v0.0.0-20211209120228-48547f28849e // indirect
github.com/ClickHouse/clickhouse-go v1.5.4 // indirect
github.com/Masterminds/semver v1.4.2 // indirect
github.com/Masterminds/sprig v2.16.0+incompatible // indirect
@@ -75,6 +75,7 @@ require (
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.9 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.3 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.10 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.0.0 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.1 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.3 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.3 // indirect
@@ -93,16 +94,16 @@ require (
github.com/cockroachdb/sentry-go v0.6.1-cockroachdb.2 // indirect
github.com/denisenkom/go-mssqldb v0.12.0 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-asn1-ber/asn1-ber v1.5.1 // indirect
github.com/go-asn1-ber/asn1-ber v1.5.4 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/gogo/protobuf v1.3.1 // indirect
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe // indirect
github.com/golang-sql/sqlexp v0.0.0-20170517235910-f1bb20e5a188 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.3 // indirect
github.com/golang/snappy v0.0.3-0.20201103224600-674baa8c7fc3 // indirect
github.com/google/btree v1.0.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/uuid v1.1.2 // indirect
@@ -115,7 +116,7 @@ require (
github.com/hashicorp/go-sockaddr v1.0.0 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/memberlist v0.3.0 // indirect
github.com/hashicorp/memberlist v0.2.2 // indirect
github.com/huandu/xstrings v1.2.0 // indirect
github.com/imdario/mergo v0.3.6 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
@@ -137,13 +138,13 @@ require (
github.com/kr/text v0.2.0 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/lni/goutils v1.3.0 // indirect
github.com/magiconair/properties v1.8.5 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/mattn/go-sqlite3 v1.14.9 // indirect
github.com/mattn/go-tty v0.0.3 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/miekg/dns v1.1.41 // indirect
github.com/miekg/dns v1.1.26 // indirect
github.com/minio/highwayhash v1.0.2 // indirect
github.com/mitchellh/mapstructure v1.4.3 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
@@ -151,6 +152,7 @@ require (
github.com/nats-io/nkeys v0.3.0 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
github.com/olekukonko/tablewriter v0.0.1 // indirect
github.com/pelletier/go-toml/v2 v2.0.0-beta.8 // indirect
github.com/pkg/term v1.2.0-beta.2 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
@@ -158,7 +160,7 @@ require (
github.com/rogpeppe/go-internal v1.8.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 // indirect
github.com/spf13/afero v1.6.0 // indirect
github.com/spf13/afero v1.8.2 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf // indirect
@@ -171,11 +173,12 @@ require (
github.com/x448/float16 v0.8.4 // indirect
github.com/xujiajun/mmap-go v1.0.1 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
golang.org/x/crypto v0.0.0-20220112180741-5e0467b6c7ce // indirect
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
golang.org/x/exp v0.0.0-20200513190911-00229845015e // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/ini.v1 v1.66.2 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/ini.v1 v1.66.4 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)