1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
15 "git.curoverse.com/arvados.git/lib/cmd"
16 "git.curoverse.com/arvados.git/sdk/go/ctxlog"
17 "github.com/ghodss/yaml"
20 var DumpCommand cmd.Handler = 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)
32 err = fmt.Errorf("usage: %s <config-src.yaml >config-min.yaml", prog)
35 log := ctxlog.New(stderr, "text", "info")
36 cfg, err := Load(stdin, log)
40 out, err := yaml.Marshal(cfg)
44 _, err = stdout.Write(out)
51 var CheckCommand cmd.Handler = checkCommand{}
53 type checkCommand struct{}
55 func (checkCommand) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
59 fmt.Fprintf(stderr, "%s\n", err)
63 err = fmt.Errorf("usage: %s <config-src.yaml && echo 'no changes needed'", prog)
66 log := &plainLogger{w: stderr}
67 buf, err := ioutil.ReadAll(stdin)
71 withoutDepr, err := load(bytes.NewBuffer(buf), log, false)
75 withDepr, err := load(bytes.NewBuffer(buf), nil, true)
79 cmd := exec.Command("diff", "-u", "--label", "without-deprecated-configs", "--label", "relying-on-deprecated-configs", "/dev/fd/3", "/dev/fd/4")
80 for _, obj := range []interface{}{withoutDepr, withDepr} {
81 y, _ := yaml.Marshal(obj)
82 pr, pw, err := os.Pipe()
88 io.Copy(pw, bytes.NewBuffer(y))
91 cmd.ExtraFiles = append(cmd.ExtraFiles, pr)
93 diff, err := cmd.CombinedOutput()
94 if bytes.HasPrefix(diff, []byte("--- ")) {
95 fmt.Fprintln(stdout, "Your configuration is relying on deprecated entries. Suggest making the following changes.")
98 } else if len(diff) > 0 {
99 fmt.Fprintf(stderr, "Unexpected diff output:\n%s", diff)
101 } else if err != nil {
110 type plainLogger struct {
115 func (pl *plainLogger) Warnf(format string, args ...interface{}) {
117 fmt.Fprintf(pl.w, format+"\n", args...)