Address review feedback

This commit is contained in:
vishalnayak 2016-06-17 10:11:39 -04:00
parent 1776ff449f
commit cf15354e44
7 changed files with 30 additions and 5 deletions

View file

@ -38,7 +38,7 @@ func pathConfigConnection(b *backend) *framework.Path {
}
}
// pathConnectionWrite reads out the connection configuration
// pathConnectionRead reads out the connection configuration
func (b *backend) pathConnectionRead(req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
entry, err := req.Storage.Get("config/connection")
if err != nil {

View file

@ -68,7 +68,12 @@ func (b *backend) DB(s logical.Storage) (*sql.DB, error) {
return nil, err
}
b.db, err = sql.Open("mysql", connConfig.ConnectionURL)
conn := connConfig.ConnectionURL
if len(conn) == 0 {
conn = connConfig.ConnectionString
}
b.db, err = sql.Open("mysql", conn)
if err != nil {
return nil, err
}

View file

@ -23,6 +23,7 @@ func TestBackend_config_connection(t *testing.T) {
}
configData := map[string]interface{}{
"value": "",
"connection_url": "sample_connection_url",
"max_open_connections": 7,
"verify_connection": false,

View file

@ -18,6 +18,11 @@ func pathConfigConnection(b *backend) *framework.Path {
Type: framework.TypeString,
Description: "DB connection string",
},
"value": &framework.FieldSchema{
Type: framework.TypeString,
Description: `DB connection string. Use 'connection_url' instead.
This name is deprecated.`,
},
"max_open_connections": &framework.FieldSchema{
Type: framework.TypeInt,
Description: "Maximum number of open connections to database",
@ -60,9 +65,14 @@ func (b *backend) pathConnectionRead(req *logical.Request, data *framework.Field
func (b *backend) pathConnectionWrite(
req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
connValue := data.Get("value").(string)
connURL := data.Get("connection_url").(string)
if connURL == "" {
return logical.ErrorResponse("the connection_url parameter must be supplied"), nil
if connValue == "" {
return logical.ErrorResponse("the connection_url parameter must be supplied"), nil
} else {
connURL = connValue
}
}
maxOpenConns := data.Get("max_open_connections").(int)
@ -106,7 +116,9 @@ func (b *backend) pathConnectionWrite(
}
type connectionConfig struct {
ConnectionURL string `json:"connection_url" structs:"connection_url" mapstructure:"connection_url"`
ConnectionURL string `json:"connection_url" structs:"connection_url" mapstructure:"connection_url"`
// Deprecate "value" in coming releases
ConnectionString string `json:"value" structs:"value" mapstructure:"value"`
MaxOpenConnections int `json:"max_open_connections" structs:"max_open_connections" mapstructure:"max_open_connections"`
VerifyConnection bool `json:"verify_connection" structs:"verify_connection" mapstructure:"verify_connection"`
}

View file

@ -70,6 +70,9 @@ func (b *backend) DB(s logical.Storage) (*sql.DB, error) {
}
conn := connConfig.ConnectionURL
if len(conn) == 0 {
conn = connConfig.ConnectionString
}
// Ensure timezone is set to UTC for all the conenctions
if strings.HasPrefix(conn, "postgres://") || strings.HasPrefix(conn, "postgresql://") {

View file

@ -26,6 +26,7 @@ func TestBackend_config_connection(t *testing.T) {
configData := map[string]interface{}{
"connection_url": "sample_connection_url",
"value": "",
"max_open_connections": 9,
"max_idle_connections": 7,
"verify_connection": false,

View file

@ -118,6 +118,7 @@ func (b *backend) pathConnectionWrite(
// Store it
entry, err := logical.StorageEntryJSON("config/connection", connectionConfig{
ConnectionString: connValue,
ConnectionURL: connURL,
MaxOpenConnections: maxOpenConns,
MaxIdleConnections: maxIdleConns,
@ -137,7 +138,9 @@ func (b *backend) pathConnectionWrite(
}
type connectionConfig struct {
ConnectionURL string `json:"connection_url" structs:"connection_url" mapstructure:"connection_url"`
ConnectionURL string `json:"connection_url" structs:"connection_url" mapstructure:"connection_url"`
// Deprecate "value" in coming releases
ConnectionString string `json:"value" structs:"value" mapstructure:"value"`
MaxOpenConnections int `json:"max_open_connections" structs:"max_open_connections" mapstructure:"max_open_connections"`
MaxIdleConnections int `json:"max_idle_connections" structs:"max_idle_connections" mapstructure:"max_idle_connections"`
VerifyConnection bool `json:"verify_connection" structs:"verify_connection" mapstructure:"verify_connection"`