agent: remove deadcode that called lib.TranslateKeys
Move the last remaining function from agent/config.go to the one place it was called.
This commit is contained in:
parent
54b8a410a9
commit
abed523b60
100
agent/config.go
100
agent/config.go
|
@ -1,100 +0,0 @@
|
||||||
package agent
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/hashicorp/consul/lib"
|
|
||||||
)
|
|
||||||
|
|
||||||
var errInvalidHeaderFormat = errors.New("agent: invalid format of 'header' field")
|
|
||||||
|
|
||||||
func FixupCheckType(raw interface{}) error {
|
|
||||||
rawMap, ok := raw.(map[string]interface{})
|
|
||||||
if !ok {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// See https://github.com/hashicorp/consul/pull/3557 why we need this
|
|
||||||
// and why we should get rid of it. In Consul 1.0 we also didn't map
|
|
||||||
// Args correctly, so we ended up exposing (and need to carry forward)
|
|
||||||
// ScriptArgs, see https://github.com/hashicorp/consul/issues/3587.
|
|
||||||
lib.TranslateKeys(rawMap, map[string]string{
|
|
||||||
"args": "ScriptArgs",
|
|
||||||
"script_args": "ScriptArgs",
|
|
||||||
"deregister_critical_service_after": "DeregisterCriticalServiceAfter",
|
|
||||||
"docker_container_id": "DockerContainerID",
|
|
||||||
"tls_skip_verify": "TLSSkipVerify",
|
|
||||||
"service_id": "ServiceID",
|
|
||||||
})
|
|
||||||
|
|
||||||
parseDuration := func(v interface{}) (time.Duration, error) {
|
|
||||||
if v == nil {
|
|
||||||
return 0, nil
|
|
||||||
}
|
|
||||||
switch x := v.(type) {
|
|
||||||
case time.Duration:
|
|
||||||
return x, nil
|
|
||||||
case float64:
|
|
||||||
return time.Duration(x), nil
|
|
||||||
case string:
|
|
||||||
return time.ParseDuration(x)
|
|
||||||
default:
|
|
||||||
return 0, fmt.Errorf("invalid format")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
parseHeaderMap := func(v interface{}) (map[string][]string, error) {
|
|
||||||
if v == nil {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
vm, ok := v.(map[string]interface{})
|
|
||||||
if !ok {
|
|
||||||
return nil, errInvalidHeaderFormat
|
|
||||||
}
|
|
||||||
m := map[string][]string{}
|
|
||||||
for k, vv := range vm {
|
|
||||||
vs, ok := vv.([]interface{})
|
|
||||||
if !ok {
|
|
||||||
return nil, errInvalidHeaderFormat
|
|
||||||
}
|
|
||||||
for _, vs := range vs {
|
|
||||||
s, ok := vs.(string)
|
|
||||||
if !ok {
|
|
||||||
return nil, errInvalidHeaderFormat
|
|
||||||
}
|
|
||||||
m[k] = append(m[k], s)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return m, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
for k, v := range rawMap {
|
|
||||||
switch strings.ToLower(k) {
|
|
||||||
case "header":
|
|
||||||
h, err := parseHeaderMap(v)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("invalid %q: %s", k, err)
|
|
||||||
}
|
|
||||||
rawMap[k] = h
|
|
||||||
|
|
||||||
case "ttl", "interval", "timeout", "deregistercriticalserviceafter":
|
|
||||||
d, err := parseDuration(v)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("invalid %q: %v", k, err)
|
|
||||||
}
|
|
||||||
rawMap[k] = d
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func ParseMetaPair(raw string) (string, string) {
|
|
||||||
pair := strings.SplitN(raw, ":", 2)
|
|
||||||
if len(pair) == 2 {
|
|
||||||
return pair[0], pair[1]
|
|
||||||
}
|
|
||||||
return pair[0], ""
|
|
||||||
}
|
|
|
@ -1038,7 +1038,7 @@ func (s *HTTPServer) parseMetaFilter(req *http.Request) map[string]string {
|
||||||
if filterList, ok := req.URL.Query()["node-meta"]; ok {
|
if filterList, ok := req.URL.Query()["node-meta"]; ok {
|
||||||
filters := make(map[string]string)
|
filters := make(map[string]string)
|
||||||
for _, filter := range filterList {
|
for _, filter := range filterList {
|
||||||
key, value := ParseMetaPair(filter)
|
key, value := parseMetaPair(filter)
|
||||||
filters[key] = value
|
filters[key] = value
|
||||||
}
|
}
|
||||||
return filters
|
return filters
|
||||||
|
@ -1046,6 +1046,14 @@ func (s *HTTPServer) parseMetaFilter(req *http.Request) map[string]string {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseMetaPair(raw string) (string, string) {
|
||||||
|
pair := strings.SplitN(raw, ":", 2)
|
||||||
|
if len(pair) == 2 {
|
||||||
|
return pair[0], pair[1]
|
||||||
|
}
|
||||||
|
return pair[0], ""
|
||||||
|
}
|
||||||
|
|
||||||
// parseInternal is a convenience method for endpoints that need
|
// parseInternal is a convenience method for endpoints that need
|
||||||
// to use both parseWait and parseDC.
|
// to use both parseWait and parseDC.
|
||||||
func (s *HTTPServer) parseInternal(resp http.ResponseWriter, req *http.Request, dc *string, b structs.QueryOptionsCompat) bool {
|
func (s *HTTPServer) parseInternal(resp http.ResponseWriter, req *http.Request, dc *string, b structs.QueryOptionsCompat) bool {
|
||||||
|
|
Loading…
Reference in New Issue