- Package AWS : extend aws helper to manage accessKey
	- Package Cobra : refactor configure function to allow use independant part of the command
	- Package ldap : fix error
	- Package config
		- interface : add shutdown method
		- components:
			- request : syntax error in default json
			- mail : syntax error default json
			- ldap :
				- allow to access loaded config
				- mutex lock circular
			- tls : allow to access loaded config
	- Package request :
		- add error managment
		- fix error with circular mutex
		- fix bug with empty response body
		- fix some other errors
	- Package status : default label in component default config
	- Bump dependancies
	- Bump yaml to v3 (in waiting fix for CVE-2022-28948)
	- force dependancies gogo/protobuff to v1.3.2+
This commit is contained in:
Nicolas JUHEL
2022-05-23 11:01:03 +02:00
parent 01308cc8f2
commit 90ceb19d2f
19 changed files with 397 additions and 277 deletions

View File

@@ -26,19 +26,33 @@
package user
import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/iam"
"github.com/aws/aws-sdk-go-v2/service/iam/types"
"github.com/nabbar/golib/aws/helper"
"github.com/nabbar/golib/errors"
sdkaws "github.com/aws/aws-sdk-go-v2/aws"
sdkiam "github.com/aws/aws-sdk-go-v2/service/iam"
sdktps "github.com/aws/aws-sdk-go-v2/service/iam/types"
awshlp "github.com/nabbar/golib/aws/helper"
liberr "github.com/nabbar/golib/errors"
)
func (cli *client) AccessList(username string) (map[string]bool, errors.Error) {
var req = &iam.ListAccessKeysInput{}
func (cli *client) AccessListAll() ([]sdktps.AccessKeyMetadata, liberr.Error) {
var req = &sdkiam.ListAccessKeysInput{}
out, err := cli.iam.ListAccessKeys(cli.GetContext(), req)
if err != nil {
return nil, cli.GetError(err)
} else if out.AccessKeyMetadata == nil {
return nil, awshlp.ErrorResponse.Error(nil)
} else {
return out.AccessKeyMetadata, nil
}
}
func (cli *client) AccessList(username string) (map[string]bool, liberr.Error) {
var req = &sdkiam.ListAccessKeysInput{}
if username != "" {
req = &iam.ListAccessKeysInput{
UserName: aws.String(username),
req = &sdkiam.ListAccessKeysInput{
UserName: sdkaws.String(username),
}
}
@@ -47,15 +61,15 @@ func (cli *client) AccessList(username string) (map[string]bool, errors.Error) {
if err != nil {
return nil, cli.GetError(err)
} else if out.AccessKeyMetadata == nil {
return nil, helper.ErrorResponse.Error(nil)
return nil, awshlp.ErrorResponse.Error(nil)
} else {
var res = make(map[string]bool)
for _, a := range out.AccessKeyMetadata {
switch a.Status {
case types.StatusTypeActive:
case sdktps.StatusTypeActive:
res[*a.AccessKeyId] = true
case types.StatusTypeInactive:
case sdktps.StatusTypeInactive:
res[*a.AccessKeyId] = false
}
}
@@ -64,12 +78,12 @@ func (cli *client) AccessList(username string) (map[string]bool, errors.Error) {
}
}
func (cli *client) AccessCreate(username string) (string, string, errors.Error) {
var req = &iam.CreateAccessKeyInput{}
func (cli *client) AccessCreate(username string) (string, string, liberr.Error) {
var req = &sdkiam.CreateAccessKeyInput{}
if username != "" {
req = &iam.CreateAccessKeyInput{
UserName: aws.String(username),
req = &sdkiam.CreateAccessKeyInput{
UserName: sdkaws.String(username),
}
}
@@ -78,21 +92,21 @@ func (cli *client) AccessCreate(username string) (string, string, errors.Error)
if err != nil {
return "", "", cli.GetError(err)
} else if out.AccessKey == nil {
return "", "", helper.ErrorResponse.Error(nil)
return "", "", awshlp.ErrorResponse.Error(nil)
} else {
return *out.AccessKey.AccessKeyId, *out.AccessKey.SecretAccessKey, nil
}
}
func (cli *client) AccessDelete(username, accessKey string) errors.Error {
var req = &iam.DeleteAccessKeyInput{
AccessKeyId: aws.String(accessKey),
func (cli *client) AccessDelete(username, accessKey string) liberr.Error {
var req = &sdkiam.DeleteAccessKeyInput{
AccessKeyId: sdkaws.String(accessKey),
}
if username != "" {
req = &iam.DeleteAccessKeyInput{
AccessKeyId: aws.String(accessKey),
UserName: aws.String(username),
req = &sdkiam.DeleteAccessKeyInput{
AccessKeyId: sdkaws.String(accessKey),
UserName: sdkaws.String(username),
}
}

View File

@@ -29,7 +29,7 @@ import (
"context"
sdkiam "github.com/aws/aws-sdk-go-v2/service/iam"
sdkitp "github.com/aws/aws-sdk-go-v2/service/iam/types"
sdktps "github.com/aws/aws-sdk-go-v2/service/iam/types"
sdksss "github.com/aws/aws-sdk-go-v2/service/s3"
libhlp "github.com/nabbar/golib/aws/helper"
liberr "github.com/nabbar/golib/errors"
@@ -43,7 +43,7 @@ type client struct {
type User interface {
List() (map[string]string, liberr.Error)
Get(username string) (*sdkitp.User, liberr.Error)
Get(username string) (*sdktps.User, liberr.Error)
Create(username string) liberr.Error
Delete(username string) liberr.Error
@@ -54,6 +54,7 @@ type User interface {
LoginCreate(username, password string) liberr.Error
LoginDelete(username string) liberr.Error
AccessListAll() ([]sdktps.AccessKeyMetadata, liberr.Error)
AccessList(username string) (map[string]bool, liberr.Error)
AccessCreate(username string) (string, string, liberr.Error)
AccessDelete(username, accessKey string) liberr.Error

View File

@@ -38,12 +38,14 @@ import (
"github.com/mitchellh/go-homedir"
"github.com/pelletier/go-toml"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"
liblog "github.com/nabbar/golib/logger"
spfcbr "github.com/spf13/cobra"
)
var cfgFile string
func (c *cobra) getDefaultPath(baseName string) (string, error) {
path := ""
@@ -65,65 +67,7 @@ func (c *cobra) getDefaultPath(baseName string) (string, error) {
return path, nil
}
func (c *cobra) AddCommandConfigure(basename string, defaultConfig func() io.Reader) {
pkg := c.getPackageName()
if basename == "" && pkg != "" {
basename = "." + strings.ToLower(pkg)
}
var cfgFile string
c.c.AddCommand(&spfcbr.Command{
Use: "configure <file path with valid extension (json, yaml, toml, ...) to be generated>",
Example: "configure ~/." + strings.ToLower(pkg) + ".yml",
Short: "Generate config file",
Long: `Generates a configuration file based on giving existing config flag
override by passed flag in command line and completed with default for non existing values.`,
Run: func(cmd *spfcbr.Command, args []string) {
var fs *os.File
defer func() {
if fs != nil {
_ = fs.Close()
}
}()
buf, err := ioutil.ReadAll(defaultConfig())
c.getLog().CheckError(liblog.FatalLevel, liblog.DebugLevel, "reading default config", err)
if len(path.Ext(cfgFile)) > 0 && strings.ToLower(path.Ext(cfgFile)) != ".json" {
var mod = make(map[string]interface{}, 0)
err = json.Unmarshal(buf, &mod)
c.getLog().CheckError(liblog.FatalLevel, liblog.DebugLevel, "transform json default config", err)
switch strings.ToLower(path.Ext(cfgFile)) {
case ".toml":
buf, err = toml.Marshal(mod)
case ".yml", ".yaml":
buf, err = yaml.Marshal(mod)
default:
c.getLog().CheckError(liblog.FatalLevel, liblog.DebugLevel, "get encode for extension file", fmt.Errorf("extension file '%s' not compatible", path.Ext(cfgFile)))
}
}
fs, err = os.OpenFile(cfgFile, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0600)
c.getLog().CheckError(liblog.FatalLevel, liblog.DebugLevel, "opening destination config file for exclusive write with truncate", err)
_, err = fs.Write(buf)
c.getLog().CheckError(liblog.FatalLevel, liblog.DebugLevel, fmt.Sprintf("writing config to file '%s'", cfgFile), err)
err = os.Chmod(cfgFile, 0600)
if !c.getLog().CheckError(liblog.ErrorLevel, liblog.InfoLevel, fmt.Sprintf("setting permission for config file '%s'", cfgFile), err) {
println(fmt.Sprintf("\n\t>> Config File '%s' has been created and file permission have been set.", cfgFile))
println("\t>> To explicitly specify this config file when you call this tool, use the '-c' flag like this: ")
println(fmt.Sprintf("\t\t\t %s -c %s <cmd>...\n", pkg, cfgFile))
}
},
Args: func(cmd *spfcbr.Command, args []string) error {
func (c *cobra) ConfigureCheckArgs(basename string, args []string) error {
if len(args) < 1 {
var err error
cfgFile, err = c.getDefaultPath(basename)
@@ -135,6 +79,89 @@ override by passed flag in command line and completed with default for non exist
}
return nil
}
func (c *cobra) ConfigureWriteConfig(basename string, defaultConfig func() io.Reader) error {
pkg := c.getPackageName()
if basename == "" && pkg != "" {
basename = "." + strings.ToLower(pkg)
}
var (
fs *os.File
)
defer func() {
if fs != nil {
_ = fs.Close()
}
}()
buf, err := ioutil.ReadAll(defaultConfig())
if err != nil {
return err
}
if len(path.Ext(cfgFile)) > 0 && strings.ToLower(path.Ext(cfgFile)) != ".json" {
var mod = make(map[string]interface{}, 0)
err = json.Unmarshal(buf, &mod)
if err != nil {
return err
}
switch strings.ToLower(path.Ext(cfgFile)) {
case ".toml":
buf, err = toml.Marshal(mod)
case ".yml", ".yaml":
buf, err = yaml.Marshal(mod)
default:
return fmt.Errorf("extension file '%s' not compatible", path.Ext(cfgFile))
}
}
fs, err = os.OpenFile(cfgFile, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0600)
if err != nil {
return err
}
_, err = fs.Write(buf)
if err != nil {
return err
}
err = os.Chmod(cfgFile, 0600)
if err != nil {
return err
}
println(fmt.Sprintf("\n\t>> Config File '%s' has been created and file permission have been set.", cfgFile))
println("\t>> To explicitly specify this config file when you call this tool, use the '-c' flag like this: ")
println(fmt.Sprintf("\t\t\t %s -c %s <cmd>...\n", pkg, cfgFile))
return nil
}
func (c *cobra) AddCommandConfigure(basename string, defaultConfig func() io.Reader) {
pkg := c.getPackageName()
if basename == "" && pkg != "" {
basename = "." + strings.ToLower(pkg)
}
c.c.AddCommand(&spfcbr.Command{
Use: "configure <file path with valid extension (json, yaml, toml, ...) to be generated>",
Example: "configure ~/." + strings.ToLower(pkg) + ".yml",
Short: "Generate config file",
Long: `Generates a configuration file based on giving existing config flag
override by passed flag in command line and completed with default for non existing values.`,
RunE: func(cmd *spfcbr.Command, args []string) error {
return c.ConfigureWriteConfig(basename, defaultConfig)
},
Args: func(cmd *spfcbr.Command, args []string) error {
return c.ConfigureCheckArgs(basename, args)
},
})
}

View File

@@ -63,6 +63,9 @@ type Cobra interface {
Execute() error
Cobra() *spfcbr.Command
ConfigureCheckArgs(basename string, args []string) error
ConfigureWriteConfig(basename string, defaultConfig func() io.Reader) error
}
func New() Cobra {

View File

@@ -43,6 +43,7 @@ const (
type ComponentLDAP interface {
libcfg.Component
Config() *lbldap.Config
LDAP() *lbldap.HelperLDAP
}

View File

@@ -47,6 +47,7 @@ type componentLDAP struct {
frb func(cpt libcfg.Component) liberr.Error
m sync.Mutex
c *lbldap.Config
l *lbldap.HelperLDAP
}
@@ -86,7 +87,7 @@ func (c *componentLDAP) _runFct(fct func(cpt libcfg.Component) liberr.Error) lib
return nil
}
func (c *componentLDAP) _runCli(getCfg libcfg.FuncComponentConfigGet) liberr.Error {
func (c *componentLDAP) _runCli(ctx context.Context, getCfg libcfg.FuncComponentConfigGet) liberr.Error {
c.m.Lock()
defer c.m.Unlock()
@@ -95,10 +96,11 @@ func (c *componentLDAP) _runCli(getCfg libcfg.FuncComponentConfigGet) liberr.Err
return ErrorParamsInvalid.Error(err)
}
if l, e := lbldap.NewLDAP(c._GetContext(), &cfg, nil); e != nil {
if l, e := lbldap.NewLDAP(ctx, &cfg, nil); e != nil {
return ErrorConfigInvalid.ErrorParent(e)
} else {
c.l = l
c.c = &cfg
}
return nil
@@ -109,7 +111,7 @@ func (c *componentLDAP) _run(getCfg libcfg.FuncComponentConfigGet) liberr.Error
if err := c._runFct(fb); err != nil {
return err
} else if err = c._runCli(getCfg); err != nil {
} else if err = c._runCli(c._GetContext(), getCfg); err != nil {
return err
} else if err = c._runFct(fa); err != nil {
return err
@@ -175,6 +177,13 @@ func (c *componentLDAP) Dependencies() []string {
return make([]string, 0)
}
func (c *componentLDAP) Config() *lbldap.Config {
c.m.Lock()
defer c.m.Unlock()
return c.c
}
func (c *componentLDAP) LDAP() *lbldap.HelperLDAP {
c.m.Lock()
defer c.m.Unlock()

View File

@@ -42,9 +42,9 @@ var _defaultConfig = []byte(`{
"subject": "",
"encoding": "",
"priority": "",
"headers": [
""
],
"headers": {
"": ""
},
"from": "",
"sender": "",
"replyTo": "",

View File

@@ -78,7 +78,7 @@ var _defaultConfig = []byte(`{
"valid_http_code": [200, 201, 202, 203, 204],
"invalid_http_code": [401, 403, 404, 405, 500, 501, 502, 503, 504],
"contain": ["OK", "Done"],
"not_contain": ["KO", "fail", "error"],
"not_contain": ["KO", "fail", "error"]
},
"status": ` + string(libsts.DefaultConfig(" ")) + `
}

View File

@@ -37,6 +37,7 @@ const (
type ComponentTlS interface {
libcfg.Component
Config() *libtls.Config
GetTLS() libtls.TLSConfig
SetTLS(tls libtls.TLSConfig)
}

View File

@@ -47,6 +47,7 @@ type componentTls struct {
m sync.Mutex
t libtls.TLSConfig
c *libtls.Config
}
func (c *componentTls) _getFct() (func(cpt libcfg.Component) liberr.Error, func(cpt libcfg.Component) liberr.Error) {
@@ -87,6 +88,7 @@ func (c *componentTls) _runCli(getCfg libcfg.FuncComponentConfigGet) liberr.Erro
return ErrorComponentStart.Error(err)
} else {
c.t = tls
c.c = cfg
}
return nil
@@ -163,6 +165,13 @@ func (c *componentTls) Dependencies() []string {
return make([]string, 0)
}
func (c *componentTls) Config() *libtls.Config {
c.m.Lock()
defer c.m.Unlock()
return c.c
}
func (c *componentTls) GetTLS() libtls.TLSConfig {
c.m.Lock()
defer c.m.Unlock()

View File

@@ -112,6 +112,12 @@ type Config interface {
// is trigger. This func is call after the stop sequence.
RegisterFuncStopAfter(fct func())
// Shutdown will trigger all stop function.
// This function will call the Stop function and the private function cancel.
// This will stop all process and do like a SIGTERM/SIGINT signal.
// This will finish by an os.Exit with the given parameter code.
Shutdown(code int)
/*
// Section Component : github.com/nabbar/golib/config
*/

View File

@@ -29,6 +29,7 @@ package config
import (
"context"
"fmt"
"os"
libctx "github.com/nabbar/golib/context"
liberr "github.com/nabbar/golib/errors"
@@ -227,6 +228,11 @@ func (c *configModel) RegisterFuncStopAfter(fct func()) {
c.fctStopAfter = fct
}
func (c *configModel) Shutdown(code int) {
c.cancel()
os.Exit(code)
}
func (c *configModel) ComponentHas(key string) bool {
return c.cpt.ComponentHas(key)
}

240
go.mod
View File

@@ -2,194 +2,186 @@ module github.com/nabbar/golib
go 1.18
require (
github.com/aws/aws-sdk-go-v2 v1.16.3
github.com/aws/aws-sdk-go-v2/config v1.15.4
github.com/aws/aws-sdk-go-v2/credentials v1.12.0
github.com/aws/aws-sdk-go-v2/service/iam v1.18.4
github.com/aws/aws-sdk-go-v2/service/s3 v1.26.7
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.4
github.com/fxamacker/cbor/v2 v2.4.0
github.com/gin-gonic/gin v1.7.7
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.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.1.1-0.20220423051305-68cf0ad96f46
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.20220330180145-442af02fd36a
github.com/nats-io/nats-server/v2 v2.8.1
github.com/nats-io/nats.go v1.14.0
github.com/onsi/ginkgo/v2 v2.1.4
github.com/onsi/gomega v1.19.0
github.com/pelletier/go-toml v1.9.5
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.12.1
github.com/shirou/gopsutil v3.21.11+incompatible
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.11.0
github.com/vbauerster/mpb/v5 v5.4.0
github.com/xanzy/go-gitlab v0.64.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-20220425223048-2871e0cb64e4
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-20220422013727-9388b58f7150
golang.org/x/term v0.0.0-20220411215600-e5f449aeb171
gopkg.in/yaml.v2 v2.4.0
gorm.io/driver/clickhouse v0.3.2
gorm.io/driver/mysql v1.3.3
gorm.io/driver/postgres v1.3.5
gorm.io/driver/sqlite v1.3.2
gorm.io/driver/sqlserver v1.3.2
gorm.io/gorm v1.23.5
)
require (
github.com/Azure/go-ntlmssp v0.0.0-20211209120228-48547f28849e // indirect
github.com/ClickHouse/clickhouse-go v1.5.4 // indirect
github.com/DataDog/zstd v1.5.2 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Masterminds/sprig v2.22.0+incompatible // indirect
github.com/PuerkitoBio/goquery v1.8.0 // indirect
github.com/VictoriaMetrics/metrics v1.18.1 // indirect
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/ClickHouse/clickhouse-go/v2 v2.2.0 // indirect
github.com/Masterminds/semver v1.4.2 // indirect
github.com/Masterminds/sprig v2.16.0+incompatible // indirect
github.com/PuerkitoBio/goquery v1.5.0 // indirect
github.com/VictoriaMetrics/metrics v1.6.2 // indirect
github.com/VividCortex/ewma v1.1.1 // indirect
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
github.com/andybalholm/cascadia v1.3.1 // indirect
github.com/aokoli/goutils v1.1.1 // indirect
github.com/armon/go-metrics v0.3.11 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.1 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.4 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.10 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.4 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.11 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.0.1 // 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.5 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.4 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.13.4 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.11.4 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.16.4 // indirect
github.com/aws/smithy-go v1.11.2 // indirect
github.com/andybalholm/cascadia v1.0.0 // indirect
github.com/aokoli/goutils v1.0.1 // indirect
github.com/armon/go-metrics v0.3.10 // indirect
github.com/aws/aws-sdk-go-v2 v1.16.7 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.3 // indirect
github.com/aws/aws-sdk-go-v2/config v1.15.14 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.12.9 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.8 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.14 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.8 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.15 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.0.5 // indirect
github.com/aws/aws-sdk-go-v2/service/iam v1.18.9 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.3 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.9 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.8 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.13.8 // indirect
github.com/aws/aws-sdk-go-v2/service/s3 v1.27.1 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.11.12 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.16.9 // indirect
github.com/aws/smithy-go v1.12.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.3.0 // indirect
github.com/bwmarrin/snowflake v0.3.0 // indirect
github.com/c-bata/go-prompt v0.2.6 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58 // indirect
github.com/cockroachdb/errors v1.9.0 // indirect
github.com/cockroachdb/logtags v0.0.0-20211118104740-dabe8e521a4f // indirect
github.com/cockroachdb/pebble v0.0.0-20220428002600-b9e970a83ddd // indirect
github.com/cockroachdb/redact v1.1.3 // indirect
github.com/cockroachdb/errors v1.7.5 // indirect
github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f // indirect
github.com/cockroachdb/pebble v0.0.0-20210331181633-27fc006b8bfb // indirect
github.com/cockroachdb/redact v1.0.6 // indirect
github.com/cockroachdb/sentry-go v0.6.1-cockroachdb.2 // indirect
github.com/codahale/hdrhistogram v0.9.0 // indirect
github.com/denisenkom/go-mssqldb v0.12.0 // indirect
github.com/getsentry/sentry-go v0.13.0 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/fxamacker/cbor/v2 v2.4.0 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/gin-gonic/gin v1.8.1 // indirect
github.com/go-asn1-ber/asn1-ber v1.5.4 // indirect
github.com/go-ldap/ldap/v3 v3.4.3 // 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-playground/validator/v10 v10.11.0 // indirect
github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/goccy/go-json v0.9.7 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // 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.4 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/golang/snappy v0.0.3-0.20201103224600-674baa8c7fc3 // indirect
github.com/google/btree v1.0.0 // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/google/go-github/v33 v33.0.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/css v1.0.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-hclog v1.2.1 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-msgpack v1.1.5 // indirect
github.com/hashicorp/go-msgpack v0.5.3 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-sockaddr v1.0.2 // indirect
github.com/hashicorp/go-retryablehttp v0.7.1 // indirect
github.com/hashicorp/go-sockaddr v1.0.0 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/hashicorp/go-version v1.6.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.1 // indirect
github.com/huandu/xstrings v1.3.2 // indirect
github.com/imdario/mergo v0.3.12 // 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
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.12.0 // indirect
github.com/jackc/pgconn v1.12.1 // indirect
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.3.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
github.com/jackc/pgtype v1.11.0 // indirect
github.com/jackc/pgx/v4 v4.16.0 // indirect
github.com/jaytaylor/html2text v0.0.0-20211105163654-bc68cce691ba // indirect
github.com/jackc/pgx/v4 v4.16.1 // indirect
github.com/jaytaylor/html2text v0.0.0-20180606194806-57d518f124b0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/jlaffaye/ftp v0.0.0-20220630165035-11536801d1ff // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/juju/ratelimit v1.0.2-0.20191002062651-f60b32039441 // indirect
github.com/klauspost/compress v1.15.2 // indirect
github.com/klauspost/compress v1.14.4 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/lni/goutils v1.3.1-0.20220404072553-ddb2075d2587 // indirect
github.com/lni/vfs v0.2.1-0.20220408085249-8be85be1c3c1 // indirect
github.com/lni/dragonboat/v3 v3.3.5 // indirect
github.com/lni/goutils v1.3.0 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/matcornic/hermes/v2 v2.1.0 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/mattn/go-sqlite3 v1.14.12 // indirect
github.com/mattn/go-tty v0.0.4 // 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.48 // indirect
github.com/miekg/dns v1.1.26 // indirect
github.com/minio/highwayhash v1.0.2 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/nats-io/jwt/v2 v2.3.0 // indirect
github.com/nats-io/nats-server/v2 v2.8.4 // indirect
github.com/nats-io/nats.go v1.16.0 // indirect
github.com/nats-io/nkeys v0.3.0 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.0 // indirect
github.com/olekukonko/tablewriter v0.0.1 // indirect
github.com/onsi/ginkgo/v2 v2.1.4 // indirect
github.com/onsi/gomega v1.20.0 // indirect
github.com/paulmach/orb v0.7.1 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
github.com/pierrec/lz4/v4 v4.1.15 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/term v1.2.0-beta.2 // indirect
github.com/prometheus/client_golang v1.12.2 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.34.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/rogpeppe/go-internal v1.8.1 // indirect
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/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/spf13/afero v1.8.2 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/cobra v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.12.0 // indirect
github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/subosito/gotenv v1.3.0 // indirect
github.com/ugorji/go/codec v1.2.7 // indirect
github.com/valyala/fastrand v1.1.0 // indirect
github.com/valyala/histogram v1.2.0 // indirect
github.com/vanng822/css v1.0.1 // indirect
github.com/vanng822/go-premailer v1.20.1 // indirect
github.com/valyala/fastrand v1.0.0 // indirect
github.com/valyala/histogram v1.0.1 // indirect
github.com/vanng822/css v0.0.0-20190504095207-a21e860bcd04 // indirect
github.com/vanng822/go-premailer v0.0.0-20191214114701-be27abe028fe // indirect
github.com/vbauerster/mpb/v5 v5.4.0 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/xanzy/go-gitlab v0.69.0 // indirect
github.com/xhit/go-simple-mail v2.2.2+incompatible // indirect
github.com/xujiajun/mmap-go v1.0.1 // indirect
github.com/xujiajun/nutsdb v0.9.0 // indirect
github.com/xujiajun/utils v0.0.0-20190123093513-8bf096c4f53b // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f // indirect
golang.org/x/exp v0.0.0-20220426173459-3bcf042a4bf5 // indirect
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
go.opentelemetry.io/otel v1.7.0 // indirect
go.opentelemetry.io/otel/trace v1.7.0 // indirect
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
golang.org/x/exp v0.0.0-20200513190911-00229845015e // indirect
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
golang.org/x/oauth2 v0.0.0-20220722155238-128564f6959c // indirect
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20220411224347-583f2d630306 // indirect
golang.org/x/tools v0.1.10 // indirect
golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f // indirect
google.golang.org/appengine v1.6.7 // 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
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/driver/clickhouse v0.4.2 // indirect
gorm.io/driver/mysql v1.3.5 // indirect
gorm.io/driver/postgres v1.3.8 // indirect
gorm.io/driver/sqlite v1.3.6 // indirect
gorm.io/driver/sqlserver v1.3.2 // indirect
gorm.io/gorm v1.23.8 // indirect
)

View File

@@ -49,14 +49,13 @@ const (
ErrorLDAPGroupNotFound
)
var isCodeError = false
var isCodeError = errors.ExistInMapMessage(ErrorEmptyParams)
func IsCodeError() bool {
return isCodeError
}
func init() {
isCodeError = errors.ExistInMapMessage(ErrorEmptyParams)
errors.RegisterIdFctMessage(ErrorEmptyParams, getMessage)
}

View File

@@ -170,7 +170,7 @@ func (lc *HelperLDAP) dialTLS() (*ldap.Conn, liberr.Error) {
func (lc *HelperLDAP) dial() (*ldap.Conn, liberr.Error) {
d := net.Dialer{}
c, err := d.DialContext(lc.ctx, "tcp", lc.config.ServerAddr(true))
c, err := d.DialContext(lc.ctx, "tcp", lc.config.ServerAddr(false))
if err != nil {
if c != nil {

View File

@@ -26,12 +26,17 @@
package request
import "bytes"
import (
"bytes"
"encoding/json"
)
type requestError struct {
c int
s string
se bool
b *bytes.Buffer
be bool
e error
}
@@ -50,3 +55,25 @@ func (r *requestError) Body() *bytes.Buffer {
func (r *requestError) Error() error {
return r.e
}
func (r *requestError) IsError() bool {
return r.se || r.be || r.e != nil
}
func (r *requestError) IsStatusError() bool {
return r.se
}
func (r *requestError) IsBodyError() bool {
return r.be
}
func (r *requestError) ParseBody(i interface{}) bool {
if r.b != nil && r.b.Len() > 0 {
if e := json.Unmarshal(r.b.Bytes(), i); e == nil {
return true
}
}
return false
}

View File

@@ -47,6 +47,12 @@ type RequestError interface {
Status() string
Body() *bytes.Buffer
Error() error
IsError() bool
IsStatusError() bool
IsBodyError() bool
ParseBody(i interface{}) bool
}
type Request interface {

View File

@@ -178,8 +178,20 @@ func (r *request) _GetContext() context.Context {
return context.Background()
}
func (r *request) _GetOption() *Options {
if r.o == nil {
return nil
} else if i := r.o.Load(); i == nil {
return nil
} else if o, ok := i.(*Options); !ok {
return nil
} else {
return o
}
}
func (r *request) _GetDefaultTLS() libtls.TLSConfig {
if cfg := r.GetOption(); cfg != nil {
if cfg := r._GetOption(); cfg != nil {
return cfg._GetDefaultTLS()
}
@@ -199,7 +211,7 @@ func (r *request) _GetClient() *http.Client {
}
}
if cfg := r.GetOption(); cfg != nil {
if cfg := r._GetOption(); cfg != nil {
return cfg.GetClientHTTP(h)
}
@@ -252,8 +264,10 @@ func (r *request) _CheckResponse(rsp *http.Response, validStatus ...int) (*bytes
}
if rsp.Body != nil {
if _, e = io.Copy(b, rsp.Body); e != nil {
return b, ErrorResponseLoadBody.ErrorParent(e)
}
}
if !r._IsValidCode(validStatus, rsp.StatusCode) {
return b, ErrorResponseStatus.Error(nil)
@@ -314,20 +328,23 @@ func (r *request) Clone() (Request, error) {
}
func (r *request) New() (Request, error) {
cfg := r.GetOption()
r.s.Lock()
defer r.s.Unlock()
var n *request
var (
n *request
c = r._GetOption()
)
if cfg == nil {
if i, e := New(r.x, r.f, Options{}); e != nil {
if c == nil {
c = &Options{}
}
if i, e := New(r.x, r.f, *c); e != nil {
return nil, e
} else {
n = i.(*request)
}
}
if r.u != nil {
n.u = &url.URL{
@@ -351,15 +368,7 @@ func (r *request) GetOption() *Options {
r.s.Lock()
defer r.s.Unlock()
if r.o == nil {
return nil
} else if i := r.o.Load(); i == nil {
return nil
} else if o, ok := i.(*Options); !ok {
return nil
} else {
return o
}
return r._GetOption()
}
func (r *request) SetOption(opt *Options) error {
@@ -437,7 +446,9 @@ func (r *request) AddPath(raw bool, path ...string) {
}
for i := range path {
if strings.HasPrefix(path[i], "/") {
if raw && strings.HasSuffix(r.u.RawPath, "/") && strings.HasPrefix(path[i], "/") {
path[i] = strings.TrimPrefix(path[i], "/")
} else if !raw && strings.HasSuffix(r.u.Path, "/") && strings.HasPrefix(path[i], "/") {
path[i] = strings.TrimPrefix(path[i], "/")
}
@@ -594,10 +605,7 @@ func (r *request) BodyJson(body interface{}) error {
if p, e := json.Marshal(body); e != nil {
return e
} else {
r.s.Lock()
defer r.s.Unlock()
r.b = bytes.NewBuffer(p)
r._BodyReader(bytes.NewBuffer(p))
}
r.ContentType("application/json")
@@ -605,16 +613,20 @@ func (r *request) BodyJson(body interface{}) error {
}
func (r *request) BodyReader(body io.Reader, contentType string) {
r.s.Lock()
defer r.s.Unlock()
r.b = body
r._BodyReader(body)
if contentType != "" {
r.ContentType(contentType)
}
}
func (r *request) _BodyReader(body io.Reader) {
r.s.Lock()
defer r.s.Unlock()
r.b = body
}
func (r *request) Error() RequestError {
r.s.Lock()
defer r.s.Unlock()
@@ -626,7 +638,7 @@ func (r *request) IsError() bool {
r.s.Lock()
defer r.s.Unlock()
return r.e != nil
return r.e != nil && r.e.IsError()
}
func (r *request) Do() (*http.Response, liberr.Error) {
@@ -644,28 +656,25 @@ func (r *request) Do() (*http.Response, liberr.Error) {
err liberr.Error
)
r.e = nil
req, err = r._MakeRequest(r.u, r.m, r.b, r.h, r.p)
if err != nil {
r.e = &requestError{
c: 0,
s: "",
b: nil,
e: err,
se: false,
b: bytes.NewBuffer(make([]byte, 0)),
be: false,
e: nil,
}
req, err = r._MakeRequest(r.u, r.m, r.b, r.h, r.p)
if err != nil {
r.e.e = err
return nil, err
}
rsp, e = r._GetClient().Do(req)
if e != nil {
r.e = &requestError{
c: 0,
s: "",
b: nil,
e: e,
}
r.e.e = e
return nil, ErrorSendRequest.ErrorParent(e)
}
@@ -681,31 +690,41 @@ func (r *request) DoParse(model interface{}, validStatus ...int) liberr.Error {
rsp *http.Response
)
r.e = &requestError{
c: 0,
s: "",
se: false,
b: bytes.NewBuffer(make([]byte, 0)),
be: false,
e: nil,
}
if rsp, err = r.Do(); err != nil {
return err
} else if rsp == nil {
return ErrorResponseInvalid.Error(nil)
} else {
r.e.c = rsp.StatusCode
r.e.s = rsp.Status
}
if b, err = r._CheckResponse(rsp, validStatus...); e != nil {
r.e = &requestError{
c: rsp.StatusCode,
s: rsp.Status,
b: b,
e: err,
}
b, err = r._CheckResponse(rsp, validStatus...)
r.e.b = b
if err != nil && err.HasCodeError(ErrorResponseStatus) {
r.e.se = true
} else if err != nil {
r.e.e = err
return err
}
if b.Len() > 0 {
if e = json.Unmarshal(b.Bytes(), model); e != nil {
r.e = &requestError{
c: rsp.StatusCode,
s: rsp.Status,
b: b,
e: e,
}
r.e.be = true
r.e.e = e
return ErrorResponseUnmarshall.ErrorParent(e)
}
}
return nil
}

View File

@@ -59,7 +59,7 @@ type ConfigStatus struct {
var _defaultConfig = []byte(`{
"mandatory": false,
"message_ok": "OK",
"message_ko": "OK",
"message_ko": "KO",
"cache_timeout_info": "30s",
"cache_timeout_health": "5s"
}