Support v1 configurations for config dump

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
Derek McGowan 2019-09-03 17:12:03 -07:00
parent db3a711738
commit 01f7265892
No known key found for this signature in database
GPG Key ID: F58C5D0A4405ACDB

View File

@ -45,11 +45,6 @@ func outputConfig(cfg *srvconfig.Config) error {
Config: cfg, Config: cfg,
} }
// for the time being, keep the defaultConfig's version set at 1 so that
// when a config without a version is loaded from disk and has no version
// set, we assume it's a v1 config. But when generating new configs via
// this command, generate the v2 config
config.Config.Version = 2
plugins, err := server.LoadPlugins(gocontext.Background(), config.Config) plugins, err := server.LoadPlugins(gocontext.Background(), config.Config)
if err != nil { if err != nil {
return err return err
@ -60,15 +55,31 @@ func outputConfig(cfg *srvconfig.Config) error {
if p.Config == nil { if p.Config == nil {
continue continue
} }
config.Plugins[p.URI()] = p.Config
pc, err := config.Decode(p)
if err != nil {
return err
}
config.Plugins[p.URI()] = pc
} }
} }
timeouts := timeout.All() timeouts := timeout.All()
config.Timeouts = make(map[string]string) config.Timeouts = make(map[string]string)
for k, v := range timeouts { for k, v := range timeouts {
config.Timeouts[k] = v.String() config.Timeouts[k] = v.String()
} }
// for the time being, keep the defaultConfig's version set at 1 so that
// when a config without a version is loaded from disk and has no version
// set, we assume it's a v1 config. But when generating new configs via
// this command, generate the v2 config
config.Config.Version = 2
// remove overridden Plugins type to avoid duplication in output
config.Config.Plugins = nil
_, err = config.WriteTo(os.Stdout) _, err = config.WriteTo(os.Stdout)
return err return err
} }