1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
15 "git.curoverse.com/arvados.git/sdk/go/ctxlog"
16 "github.com/ghodss/yaml"
17 "github.com/sirupsen/logrus"
20 var DumpCommand dumpCommand
22 type dumpCommand struct{}
24 func (dumpCommand) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
28 fmt.Fprintf(stderr, "%s\n", err)
34 Logger: ctxlog.New(stderr, "text", "info"),
37 flags := flag.NewFlagSet("", flag.ContinueOnError)
38 flags.SetOutput(stderr)
39 loader.SetupFlags(flags)
41 err = flags.Parse(args)
42 if err == flag.ErrHelp {
45 } else if err != nil {
49 if len(flags.Args()) != 0 {
54 cfg, err := loader.Load()
58 out, err := yaml.Marshal(cfg)
62 _, err = stdout.Write(out)
69 var CheckCommand checkCommand
71 type checkCommand struct{}
73 func (checkCommand) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
75 var logbuf = &bytes.Buffer{}
77 io.Copy(stderr, logbuf)
79 fmt.Fprintf(stderr, "%s\n", err)
83 logger := logrus.New()
90 flags := flag.NewFlagSet("", flag.ContinueOnError)
91 flags.SetOutput(stderr)
92 loader.SetupFlags(flags)
94 err = flags.Parse(args)
95 if err == flag.ErrHelp {
98 } else if err != nil {
102 if len(flags.Args()) != 0 {
107 // Load the config twice -- once without loading deprecated
108 // keys/files, once with -- and then compare the two resulting
109 // configs. This reveals whether the deprecated keys/files
110 // have any effect on the final configuration.
112 // If they do, show the operator how to update their config
113 // such that the deprecated keys/files are superfluous and can
115 loader.SkipDeprecated = true
116 withoutDepr, err := loader.Load()
120 loader.SkipDeprecated = false
121 withDepr, err := loader.Load()
125 cmd := exec.Command("diff", "-u", "--label", "without-deprecated-configs", "--label", "relying-on-deprecated-configs", "/dev/fd/3", "/dev/fd/4")
126 for _, obj := range []interface{}{withoutDepr, withDepr} {
127 y, _ := yaml.Marshal(obj)
128 pr, pw, err := os.Pipe()
134 io.Copy(pw, bytes.NewBuffer(y))
137 cmd.ExtraFiles = append(cmd.ExtraFiles, pr)
139 diff, err := cmd.CombinedOutput()
140 if bytes.HasPrefix(diff, []byte("--- ")) {
141 fmt.Fprintln(stdout, "Your configuration is relying on deprecated entries. Suggest making the following changes.")
145 } else if len(diff) > 0 {
146 fmt.Fprintf(stderr, "Unexpected diff output:\n%s", diff)
148 } else if err != nil {
151 if logbuf.Len() > 0 {
157 var DumpDefaultsCommand defaultsCommand
159 type defaultsCommand struct{}
161 func (defaultsCommand) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
162 _, err := stdout.Write(DefaultYAML)
164 fmt.Fprintln(stderr, err)