aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/hashicorp/vault/helper
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/hashicorp/vault/helper')
-rw-r--r--vendor/github.com/hashicorp/vault/helper/consts/consts.go14
-rw-r--r--vendor/github.com/hashicorp/vault/helper/consts/error.go16
-rw-r--r--vendor/github.com/hashicorp/vault/helper/consts/replication.go82
-rw-r--r--vendor/github.com/hashicorp/vault/helper/parseutil/parseutil.go2
-rw-r--r--vendor/github.com/hashicorp/vault/helper/strutil/strutil.go61
5 files changed, 154 insertions, 21 deletions
diff --git a/vendor/github.com/hashicorp/vault/helper/consts/consts.go b/vendor/github.com/hashicorp/vault/helper/consts/consts.go
new file mode 100644
index 0000000..972a69f
--- /dev/null
+++ b/vendor/github.com/hashicorp/vault/helper/consts/consts.go
@@ -0,0 +1,14 @@
+package consts
+
+const (
+ // ExpirationRestoreWorkerCount specifies the number of workers to use while
+ // restoring leases into the expiration manager
+ ExpirationRestoreWorkerCount = 64
+
+ // NamespaceHeaderName is the header set to specify which namespace the
+ // request is indented for.
+ NamespaceHeaderName = "X-Vault-Namespace"
+
+ // AuthHeaderName is the name of the header containing the token.
+ AuthHeaderName = "X-Vault-Token"
+)
diff --git a/vendor/github.com/hashicorp/vault/helper/consts/error.go b/vendor/github.com/hashicorp/vault/helper/consts/error.go
new file mode 100644
index 0000000..06977d5
--- /dev/null
+++ b/vendor/github.com/hashicorp/vault/helper/consts/error.go
@@ -0,0 +1,16 @@
+package consts
+
+import "errors"
+
+var (
+ // ErrSealed is returned if an operation is performed on a sealed barrier.
+ // No operation is expected to succeed before unsealing
+ ErrSealed = errors.New("Vault is sealed")
+
+ // ErrStandby is returned if an operation is performed on a standby Vault.
+ // No operation is expected to succeed until active.
+ ErrStandby = errors.New("Vault is in standby mode")
+
+ // Used when .. is used in a path
+ ErrPathContainsParentReferences = errors.New("path cannot contain parent references")
+)
diff --git a/vendor/github.com/hashicorp/vault/helper/consts/replication.go b/vendor/github.com/hashicorp/vault/helper/consts/replication.go
new file mode 100644
index 0000000..c109977
--- /dev/null
+++ b/vendor/github.com/hashicorp/vault/helper/consts/replication.go
@@ -0,0 +1,82 @@
+package consts
+
+type ReplicationState uint32
+
+const (
+ _ ReplicationState = iota
+ OldReplicationPrimary
+ OldReplicationSecondary
+ OldReplicationBootstrapping
+ // Don't add anything here. Adding anything to this Old block would cause
+ // the rest of the values to change below. This was done originally to
+ // ensure no overlap between old and new values.
+
+ ReplicationUnknown ReplicationState = 0
+ ReplicationPerformancePrimary ReplicationState = 1 << iota
+ ReplicationPerformanceSecondary
+ OldSplitReplicationBootstrapping
+ ReplicationDRPrimary
+ ReplicationDRSecondary
+ ReplicationPerformanceBootstrapping
+ ReplicationDRBootstrapping
+ ReplicationPerformanceDisabled
+ ReplicationDRDisabled
+)
+
+func (r ReplicationState) string() string {
+ switch r {
+ case ReplicationPerformanceSecondary:
+ return "secondary"
+ case ReplicationPerformancePrimary:
+ return "primary"
+ case ReplicationPerformanceBootstrapping:
+ return "bootstrapping"
+ case ReplicationPerformanceDisabled:
+ return "disabled"
+ case ReplicationDRPrimary:
+ return "primary"
+ case ReplicationDRSecondary:
+ return "secondary"
+ case ReplicationDRBootstrapping:
+ return "bootstrapping"
+ case ReplicationDRDisabled:
+ return "disabled"
+ }
+
+ return "unknown"
+}
+
+func (r ReplicationState) GetDRString() string {
+ switch {
+ case r.HasState(ReplicationDRBootstrapping):
+ return ReplicationDRBootstrapping.string()
+ case r.HasState(ReplicationDRPrimary):
+ return ReplicationDRPrimary.string()
+ case r.HasState(ReplicationDRSecondary):
+ return ReplicationDRSecondary.string()
+ case r.HasState(ReplicationDRDisabled):
+ return ReplicationDRDisabled.string()
+ default:
+ return "unknown"
+ }
+}
+
+func (r ReplicationState) GetPerformanceString() string {
+ switch {
+ case r.HasState(ReplicationPerformanceBootstrapping):
+ return ReplicationPerformanceBootstrapping.string()
+ case r.HasState(ReplicationPerformancePrimary):
+ return ReplicationPerformancePrimary.string()
+ case r.HasState(ReplicationPerformanceSecondary):
+ return ReplicationPerformanceSecondary.string()
+ case r.HasState(ReplicationPerformanceDisabled):
+ return ReplicationPerformanceDisabled.string()
+ default:
+ return "unknown"
+ }
+}
+
+func (r ReplicationState) HasState(flag ReplicationState) bool { return r&flag != 0 }
+func (r *ReplicationState) AddState(flag ReplicationState) { *r |= flag }
+func (r *ReplicationState) ClearState(flag ReplicationState) { *r &= ^flag }
+func (r *ReplicationState) ToggleState(flag ReplicationState) { *r ^= flag }
diff --git a/vendor/github.com/hashicorp/vault/helper/parseutil/parseutil.go b/vendor/github.com/hashicorp/vault/helper/parseutil/parseutil.go
index ae8c58b..9b32bf7 100644
--- a/vendor/github.com/hashicorp/vault/helper/parseutil/parseutil.go
+++ b/vendor/github.com/hashicorp/vault/helper/parseutil/parseutil.go
@@ -28,7 +28,7 @@ func ParseDurationSecond(in interface{}) (time.Duration, error) {
}
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") {
+ 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
diff --git a/vendor/github.com/hashicorp/vault/helper/strutil/strutil.go b/vendor/github.com/hashicorp/vault/helper/strutil/strutil.go
index a77e60d..8d84c1e 100644
--- a/vendor/github.com/hashicorp/vault/helper/strutil/strutil.go
+++ b/vendor/github.com/hashicorp/vault/helper/strutil/strutil.go
@@ -43,9 +43,9 @@ func StrListSubset(super, sub []string) bool {
return true
}
-// Parses a comma separated list of strings into a slice of strings.
-// The return slice will be sorted and will not contain duplicate or
-// empty items.
+// ParseDedupAndSortStrings parses a comma separated list of strings
+// into a slice of strings. The return slice will be sorted and will
+// not contain duplicate or empty items.
func ParseDedupAndSortStrings(input string, sep string) []string {
input = strings.TrimSpace(input)
parsed := []string{}
@@ -56,9 +56,10 @@ func ParseDedupAndSortStrings(input string, sep string) []string {
return RemoveDuplicates(strings.Split(input, sep), false)
}
-// Parses a comma separated list of strings into a slice of strings.
-// The return slice will be sorted and will not contain duplicate or
-// empty items. The values will be converted to lower case.
+// ParseDedupLowercaseAndSortStrings parses a comma separated list of
+// strings into a slice of strings. The return slice will be sorted and
+// will not contain duplicate or empty items. The values will be converted
+// to lower case.
func ParseDedupLowercaseAndSortStrings(input string, sep string) []string {
input = strings.TrimSpace(input)
parsed := []string{}
@@ -69,8 +70,8 @@ func ParseDedupLowercaseAndSortStrings(input string, sep string) []string {
return RemoveDuplicates(strings.Split(input, sep), true)
}
-// Parses a comma separated list of `<key>=<value>` tuples into a
-// map[string]string.
+// ParseKeyValues parses a comma separated list of `<key>=<value>` tuples
+// into a map[string]string.
func ParseKeyValues(input string, out map[string]string, sep string) error {
if out == nil {
return fmt.Errorf("'out is nil")
@@ -97,8 +98,8 @@ func ParseKeyValues(input string, out map[string]string, sep string) error {
return nil
}
-// Parses arbitrary <key,value> tuples. The input can be one of
-// the following:
+// ParseArbitraryKeyValues parses arbitrary <key,value> tuples. The input
+// can be one of the following:
// * JSON string
// * Base64 encoded JSON string
// * Comma separated list of `<key>=<value>` pairs
@@ -144,8 +145,8 @@ func ParseArbitraryKeyValues(input string, out map[string]string, sep string) er
return nil
}
-// Parses a `sep`-separated list of strings into a
-// []string.
+// ParseStringSlice parses a `sep`-separated list of strings into a
+// []string with surrounding whitespace removed.
//
// The output will always be a valid slice but may be of length zero.
func ParseStringSlice(input string, sep string) []string {
@@ -157,14 +158,14 @@ func ParseStringSlice(input string, sep string) []string {
splitStr := strings.Split(input, sep)
ret := make([]string, len(splitStr))
for i, val := range splitStr {
- ret[i] = val
+ ret[i] = strings.TrimSpace(val)
}
return ret
}
-// Parses arbitrary string slice. The input can be one of
-// the following:
+// ParseArbitraryStringSlice parses arbitrary string slice. The input
+// can be one of the following:
// * JSON string
// * Base64 encoded JSON string
// * `sep` separated list of values
@@ -215,8 +216,9 @@ func TrimStrings(items []string) []string {
return ret
}
-// Removes duplicate and empty elements from a slice of strings. This also may
-// convert the items in the slice to lower case and returns a sorted slice.
+// RemoveDuplicates removes duplicate and empty elements from a slice of
+// 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{}
for _, item := range items {
@@ -230,7 +232,7 @@ func RemoveDuplicates(items []string, lowercase bool) []string {
itemsMap[item] = true
}
items = make([]string, 0, len(itemsMap))
- for item, _ := range itemsMap {
+ for item := range itemsMap {
items = append(items, item)
}
sort.Strings(items)
@@ -260,10 +262,10 @@ func EquivalentSlices(a, b []string) bool {
// Now we'll build our checking slices
var sortedA, sortedB []string
- for keyA, _ := range mapA {
+ for keyA := range mapA {
sortedA = append(sortedA, keyA)
}
- for keyB, _ := range mapB {
+ for keyB := range mapB {
sortedB = append(sortedB, keyB)
}
sort.Strings(sortedA)
@@ -299,6 +301,8 @@ func StrListDelete(s []string, d string) []string {
return s
}
+// GlobbedStringsMatch compares item to val with support for a leading and/or
+// trailing wildcard '*' in item.
func GlobbedStringsMatch(item, val string) bool {
if len(item) < 2 {
return val == item
@@ -325,3 +329,20 @@ func AppendIfMissing(slice []string, i string) []string {
}
return append(slice, i)
}
+
+// MergeSlices adds an arbitrary number of slices together, uniquely
+func MergeSlices(args ...[]string) []string {
+ all := map[string]struct{}{}
+ for _, slice := range args {
+ for _, v := range slice {
+ all[v] = struct{}{}
+ }
+ }
+
+ result := make([]string, 0, len(all))
+ for k, _ := range all {
+ result = append(result, k)
+ }
+ sort.Strings(result)
+ return result
+}