Update mssql's contained_db field to accept a boolean (#13469)
Previously the `contained_db` parameter would only accept a string value despite the fact that field type is documented as a boolean.
This commit is contained in:
parent
b2c473edbd
commit
9253abb2e1
|
@ -0,0 +1,3 @@
|
|||
```release-note:bug
|
||||
secrets/database/mssql: Accept a boolean for `contained_db`, rather than just a string.
|
||||
```
|
|
@ -5,13 +5,14 @@ import (
|
|||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
_ "github.com/denisenkom/go-mssqldb"
|
||||
multierror "github.com/hashicorp/go-multierror"
|
||||
"github.com/hashicorp/go-multierror"
|
||||
"github.com/hashicorp/go-secure-stdlib/parseutil"
|
||||
"github.com/hashicorp/go-secure-stdlib/strutil"
|
||||
dbplugin "github.com/hashicorp/vault/sdk/database/dbplugin/v5"
|
||||
|
||||
"github.com/hashicorp/vault/sdk/database/dbplugin/v5"
|
||||
"github.com/hashicorp/vault/sdk/database/helper/connutil"
|
||||
"github.com/hashicorp/vault/sdk/database/helper/dbutil"
|
||||
"github.com/hashicorp/vault/sdk/helper/dbtxn"
|
||||
|
@ -98,19 +99,13 @@ func (m *MSSQL) Initialize(ctx context.Context, req dbplugin.InitializeRequest)
|
|||
return dbplugin.InitializeResponse{}, fmt.Errorf("invalid username template - did you reference a field that isn't available? : %w", err)
|
||||
}
|
||||
|
||||
containedDB := false
|
||||
containedDBRaw, err := strutil.GetString(req.Config, "contained_db")
|
||||
if v, ok := req.Config["contained_db"]; ok {
|
||||
containedDB, err := parseutil.ParseBool(v)
|
||||
if err != nil {
|
||||
return dbplugin.InitializeResponse{}, fmt.Errorf("failed to retrieve contained_db: %w", err)
|
||||
return dbplugin.InitializeResponse{}, fmt.Errorf(`invalid value for "contained_db": %w`, err)
|
||||
}
|
||||
if containedDBRaw != "" {
|
||||
containedDB, err = strconv.ParseBool(containedDBRaw)
|
||||
if err != nil {
|
||||
return dbplugin.InitializeResponse{}, fmt.Errorf("parsing error: incorrect boolean operator provided for contained_db: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
m.containedDB = containedDB
|
||||
}
|
||||
|
||||
resp := dbplugin.InitializeResponse{
|
||||
Config: newConf,
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
"time"
|
||||
|
||||
mssqlhelper "github.com/hashicorp/vault/helper/testhelpers/mssql"
|
||||
dbplugin "github.com/hashicorp/vault/sdk/database/dbplugin/v5"
|
||||
"github.com/hashicorp/vault/sdk/database/dbplugin/v5"
|
||||
dbtesting "github.com/hashicorp/vault/sdk/database/dbplugin/v5/testing"
|
||||
"github.com/hashicorp/vault/sdk/helper/dbtxn"
|
||||
)
|
||||
|
@ -43,6 +43,15 @@ func TestInitialize(t *testing.T) {
|
|||
},
|
||||
},
|
||||
"contained_db set": {
|
||||
dbplugin.InitializeRequest{
|
||||
Config: map[string]interface{}{
|
||||
"connection_url": connURL,
|
||||
"contained_db": true,
|
||||
},
|
||||
VerifyConnection: true,
|
||||
},
|
||||
},
|
||||
"contained_db set string": {
|
||||
dbplugin.InitializeRequest{
|
||||
Config: map[string]interface{}{
|
||||
"connection_url": connURL,
|
||||
|
|
Loading…
Reference in New Issue