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"
|
"database/sql"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
_ "github.com/denisenkom/go-mssqldb"
|
_ "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"
|
"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/connutil"
|
||||||
"github.com/hashicorp/vault/sdk/database/helper/dbutil"
|
"github.com/hashicorp/vault/sdk/database/helper/dbutil"
|
||||||
"github.com/hashicorp/vault/sdk/helper/dbtxn"
|
"github.com/hashicorp/vault/sdk/helper/dbtxn"
|
||||||
|
@ -98,20 +99,14 @@ 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)
|
return dbplugin.InitializeResponse{}, fmt.Errorf("invalid username template - did you reference a field that isn't available? : %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
containedDB := false
|
if v, ok := req.Config["contained_db"]; ok {
|
||||||
containedDBRaw, err := strutil.GetString(req.Config, "contained_db")
|
containedDB, err := parseutil.ParseBool(v)
|
||||||
if err != nil {
|
|
||||||
return dbplugin.InitializeResponse{}, fmt.Errorf("failed to retrieve contained_db: %w", err)
|
|
||||||
}
|
|
||||||
if containedDBRaw != "" {
|
|
||||||
containedDB, err = strconv.ParseBool(containedDBRaw)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return dbplugin.InitializeResponse{}, fmt.Errorf("parsing error: incorrect boolean operator provided for contained_db: %w", err)
|
return dbplugin.InitializeResponse{}, fmt.Errorf(`invalid value for "contained_db": %w`, err)
|
||||||
}
|
}
|
||||||
|
m.containedDB = containedDB
|
||||||
}
|
}
|
||||||
|
|
||||||
m.containedDB = containedDB
|
|
||||||
|
|
||||||
resp := dbplugin.InitializeResponse{
|
resp := dbplugin.InitializeResponse{
|
||||||
Config: newConf,
|
Config: newConf,
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
mssqlhelper "github.com/hashicorp/vault/helper/testhelpers/mssql"
|
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"
|
dbtesting "github.com/hashicorp/vault/sdk/database/dbplugin/v5/testing"
|
||||||
"github.com/hashicorp/vault/sdk/helper/dbtxn"
|
"github.com/hashicorp/vault/sdk/helper/dbtxn"
|
||||||
)
|
)
|
||||||
|
@ -43,6 +43,15 @@ func TestInitialize(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"contained_db set": {
|
"contained_db set": {
|
||||||
|
dbplugin.InitializeRequest{
|
||||||
|
Config: map[string]interface{}{
|
||||||
|
"connection_url": connURL,
|
||||||
|
"contained_db": true,
|
||||||
|
},
|
||||||
|
VerifyConnection: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"contained_db set string": {
|
||||||
dbplugin.InitializeRequest{
|
dbplugin.InitializeRequest{
|
||||||
Config: map[string]interface{}{
|
Config: map[string]interface{}{
|
||||||
"connection_url": connURL,
|
"connection_url": connURL,
|
||||||
|
|
Loading…
Reference in New Issue