Bump api/sdk

This commit is contained in:
Jeff Mitchell 2019-07-02 09:53:02 -04:00
parent ece9a4a6f0
commit 7cb73f5457
4 changed files with 133 additions and 5 deletions

4
go.mod
View file

@ -82,8 +82,8 @@ require (
github.com/hashicorp/vault-plugin-secrets-gcp v0.5.3-0.20190620162751-272efd334652
github.com/hashicorp/vault-plugin-secrets-gcpkms v0.5.2-0.20190516000311-88f9a4f11829
github.com/hashicorp/vault-plugin-secrets-kv v0.5.2-0.20190626201950-a6e92ff82578
github.com/hashicorp/vault/api v1.0.3-0.20190701222923-add28c66499c
github.com/hashicorp/vault/sdk v0.1.12-0.20190701222923-add28c66499c
github.com/hashicorp/vault/api v1.0.3-0.20190702135236-ece9a4a6f0ef
github.com/hashicorp/vault/sdk v0.1.12-0.20190702135205-50704e612cb9
github.com/influxdata/influxdb v0.0.0-20190411212539-d24b7ba8c4c4
github.com/jackc/fake v0.0.0-20150926172116-812a484cc733 // indirect
github.com/jackc/pgx v3.3.0+incompatible // indirect

View file

@ -11,7 +11,7 @@ require (
github.com/hashicorp/go-retryablehttp v0.5.4
github.com/hashicorp/go-rootcerts v1.0.1
github.com/hashicorp/hcl v1.0.0
github.com/hashicorp/vault/sdk v0.1.12-0.20190701221336-a2924e1e8326
github.com/hashicorp/vault/sdk v0.1.12-0.20190702135205-50704e612cb9
github.com/mitchellh/mapstructure v1.1.2
golang.org/x/net v0.0.0-20190620200207-3b0461eec859
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4

View file

@ -8,6 +8,7 @@ import (
sockaddr "github.com/hashicorp/go-sockaddr"
"github.com/hashicorp/vault/sdk/framework"
"github.com/hashicorp/vault/sdk/helper/parseutil"
"github.com/hashicorp/vault/sdk/helper/policyutil"
"github.com/hashicorp/vault/sdk/helper/strutil"
"github.com/hashicorp/vault/sdk/logical"
)
@ -266,6 +267,133 @@ func DeprecationText(param string) string {
return fmt.Sprintf("Use %q instead. If this and %q are both specified, only %q will be used.", param, param, param)
}
func upgradeDurationValue(d *framework.FieldData, oldKey, newKey string, oldVal, newVal *time.Duration) error {
_, ok := d.GetOk(newKey)
if !ok {
raw, ok := d.GetOk(oldKey)
if ok {
*oldVal = time.Duration(raw.(int)) * time.Second
*newVal = *oldVal
}
} else {
_, ok = d.GetOk(oldKey)
if ok {
*oldVal = *newVal
} else {
*oldVal = 0
}
}
return nil
}
func upgradeIntValue(d *framework.FieldData, oldKey, newKey string, oldVal, newVal *int) error {
_, ok := d.GetOk(newKey)
if !ok {
raw, ok := d.GetOk(oldKey)
if ok {
*oldVal = raw.(int)
*newVal = *oldVal
}
} else {
_, ok = d.GetOk(oldKey)
if ok {
*oldVal = *newVal
} else {
*oldVal = 0
}
}
return nil
}
func upgradeStringSliceValue(d *framework.FieldData, oldKey, newKey string, oldVal, newVal *[]string) error {
_, ok := d.GetOk(newKey)
if !ok {
raw, ok := d.GetOk(oldKey)
if ok {
// Special case: if we're looking at "token_policies" parse the policies
if newKey == "token_policies" {
*oldVal = policyutil.ParsePolicies(raw)
} else {
*oldVal = raw.([]string)
}
*newVal = *oldVal
}
} else {
_, ok = d.GetOk(oldKey)
if ok {
*oldVal = *newVal
} else {
*oldVal = nil
}
}
return nil
}
func upgradeSockAddrSliceValue(d *framework.FieldData, oldKey, newKey string, oldVal, newVal *[]*sockaddr.SockAddrMarshaler) error {
_, ok := d.GetOk(newKey)
if !ok {
raw, ok := d.GetOk(oldKey)
if ok {
boundCIDRs, err := parseutil.ParseAddrs(raw)
if err != nil {
return err
}
*oldVal = boundCIDRs
*newVal = *oldVal
}
} else {
_, ok = d.GetOk(oldKey)
if ok {
*oldVal = *newVal
} else {
*oldVal = nil
}
}
return nil
}
// UpgradeValue takes in old/new data keys and old/new values and calls out to
// a helper function to perform upgrades in a standardized way. It reqiures
// pointers in all cases so that we can set directly into the target struct.
func UpgradeValue(d *framework.FieldData, oldKey, newKey string, oldVal, newVal interface{}) error {
switch typedOldVal := oldVal.(type) {
case *time.Duration:
typedNewVal, ok := newVal.(*time.Duration)
if !ok {
return errors.New("mismatch in value types in tokenutil.UpgradeValue")
}
return upgradeDurationValue(d, oldKey, newKey, typedOldVal, typedNewVal)
case *int:
typedNewVal, ok := newVal.(*int)
if !ok {
return errors.New("mismatch in value types in tokenutil.UpgradeValue")
}
return upgradeIntValue(d, oldKey, newKey, typedOldVal, typedNewVal)
case *[]string:
typedNewVal, ok := newVal.(*[]string)
if !ok {
return errors.New("mismatch in value types in tokenutil.UpgradeValue")
}
return upgradeStringSliceValue(d, oldKey, newKey, typedOldVal, typedNewVal)
case *[]*sockaddr.SockAddrMarshaler:
typedNewVal, ok := newVal.(*[]*sockaddr.SockAddrMarshaler)
if !ok {
return errors.New("mismatch in value types in tokenutil.UpgradeValue")
}
return upgradeSockAddrSliceValue(d, oldKey, newKey, typedOldVal, typedNewVal)
default:
return errors.New("unhandled type in tokenutil.UpgradeValue")
}
}
const (
tokenPeriodHelp = `If set, tokens created via this role
will have no max lifetime; instead, their

4
vendor/modules.txt vendored
View file

@ -362,9 +362,9 @@ github.com/hashicorp/vault-plugin-secrets-gcp/plugin/util
github.com/hashicorp/vault-plugin-secrets-gcpkms
# github.com/hashicorp/vault-plugin-secrets-kv v0.5.2-0.20190626201950-a6e92ff82578
github.com/hashicorp/vault-plugin-secrets-kv
# github.com/hashicorp/vault/api v1.0.3-0.20190701222923-add28c66499c => ./api
# github.com/hashicorp/vault/api v1.0.3-0.20190702135236-ece9a4a6f0ef => ./api
github.com/hashicorp/vault/api
# github.com/hashicorp/vault/sdk v0.1.12-0.20190701222923-add28c66499c => ./sdk
# github.com/hashicorp/vault/sdk v0.1.12-0.20190702135205-50704e612cb9 => ./sdk
github.com/hashicorp/vault/sdk/helper/salt
github.com/hashicorp/vault/sdk/helper/strutil
github.com/hashicorp/vault/sdk/helper/wrapping