Address review feedback.
Switch ConnectTimeout to framework.TypeDurationSecond with a default of 5. Remove own parsing code.
This commit is contained in:
parent
3859f7938a
commit
ab63c938c4
|
@ -55,7 +55,7 @@ type sessionConfig struct {
|
|||
PrivateKey string `json:"private_key" structs:"private_key"`
|
||||
IssuingCA string `json:"issuing_ca" structs:"issuing_ca"`
|
||||
ProtocolVersion int `json:"protocol_version" structs:"protocol_version"`
|
||||
ConnectTimeout string `json:"connect_timeout" structs:"connect_timeout"`
|
||||
ConnectTimeout int `json:"connect_timeout" structs:"connect_timeout"`
|
||||
}
|
||||
|
||||
// DB returns the database connection.
|
||||
|
@ -82,7 +82,7 @@ func (b *backend) DB(s logical.Storage) (*gocql.Session, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
return createSession(config, s, b.Logger())
|
||||
return createSession(config, s)
|
||||
}
|
||||
|
||||
// ResetDB forces a connection next time DB() is called.
|
||||
|
|
|
@ -62,8 +62,9 @@ take precedence.`,
|
|||
},
|
||||
|
||||
"connect_timeout": &framework.FieldSchema{
|
||||
Type: framework.TypeString,
|
||||
Description: `The connection timeout to use. Defaults to 5s.`,
|
||||
Type: framework.TypeDurationSecond,
|
||||
Default: 5,
|
||||
Description: `The connection timeout to use. Defaults to 5.`,
|
||||
},
|
||||
},
|
||||
|
||||
|
@ -124,7 +125,7 @@ func (b *backend) pathConnectionWrite(
|
|||
TLS: data.Get("tls").(bool),
|
||||
InsecureTLS: data.Get("insecure_tls").(bool),
|
||||
ProtocolVersion: data.Get("protocol_version").(int),
|
||||
ConnectTimeout: data.Get("connect_timeout").(string),
|
||||
ConnectTimeout: data.Get("connect_timeout").(int),
|
||||
}
|
||||
|
||||
if config.InsecureTLS {
|
||||
|
@ -168,7 +169,7 @@ func (b *backend) pathConnectionWrite(
|
|||
config.TLS = true
|
||||
}
|
||||
|
||||
session, err := createSession(config, req.Storage, b.Logger())
|
||||
session, err := createSession(config, req.Storage)
|
||||
if err != nil {
|
||||
return logical.ErrorResponse(err.Error()), nil
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package cassandra
|
|||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -34,7 +33,7 @@ func substQuery(tpl string, data map[string]string) string {
|
|||
return tpl
|
||||
}
|
||||
|
||||
func createSession(cfg *sessionConfig, s logical.Storage, logger *log.Logger) (*gocql.Session, error) {
|
||||
func createSession(cfg *sessionConfig, s logical.Storage) (*gocql.Session, error) {
|
||||
clusterConfig := gocql.NewCluster(strings.Split(cfg.Hosts, ",")...)
|
||||
clusterConfig.Authenticator = gocql.PasswordAuthenticator{
|
||||
Username: cfg.Username,
|
||||
|
@ -46,21 +45,7 @@ func createSession(cfg *sessionConfig, s logical.Storage, logger *log.Logger) (*
|
|||
clusterConfig.ProtoVersion = 2
|
||||
}
|
||||
|
||||
if len(cfg.ConnectTimeout) != 0 {
|
||||
d, err := time.ParseDuration(cfg.ConnectTimeout)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if d < 1 {
|
||||
return nil, fmt.Errorf("Cassandra connect_timeout must be greater than 0")
|
||||
}
|
||||
|
||||
clusterConfig.Timeout = d
|
||||
logger.Printf("[DEBUG]: cassandra: config connect_timeout set to %v", d)
|
||||
} else {
|
||||
clusterConfig.Timeout = 5 * time.Second
|
||||
}
|
||||
clusterConfig.Timeout = time.Duration(cfg.ConnectTimeout) * time.Second
|
||||
|
||||
if cfg.TLS {
|
||||
tlsConfig := &tls.Config{
|
||||
|
|
|
@ -185,7 +185,7 @@ subpath for interactive help output.
|
|||
<li>
|
||||
<span class="param">connect_timeout</span>
|
||||
<span class="param-flags">optional</span>
|
||||
The connection timeout to use. Defaults to 5s.
|
||||
The connection timeout to use. Defaults to 5 seconds.
|
||||
</li>
|
||||
</ul>
|
||||
</dd>
|
||||
|
|
Loading…
Reference in New Issue