From 54bc937feda62c17f09f452650e599821b594432 Mon Sep 17 00:00:00 2001 From: Kyle Havlovitz Date: Fri, 25 May 2018 10:28:18 -0700 Subject: [PATCH] Re-use uint8ToString --- agent/connect/ca/provider_consul_config.go | 18 +++++++++--------- agent/connect_ca_endpoint.go | 17 +++++++---------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/agent/connect/ca/provider_consul_config.go b/agent/connect/ca/provider_consul_config.go index e0112b3e2..9eae88610 100644 --- a/agent/connect/ca/provider_consul_config.go +++ b/agent/connect/ca/provider_consul_config.go @@ -37,14 +37,6 @@ func ParseConsulCAConfig(raw map[string]interface{}) (*structs.ConsulCAProviderC // ParseDurationFunc is a mapstructure hook for decoding a string or // []uint8 into a time.Duration value. func ParseDurationFunc() mapstructure.DecodeHookFunc { - uint8ToString := func(bs []uint8) string { - b := make([]byte, len(bs)) - for i, v := range bs { - b[i] = byte(v) - } - return string(b) - } - return func( f reflect.Type, t reflect.Type, @@ -63,7 +55,7 @@ func ParseDurationFunc() mapstructure.DecodeHookFunc { } return v, nil case f == reflect.SliceOf(reflect.TypeOf(uint8(0))): - s := uint8ToString(data.([]uint8)) + s := Uint8ToString(data.([]uint8)) if dur, err := time.ParseDuration(s); err != nil { return nil, err } else { @@ -75,3 +67,11 @@ func ParseDurationFunc() mapstructure.DecodeHookFunc { } } } + +func Uint8ToString(bs []uint8) string { + b := make([]byte, len(bs)) + for i, v := range bs { + b[i] = byte(v) + } + return string(b) +} diff --git a/agent/connect_ca_endpoint.go b/agent/connect_ca_endpoint.go index f7f83b13a..49851baac 100644 --- a/agent/connect_ca_endpoint.go +++ b/agent/connect_ca_endpoint.go @@ -4,6 +4,7 @@ import ( "fmt" "net/http" + "github.com/hashicorp/consul/agent/connect/ca" "github.com/hashicorp/consul/agent/structs" ) @@ -47,8 +48,12 @@ func (s *HTTPServer) ConnectCAConfigurationGet(resp http.ResponseWriter, req *ht var reply structs.CAConfiguration err := s.agent.RPC("ConnectCA.ConfigurationGet", &args, &reply) + if err != nil { + return nil, err + } + fixupConfig(&reply) - return reply, err + return reply, nil } // PUT /v1/connect/ca/configuration @@ -77,16 +82,8 @@ func fixupConfig(conf *structs.CAConfiguration) { if conf.Provider == structs.ConsulCAProvider { if v, ok := conf.Config["RotationPeriod"]; ok { if raw, ok := v.([]uint8); ok { - conf.Config["RotationPeriod"] = uint8ToString(raw) + conf.Config["RotationPeriod"] = ca.Uint8ToString(raw) } } } } - -func uint8ToString(bs []uint8) string { - b := make([]byte, len(bs)) - for i, v := range bs { - b[i] = byte(v) - } - return string(b) -}