updated libs

This commit is contained in:
ston1th 2021-10-16 19:13:57 +02:00
commit f305f96195
11 changed files with 79 additions and 265 deletions

View file

@ -141,8 +141,14 @@ func NewClient(options ...ClientOption) *Client {
if client.httpClient == nil {
client.httpClient = &http.Client{Transport: &http.Transport{
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
}).DialContext,
ForceAttemptHTTP2: true,
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
TLSClientConfig: &tls.Config{
InsecureSkipVerify: client.insecure,
},

View file

@ -60,7 +60,10 @@ func NewServer(c *config.Config, log logr.Logger) (*Server, error) {
prefix: c.VIP.Prefix,
store: c.VIP.Store,
}
s.Data.Auth = types.NewAuth(c.APIServer.BasicAuth)
s.Data.AuthDisabled = c.APIServer.DisableAuth
if !s.Data.AuthDisabled {
s.Data.Auth = types.NewAuth(c.APIServer.BasicAuth)
}
if c.APIServer.TLS != nil {
cert, err := tls.LoadX509KeyPair(c.APIServer.TLS.Cert, c.APIServer.TLS.Key)

View file

@ -14,9 +14,12 @@ import (
)
type ContextData struct {
Net netalloc.Allocator
DB *db.DB
Auth *Auth
Net netalloc.Allocator
DB *db.DB
Auth *Auth
AuthDisabled bool
Leader bool
}

View file

@ -16,14 +16,16 @@ var errFollower = errors.New("follower write")
func authHandler(h types.CtxHandler) types.CtxHandler {
return func(ctx *types.Context) {
user, pass, ok := ctx.Request.BasicAuth()
if !ok {
ctx.Err(types.ErrUnauthorized)
return
}
if !ctx.Data.Auth.Login(user, pass, ctx.Path()) {
ctx.Err(types.ErrForbidden)
return
if !ctx.Data.AuthDisabled {
user, pass, ok := ctx.Request.BasicAuth()
if !ok {
ctx.Err(types.ErrUnauthorized)
return
}
if !ctx.Data.Auth.Login(user, pass, ctx.Path()) {
ctx.Err(types.ErrForbidden)
return
}
}
h(ctx)
}