mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 11:08:10 +00:00
Have SQL backends Ping() before access.
If unsuccessful, reestablish connections as needed.
This commit is contained in:
@@ -51,7 +51,12 @@ func (b *backend) DB(s logical.Storage) (*sql.DB, error) {
|
|||||||
|
|
||||||
// If we already have a DB, we got it!
|
// If we already have a DB, we got it!
|
||||||
if b.db != nil {
|
if b.db != nil {
|
||||||
return b.db, nil
|
if err := b.db.Ping(); err == nil {
|
||||||
|
return b.db, nil
|
||||||
|
}
|
||||||
|
// If the ping was unsuccessful, close it and ignore errors as we'll be
|
||||||
|
// reestablishing anyways
|
||||||
|
b.db.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, attempt to make connection
|
// Otherwise, attempt to make connection
|
||||||
|
|||||||
@@ -50,7 +50,12 @@ func (b *backend) DB(s logical.Storage) (*sql.DB, error) {
|
|||||||
|
|
||||||
// If we already have a DB, we got it!
|
// If we already have a DB, we got it!
|
||||||
if b.db != nil {
|
if b.db != nil {
|
||||||
return b.db, nil
|
if err := b.db.Ping(); err == nil {
|
||||||
|
return b.db, nil
|
||||||
|
}
|
||||||
|
// If the ping was unsuccessful, close it and ignore errors as we'll be
|
||||||
|
// reestablishing anyways
|
||||||
|
b.db.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, attempt to make connection
|
// Otherwise, attempt to make connection
|
||||||
|
|||||||
@@ -57,7 +57,12 @@ func (b *backend) DB(s logical.Storage) (*sql.DB, error) {
|
|||||||
|
|
||||||
// If we already have a DB, we got it!
|
// If we already have a DB, we got it!
|
||||||
if b.db != nil {
|
if b.db != nil {
|
||||||
return b.db, nil
|
if err := b.db.Ping(); err == nil {
|
||||||
|
return b.db, nil
|
||||||
|
}
|
||||||
|
// If the ping was unsuccessful, close it and ignore errors as we'll be
|
||||||
|
// reestablishing anyways
|
||||||
|
b.db.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, attempt to make connection
|
// Otherwise, attempt to make connection
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ func TestBackend_basic(t *testing.T) {
|
|||||||
Steps: []logicaltest.TestStep{
|
Steps: []logicaltest.TestStep{
|
||||||
testAccStepConfig(t, connData, false),
|
testAccStepConfig(t, connData, false),
|
||||||
testAccStepRole(t),
|
testAccStepRole(t),
|
||||||
testAccStepReadCreds(t, b, "web", connURL),
|
testAccStepReadCreds(t, b, config.StorageView, "web", connURL),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -211,7 +211,7 @@ func testAccStepDeleteRole(t *testing.T, n string) logicaltest.TestStep {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccStepReadCreds(t *testing.T, b logical.Backend, name string, connURL string) logicaltest.TestStep {
|
func testAccStepReadCreds(t *testing.T, b logical.Backend, s logical.Storage, name string, connURL string) logicaltest.TestStep {
|
||||||
return logicaltest.TestStep{
|
return logicaltest.TestStep{
|
||||||
Operation: logical.ReadOperation,
|
Operation: logical.ReadOperation,
|
||||||
Path: "creds/" + name,
|
Path: "creds/" + name,
|
||||||
@@ -266,6 +266,7 @@ func testAccStepReadCreds(t *testing.T, b logical.Backend, name string, connURL
|
|||||||
|
|
||||||
resp, err = b.HandleRequest(&logical.Request{
|
resp, err = b.HandleRequest(&logical.Request{
|
||||||
Operation: logical.RevokeOperation,
|
Operation: logical.RevokeOperation,
|
||||||
|
Storage: s,
|
||||||
Secret: &logical.Secret{
|
Secret: &logical.Secret{
|
||||||
InternalData: map[string]interface{}{
|
InternalData: map[string]interface{}{
|
||||||
"secret_type": "creds",
|
"secret_type": "creds",
|
||||||
|
|||||||
Reference in New Issue
Block a user