rebase: update github.com/hashicorp/vault/sdk to latest

The github.com/hashicorp/vault/sdk was listed in the replace section,
most likely because using a newer version failed. By adding a missing
tagged version to the `exclude` section in go.mod, updating the package
works fine.

Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Niels de Vos
2021-10-19 17:00:15 +02:00
committed by mergify[bot]
parent 6d3e25f069
commit 9bd9f5e91d
6 changed files with 141 additions and 11 deletions

View File

@ -1,9 +1,9 @@
package consts
const (
//N.B. This needs to be excluded from replication despite the name; it's
//merely saying that this is cluster information for the replicated
//cluster.
// N.B. This needs to be excluded from replication despite the name; it's
// merely saying that this is cluster information for the replicated
// cluster.
CoreReplicatedClusterPrefix = "core/cluster/replicated/"
CoreReplicatedClusterPrefixDR = "core/cluster/replicated-dr/"
@ -45,7 +45,6 @@ const (
// We verify no change to the above values are made
func init() {
if OldReplicationBootstrapping != 3 {
panic("Replication Constants have changed")
}

View File

@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"regexp"
"strconv"
"strings"
"time"
@ -14,6 +15,84 @@ import (
"github.com/mitchellh/mapstructure"
)
var validCapacityString = regexp.MustCompile("^[\t ]*([0-9]+)[\t ]?([kmgtKMGT][iI]?[bB])?[\t ]*$")
// ParseCapacityString parses a capacity string and returns the number of bytes it represents.
// Capacity strings are things like 5gib or 10MB. Supported prefixes are kb, kib, mb, mib, gb,
// gib, tb, tib, which are not case sensitive. If no prefix is present, the number is assumed
// to be in bytes already.
func ParseCapacityString(in interface{}) (uint64, error) {
var cap uint64
jsonIn, ok := in.(json.Number)
if ok {
in = jsonIn.String()
}
switch inp := in.(type) {
case nil:
// return default of zero
case string:
if inp == "" {
return cap, nil
}
matches := validCapacityString.FindStringSubmatch(inp)
// no sub-groups means we couldn't parse it
if len(matches) <= 1 {
return cap, errors.New("could not parse capacity from input")
}
var multiplier uint64 = 1
switch strings.ToLower(matches[2]) {
case "kb":
multiplier = 1000
case "kib":
multiplier = 1024
case "mb":
multiplier = 1000 * 1000
case "mib":
multiplier = 1024 * 1024
case "gb":
multiplier = 1000 * 1000 * 1000
case "gib":
multiplier = 1024 * 1024 * 1024
case "tb":
multiplier = 1000 * 1000 * 1000 * 1000
case "tib":
multiplier = 1024 * 1024 * 1024 * 1024
}
size, err := strconv.ParseUint(matches[1], 10, 64)
if err != nil {
return cap, err
}
cap = size * multiplier
case int:
cap = uint64(inp)
case int32:
cap = uint64(inp)
case int64:
cap = uint64(inp)
case uint:
cap = uint64(inp)
case uint32:
cap = uint64(inp)
case uint64:
cap = uint64(inp)
case float32:
cap = uint64(inp)
case float64:
cap = uint64(inp)
default:
return cap, errors.New("could not parse capacity from input")
}
return cap, nil
}
func ParseDurationSecond(in interface{}) (time.Duration, error) {
var dur time.Duration
jsonIn, ok := in.(json.Number)

View File

@ -32,6 +32,16 @@ func StrListContains(haystack []string, needle string) bool {
return false
}
// StrListContainsCaseInsensitive looks for a string in a list of strings.
func StrListContainsCaseInsensitive(haystack []string, needle string) bool {
for _, item := range haystack {
if strings.EqualFold(item, needle) {
return true
}
}
return false
}
// StrListSubset checks if a given list is a subset
// of another set
func StrListSubset(super, sub []string) bool {
@ -445,3 +455,26 @@ func Difference(a, b []string, lowercase bool) []string {
sort.Strings(items)
return items
}
// GetString attempts to retrieve a value from the provided map and assert that it is a string. If the key does not
// exist in the map, this will return an empty string. If the key exists, but the value is not a string type, this will
// return an error. If no map or key is provied, this will return an error
func GetString(m map[string]interface{}, key string) (string, error) {
if m == nil {
return "", fmt.Errorf("missing map")
}
if key == "" {
return "", fmt.Errorf("missing key")
}
rawVal, ok := m[key]
if !ok {
return "", nil
}
str, ok := rawVal.(string)
if !ok {
return "", fmt.Errorf("invalid value at %s: is a %T", key, rawVal)
}
return str, nil
}