forked from splunk/vault-plugin-splunk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
36 lines (30 loc) · 805 Bytes
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package splunk
import (
"reflect"
"regexp"
"strings"
"github.com/hashicorp/vault/logical"
"github.com/hashicorp/vault/logical/framework"
)
func getValue(data *framework.FieldData, op logical.Operation, key string) (interface{}, bool) {
if raw, ok := data.GetOk(key); ok {
return raw, true
}
if op == logical.CreateOperation {
return data.Get(key), true
}
return nil, false
}
func decodeValue(data *framework.FieldData, op logical.Operation, key string, v interface{}) error {
raw, ok := getValue(data, op, key)
if ok {
rraw := reflect.ValueOf(raw)
rv := reflect.ValueOf(v)
rv.Elem().Set(rraw)
}
return nil
}
var indentWhitespace = regexp.MustCompile("(?m:^[ \t]*)")
func trimIndent(s string) string {
return strings.TrimRight(indentWhitespace.ReplaceAllString(s, ""), "")
}