From 549dc22944a9487293e41c32989b5916aead1b99 Mon Sep 17 00:00:00 2001 From: Kyle Havlovitz Date: Mon, 11 Jun 2018 13:59:29 -0700 Subject: [PATCH] connect: fix two CA tests that were broken in a previous PR (#60) --- agent/connect_ca_endpoint.go | 2 +- api/connect_ca.go | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/agent/connect_ca_endpoint.go b/agent/connect_ca_endpoint.go index dd8d4a4b7..ea984ed37 100644 --- a/agent/connect_ca_endpoint.go +++ b/agent/connect_ca_endpoint.go @@ -85,7 +85,7 @@ func fixupConfig(conf *structs.CAConfiguration) { conf.Config[k] = ca.Uint8ToString(raw) } } - if conf.Config["PrivateKey"] != "" { + if v, ok := conf.Config["PrivateKey"]; ok && v != "" { conf.Config["PrivateKey"] = "hidden" } } diff --git a/api/connect_ca.go b/api/connect_ca.go index c43339969..947f70976 100644 --- a/api/connect_ca.go +++ b/api/connect_ca.go @@ -32,7 +32,19 @@ type ConsulCAProviderConfig struct { // ConsulCAProviderConfig. func ParseConsulCAConfig(raw map[string]interface{}) (*ConsulCAProviderConfig, error) { var config ConsulCAProviderConfig - if err := mapstructure.WeakDecode(raw, &config); err != nil { + decodeConf := &mapstructure.DecoderConfig{ + DecodeHook: mapstructure.StringToTimeDurationHookFunc(), + ErrorUnused: true, + Result: &config, + WeaklyTypedInput: true, + } + + decoder, err := mapstructure.NewDecoder(decodeConf) + if err != nil { + return nil, err + } + + if err := decoder.Decode(raw); err != nil { return nil, fmt.Errorf("error decoding config: %s", err) }