mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-14 10:53:34 +00:00
rebase: bump github.com/hashicorp/vault/api from 1.5.0 to 1.6.0
Bumps [github.com/hashicorp/vault/api](https://github.com/hashicorp/vault) from 1.5.0 to 1.6.0. - [Release notes](https://github.com/hashicorp/vault/releases) - [Changelog](https://github.com/hashicorp/vault/blob/main/CHANGELOG.md) - [Commits](https://github.com/hashicorp/vault/compare/v1.5.0...v1.6.0) --- updated-dependencies: - dependency-name: github.com/hashicorp/vault/api dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
committed by
mergify[bot]
parent
01923ab166
commit
3c0e1b4970
220
vendor/github.com/hashicorp/go-secure-stdlib/parseutil/parseutil.go
generated
vendored
220
vendor/github.com/hashicorp/go-secure-stdlib/parseutil/parseutil.go
generated
vendored
@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -92,6 +93,9 @@ func ParseCapacityString(in interface{}) (uint64, error) {
|
||||
return cap, nil
|
||||
}
|
||||
|
||||
// Parse a duration from an arbitrary value (a string or numeric value) into
|
||||
// a time.Duration; when units are missing (such as when a numeric type is
|
||||
// provided), the duration is assumed to be in seconds.
|
||||
func ParseDurationSecond(in interface{}) (time.Duration, error) {
|
||||
var dur time.Duration
|
||||
jsonIn, ok := in.(json.Number)
|
||||
@ -105,20 +109,22 @@ func ParseDurationSecond(in interface{}) (time.Duration, error) {
|
||||
if inp == "" {
|
||||
return dur, nil
|
||||
}
|
||||
|
||||
if v, err := strconv.ParseInt(inp, 10, 64); err == nil {
|
||||
return time.Duration(v) * time.Second, nil
|
||||
}
|
||||
|
||||
if strings.HasSuffix(inp, "d") {
|
||||
v, err := strconv.ParseInt(inp[:len(inp)-1], 10, 64)
|
||||
if err != nil {
|
||||
return dur, err
|
||||
}
|
||||
return time.Duration(v) * 24 * time.Hour, nil
|
||||
}
|
||||
|
||||
var err error
|
||||
// Look for a suffix otherwise its a plain second value
|
||||
if strings.HasSuffix(inp, "s") || strings.HasSuffix(inp, "m") || strings.HasSuffix(inp, "h") || strings.HasSuffix(inp, "ms") {
|
||||
dur, err = time.ParseDuration(inp)
|
||||
if err != nil {
|
||||
return dur, err
|
||||
}
|
||||
} else {
|
||||
// Plain integer
|
||||
secs, err := strconv.ParseInt(inp, 10, 64)
|
||||
if err != nil {
|
||||
return dur, err
|
||||
}
|
||||
dur = time.Duration(secs) * time.Second
|
||||
if dur, err = time.ParseDuration(inp); err != nil {
|
||||
return dur, err
|
||||
}
|
||||
case int:
|
||||
dur = time.Duration(inp) * time.Second
|
||||
@ -145,6 +151,9 @@ func ParseDurationSecond(in interface{}) (time.Duration, error) {
|
||||
return dur, nil
|
||||
}
|
||||
|
||||
// Parse an absolute timestamp from the provided arbitrary value (string or
|
||||
// numeric value). When an untyped numeric value is provided, it is assumed
|
||||
// to be seconds from the Unix Epoch.
|
||||
func ParseAbsoluteTime(in interface{}) (time.Time, error) {
|
||||
var t time.Time
|
||||
switch inp := in.(type) {
|
||||
@ -193,6 +202,13 @@ func ParseAbsoluteTime(in interface{}) (time.Time, error) {
|
||||
return t, nil
|
||||
}
|
||||
|
||||
// ParseInt takes an arbitrary value (either a string or numeric type) and
|
||||
// parses it as an int64 value. This value is assumed to be larger than the
|
||||
// provided type, but cannot safely be cast.
|
||||
//
|
||||
// When the end value is bounded (such as an int value), it is recommended
|
||||
// to instead call SafeParseInt or SafeParseIntRange to safely cast to a
|
||||
// more restrictive type.
|
||||
func ParseInt(in interface{}) (int64, error) {
|
||||
var ret int64
|
||||
jsonIn, ok := in.(json.Number)
|
||||
@ -230,6 +246,104 @@ func ParseInt(in interface{}) (int64, error) {
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
// ParseDirectIntSlice behaves similarly to ParseInt, but accepts typed
|
||||
// slices, returning a slice of int64s.
|
||||
//
|
||||
// If the starting value may not be in slice form (e.g.. a bare numeric value
|
||||
// could be provided), it is suggested to call ParseIntSlice instead.
|
||||
func ParseDirectIntSlice(in interface{}) ([]int64, error) {
|
||||
var ret []int64
|
||||
|
||||
switch in.(type) {
|
||||
case []int:
|
||||
for _, v := range in.([]int) {
|
||||
ret = append(ret, int64(v))
|
||||
}
|
||||
case []int32:
|
||||
for _, v := range in.([]int32) {
|
||||
ret = append(ret, int64(v))
|
||||
}
|
||||
case []int64:
|
||||
// For consistency to ensure callers can always modify ret without
|
||||
// impacting in.
|
||||
for _, v := range in.([]int64) {
|
||||
ret = append(ret, v)
|
||||
}
|
||||
case []uint:
|
||||
for _, v := range in.([]uint) {
|
||||
ret = append(ret, int64(v))
|
||||
}
|
||||
case []uint32:
|
||||
for _, v := range in.([]uint32) {
|
||||
ret = append(ret, int64(v))
|
||||
}
|
||||
case []uint64:
|
||||
for _, v := range in.([]uint64) {
|
||||
ret = append(ret, int64(v))
|
||||
}
|
||||
case []json.Number:
|
||||
for _, v := range in.([]json.Number) {
|
||||
element, err := ParseInt(v)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret = append(ret, element)
|
||||
}
|
||||
case []string:
|
||||
for _, v := range in.([]string) {
|
||||
element, err := ParseInt(v)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret = append(ret, element)
|
||||
}
|
||||
default:
|
||||
return nil, errors.New("could not parse value from input")
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
// ParseIntSlice is a helper function for handling upgrades of optional
|
||||
// slices; that is, if the API accepts a type similar to <int|[]int>,
|
||||
// nicely handle the common cases of providing only an int-ish, providing
|
||||
// an actual slice of int-ishes, or providing a comma-separated list of
|
||||
// numbers.
|
||||
//
|
||||
// When []int64 is not the desired final type (or the values should be
|
||||
// range-bound), it is suggested to call SafeParseIntSlice or
|
||||
// SafeParseIntSliceRange instead.
|
||||
func ParseIntSlice(in interface{}) ([]int64, error) {
|
||||
if ret, err := ParseInt(in); err == nil {
|
||||
return []int64{ret}, nil
|
||||
}
|
||||
|
||||
if ret, err := ParseDirectIntSlice(in); err == nil {
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
if strings, err := ParseCommaStringSlice(in); err == nil {
|
||||
var ret []int64
|
||||
for _, v := range strings {
|
||||
if v == "" {
|
||||
// Ignore empty fields
|
||||
continue
|
||||
}
|
||||
|
||||
element, err := ParseInt(v)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret = append(ret, element)
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
return nil, errors.New("could not parse value from input")
|
||||
}
|
||||
|
||||
// Parses the provided arbitrary value as a boolean-like value.
|
||||
func ParseBool(in interface{}) (bool, error) {
|
||||
var result bool
|
||||
if err := mapstructure.WeakDecode(in, &result); err != nil {
|
||||
@ -238,6 +352,7 @@ func ParseBool(in interface{}) (bool, error) {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// Parses the provided arbitrary value as a string.
|
||||
func ParseString(in interface{}) (string, error) {
|
||||
var result string
|
||||
if err := mapstructure.WeakDecode(in, &result); err != nil {
|
||||
@ -246,7 +361,13 @@ func ParseString(in interface{}) (string, error) {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// Parses the provided string-like value as a comma-separated list of values.
|
||||
func ParseCommaStringSlice(in interface{}) ([]string, error) {
|
||||
jsonIn, ok := in.(json.Number)
|
||||
if ok {
|
||||
in = jsonIn.String()
|
||||
}
|
||||
|
||||
rawString, ok := in.(string)
|
||||
if ok && rawString == "" {
|
||||
return []string{}, nil
|
||||
@ -267,6 +388,7 @@ func ParseCommaStringSlice(in interface{}) ([]string, error) {
|
||||
return strutil.TrimStrings(result), nil
|
||||
}
|
||||
|
||||
// Parses the specified value as one or more addresses, separated by commas.
|
||||
func ParseAddrs(addrs interface{}) ([]*sockaddr.SockAddrMarshaler, error) {
|
||||
out := make([]*sockaddr.SockAddrMarshaler, 0)
|
||||
stringAddrs := make([]string, 0)
|
||||
@ -306,3 +428,75 @@ func ParseAddrs(addrs interface{}) ([]*sockaddr.SockAddrMarshaler, error) {
|
||||
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Parses the provided arbitrary value (see ParseInt), ensuring it is within
|
||||
// the specified range (inclusive of bounds). If this range corresponds to a
|
||||
// smaller type, the returned value can then be safely cast without risking
|
||||
// overflow.
|
||||
func SafeParseIntRange(in interface{}, min int64, max int64) (int64, error) {
|
||||
raw, err := ParseInt(in)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
if raw < min || raw > max {
|
||||
return 0, fmt.Errorf("error parsing int value; out of range [%v to %v]: %v", min, max, raw)
|
||||
}
|
||||
|
||||
return raw, nil
|
||||
}
|
||||
|
||||
// Parses the specified arbitrary value (see ParseInt), ensuring that the
|
||||
// resulting value is within the range for an int value. If no error occurred,
|
||||
// the caller knows no overflow occurred.
|
||||
func SafeParseInt(in interface{}) (int, error) {
|
||||
raw, err := SafeParseIntRange(in, math.MinInt, math.MaxInt)
|
||||
return int(raw), err
|
||||
}
|
||||
|
||||
// Parses the provided arbitrary value (see ParseIntSlice) into a slice of
|
||||
// int64 values, ensuring each is within the specified range (inclusive of
|
||||
// bounds). If this range corresponds to a smaller type, the returned value
|
||||
// can then be safely cast without risking overflow.
|
||||
//
|
||||
// If elements is positive, it is used to ensure the resulting slice is
|
||||
// bounded above by that many number of elements (inclusive).
|
||||
func SafeParseIntSliceRange(in interface{}, minValue int64, maxValue int64, elements int) ([]int64, error) {
|
||||
raw, err := ParseIntSlice(in)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if elements > 0 && len(raw) > elements {
|
||||
return nil, fmt.Errorf("error parsing value from input: got %v but expected at most %v elements", len(raw), elements)
|
||||
}
|
||||
|
||||
for index, value := range raw {
|
||||
if value < minValue || value > maxValue {
|
||||
return nil, fmt.Errorf("error parsing value from input: element %v was outside of range [%v to %v]: %v", index, minValue, maxValue, value)
|
||||
}
|
||||
}
|
||||
|
||||
return raw, nil
|
||||
}
|
||||
|
||||
// Parses the provided arbitrary value (see ParseIntSlice) into a slice of
|
||||
// int values, ensuring the each resulting value in the slice is within the
|
||||
// range for an int value. If no error occurred, the caller knows no overflow
|
||||
// occurred.
|
||||
//
|
||||
// If elements is positive, it is used to ensure the resulting slice is
|
||||
// bounded above by that many number of elements (inclusive).
|
||||
func SafeParseIntSlice(in interface{}, elements int) ([]int, error) {
|
||||
raw, err := SafeParseIntSliceRange(in, math.MinInt, math.MaxInt, elements)
|
||||
if err != nil || raw == nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result = make([]int, len(raw))
|
||||
for _, element := range raw {
|
||||
result = append(result, int(element))
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
42
vendor/github.com/hashicorp/go-secure-stdlib/strutil/strutil.go
generated
vendored
42
vendor/github.com/hashicorp/go-secure-stdlib/strutil/strutil.go
generated
vendored
@ -230,16 +230,16 @@ func TrimStrings(items []string) []string {
|
||||
// strings. This also may convert the items in the slice to lower case and
|
||||
// returns a sorted slice.
|
||||
func RemoveDuplicates(items []string, lowercase bool) []string {
|
||||
itemsMap := map[string]bool{}
|
||||
itemsMap := make(map[string]struct{}, len(items))
|
||||
for _, item := range items {
|
||||
item = strings.TrimSpace(item)
|
||||
if lowercase {
|
||||
item = strings.ToLower(item)
|
||||
}
|
||||
if item == "" {
|
||||
continue
|
||||
}
|
||||
itemsMap[item] = true
|
||||
if lowercase {
|
||||
item = strings.ToLower(item)
|
||||
}
|
||||
itemsMap[item] = struct{}{}
|
||||
}
|
||||
items = make([]string, 0, len(itemsMap))
|
||||
for item := range itemsMap {
|
||||
@ -254,18 +254,21 @@ func RemoveDuplicates(items []string, lowercase bool) []string {
|
||||
// In all cases, strings are compared after trimming whitespace
|
||||
// If caseInsensitive, strings will be compared after ToLower()
|
||||
func RemoveDuplicatesStable(items []string, caseInsensitive bool) []string {
|
||||
itemsMap := make(map[string]bool, len(items))
|
||||
itemsMap := make(map[string]struct{}, len(items))
|
||||
deduplicated := make([]string, 0, len(items))
|
||||
|
||||
for _, item := range items {
|
||||
key := strings.TrimSpace(item)
|
||||
if _, ok := itemsMap[key]; ok || key == "" {
|
||||
continue
|
||||
}
|
||||
if caseInsensitive {
|
||||
key = strings.ToLower(key)
|
||||
}
|
||||
if key == "" || itemsMap[key] {
|
||||
if _, ok := itemsMap[key]; ok {
|
||||
continue
|
||||
}
|
||||
itemsMap[key] = true
|
||||
itemsMap[key] = struct{}{}
|
||||
deduplicated = append(deduplicated, item)
|
||||
}
|
||||
return deduplicated
|
||||
@ -299,17 +302,18 @@ func EquivalentSlices(a, b []string) bool {
|
||||
}
|
||||
|
||||
// First we'll build maps to ensure unique values
|
||||
mapA := map[string]bool{}
|
||||
mapB := map[string]bool{}
|
||||
mapA := make(map[string]struct{}, len(a))
|
||||
mapB := make(map[string]struct{}, len(b))
|
||||
for _, keyA := range a {
|
||||
mapA[keyA] = true
|
||||
mapA[keyA] = struct{}{}
|
||||
}
|
||||
for _, keyB := range b {
|
||||
mapB[keyB] = true
|
||||
mapB[keyB] = struct{}{}
|
||||
}
|
||||
|
||||
// Now we'll build our checking slices
|
||||
var sortedA, sortedB []string
|
||||
sortedA := make([]string, 0, len(mapA))
|
||||
sortedB := make([]string, 0, len(mapB))
|
||||
for keyA := range mapA {
|
||||
sortedA = append(sortedA, keyA)
|
||||
}
|
||||
@ -434,23 +438,21 @@ func Difference(a, b []string, lowercase bool) []string {
|
||||
a = RemoveDuplicates(a, lowercase)
|
||||
b = RemoveDuplicates(b, lowercase)
|
||||
|
||||
itemsMap := map[string]bool{}
|
||||
itemsMap := map[string]struct{}{}
|
||||
for _, aVal := range a {
|
||||
itemsMap[aVal] = true
|
||||
itemsMap[aVal] = struct{}{}
|
||||
}
|
||||
|
||||
// Perform difference calculation
|
||||
for _, bVal := range b {
|
||||
if _, ok := itemsMap[bVal]; ok {
|
||||
itemsMap[bVal] = false
|
||||
delete(itemsMap, bVal)
|
||||
}
|
||||
}
|
||||
|
||||
items := []string{}
|
||||
for item, exists := range itemsMap {
|
||||
if exists {
|
||||
items = append(items, item)
|
||||
}
|
||||
for item := range itemsMap {
|
||||
items = append(items, item)
|
||||
}
|
||||
sort.Strings(items)
|
||||
return items
|
||||
|
Reference in New Issue
Block a user