mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 19:17:58 +00:00
Address review feedback
This commit is contained in:
@@ -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) {
|
func (b *backend) pathConnectionRead(req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
|
||||||
entry, err := req.Storage.Get("config/connection")
|
entry, err := req.Storage.Get("config/connection")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -68,7 +68,12 @@ func (b *backend) DB(s logical.Storage) (*sql.DB, error) {
|
|||||||
return nil, err
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ func TestBackend_config_connection(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
configData := map[string]interface{}{
|
configData := map[string]interface{}{
|
||||||
|
"value": "",
|
||||||
"connection_url": "sample_connection_url",
|
"connection_url": "sample_connection_url",
|
||||||
"max_open_connections": 7,
|
"max_open_connections": 7,
|
||||||
"verify_connection": false,
|
"verify_connection": false,
|
||||||
|
|||||||
@@ -18,6 +18,11 @@ func pathConfigConnection(b *backend) *framework.Path {
|
|||||||
Type: framework.TypeString,
|
Type: framework.TypeString,
|
||||||
Description: "DB connection string",
|
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{
|
"max_open_connections": &framework.FieldSchema{
|
||||||
Type: framework.TypeInt,
|
Type: framework.TypeInt,
|
||||||
Description: "Maximum number of open connections to database",
|
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(
|
func (b *backend) pathConnectionWrite(
|
||||||
req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
|
req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
|
||||||
|
connValue := data.Get("value").(string)
|
||||||
connURL := data.Get("connection_url").(string)
|
connURL := data.Get("connection_url").(string)
|
||||||
if connURL == "" {
|
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)
|
maxOpenConns := data.Get("max_open_connections").(int)
|
||||||
@@ -106,7 +116,9 @@ func (b *backend) pathConnectionWrite(
|
|||||||
}
|
}
|
||||||
|
|
||||||
type connectionConfig struct {
|
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"`
|
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"`
|
VerifyConnection bool `json:"verify_connection" structs:"verify_connection" mapstructure:"verify_connection"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,6 +70,9 @@ func (b *backend) DB(s logical.Storage) (*sql.DB, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
conn := connConfig.ConnectionURL
|
conn := connConfig.ConnectionURL
|
||||||
|
if len(conn) == 0 {
|
||||||
|
conn = connConfig.ConnectionString
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure timezone is set to UTC for all the conenctions
|
// Ensure timezone is set to UTC for all the conenctions
|
||||||
if strings.HasPrefix(conn, "postgres://") || strings.HasPrefix(conn, "postgresql://") {
|
if strings.HasPrefix(conn, "postgres://") || strings.HasPrefix(conn, "postgresql://") {
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ func TestBackend_config_connection(t *testing.T) {
|
|||||||
|
|
||||||
configData := map[string]interface{}{
|
configData := map[string]interface{}{
|
||||||
"connection_url": "sample_connection_url",
|
"connection_url": "sample_connection_url",
|
||||||
|
"value": "",
|
||||||
"max_open_connections": 9,
|
"max_open_connections": 9,
|
||||||
"max_idle_connections": 7,
|
"max_idle_connections": 7,
|
||||||
"verify_connection": false,
|
"verify_connection": false,
|
||||||
|
|||||||
@@ -118,6 +118,7 @@ func (b *backend) pathConnectionWrite(
|
|||||||
|
|
||||||
// Store it
|
// Store it
|
||||||
entry, err := logical.StorageEntryJSON("config/connection", connectionConfig{
|
entry, err := logical.StorageEntryJSON("config/connection", connectionConfig{
|
||||||
|
ConnectionString: connValue,
|
||||||
ConnectionURL: connURL,
|
ConnectionURL: connURL,
|
||||||
MaxOpenConnections: maxOpenConns,
|
MaxOpenConnections: maxOpenConns,
|
||||||
MaxIdleConnections: maxIdleConns,
|
MaxIdleConnections: maxIdleConns,
|
||||||
@@ -137,7 +138,9 @@ func (b *backend) pathConnectionWrite(
|
|||||||
}
|
}
|
||||||
|
|
||||||
type connectionConfig struct {
|
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"`
|
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"`
|
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"`
|
VerifyConnection bool `json:"verify_connection" structs:"verify_connection" mapstructure:"verify_connection"`
|
||||||
|
|||||||
Reference in New Issue
Block a user