On change of configuration rotate the database type

This commit is contained in:
Brian Kassouf 2017-04-03 18:30:38 -07:00
parent d7dd0ab35c
commit b506bd7790

View file

@ -243,29 +243,23 @@ func (b *databaseBackend) connectionWriteHandler(factory dbs.Factory) framework.
} }
if verifyConnection { if verifyConnection {
return logical.ErrorResponse(err.Error()), nil return logical.ErrorResponse("Could not verify connection"), nil
} }
} }
if _, ok := b.connections[name]; ok { if _, ok := b.connections[name]; ok {
newType := db.Type() // Close and remove the old connection
err := b.connections[name].Close()
// Don't update connection until the reset api is hit, close for
// now.
err = db.Close()
if err != nil { if err != nil {
return nil, err return nil, err
} }
// Don't allow the connection type to change delete(b.connections, name)
if b.connections[name].Type() != newType {
return logical.ErrorResponse("Can not change type of existing connection."), nil
}
} else {
// Save the new connection
b.connections[name] = db
} }
// Save the new connection
b.connections[name] = db
// Store it // Store it
entry, err := logical.StorageEntryJSON(fmt.Sprintf("dbs/%s", name), config) entry, err := logical.StorageEntryJSON(fmt.Sprintf("dbs/%s", name), config)
if err != nil { if err != nil {