@@ -7,17 +7,12 @@ import (
77 "flag"
88 "fmt"
99 "io"
10- "time"
1110
12- "github.com/hashicorp/go-multierror"
1311 "github.com/mitchellh/cli"
14- "github.com/mitchellh/mapstructure"
1512
16- "github.com/hashicorp/consul/api"
1713 "github.com/hashicorp/consul/command/config"
1814 "github.com/hashicorp/consul/command/flags"
1915 "github.com/hashicorp/consul/command/helpers"
20- "github.com/hashicorp/consul/lib/decode"
2116)
2217
2318func New (ui cli.Ui ) * cmd {
@@ -109,67 +104,6 @@ func (c *cmd) Run(args []string) int {
109104 return 0
110105}
111106
112- // There is a 'structs' variation of this in
113- // agent/structs/config_entry.go:DecodeConfigEntry
114- func newDecodeConfigEntry (raw map [string ]interface {}) (api.ConfigEntry , error ) {
115- var entry api.ConfigEntry
116-
117- kindVal , ok := raw ["Kind" ]
118- if ! ok {
119- kindVal , ok = raw ["kind" ]
120- }
121- if ! ok {
122- return nil , fmt .Errorf ("Payload does not contain a kind/Kind key at the top level" )
123- }
124-
125- if kindStr , ok := kindVal .(string ); ok {
126- newEntry , err := api .MakeConfigEntry (kindStr , "" )
127- if err != nil {
128- return nil , err
129- }
130- entry = newEntry
131- } else {
132- return nil , fmt .Errorf ("Kind value in payload is not a string" )
133- }
134-
135- var md mapstructure.Metadata
136- decodeConf := & mapstructure.DecoderConfig {
137- DecodeHook : mapstructure .ComposeDecodeHookFunc (
138- decode .HookWeakDecodeFromSlice ,
139- decode .HookTranslateKeys ,
140- mapstructure .StringToTimeDurationHookFunc (),
141- mapstructure .StringToTimeHookFunc (time .RFC3339 ),
142- ),
143- Metadata : & md ,
144- Result : & entry ,
145- WeaklyTypedInput : true ,
146- }
147-
148- decoder , err := mapstructure .NewDecoder (decodeConf )
149- if err != nil {
150- return nil , err
151- }
152-
153- if err := decoder .Decode (raw ); err != nil {
154- return nil , err
155- }
156-
157- for _ , k := range md .Unused {
158- switch k {
159- case "kind" , "Kind" :
160- // The kind field is used to determine the target, but doesn't need
161- // to exist on the target.
162- continue
163- }
164- err = multierror .Append (err , fmt .Errorf ("invalid config key %q" , k ))
165- }
166- if err != nil {
167- return nil , err
168- }
169-
170- return entry , nil
171- }
172-
173107func (c * cmd ) Synopsis () string {
174108 return synopsis
175109}
0 commit comments