1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
15 "git.arvados.org/arvados.git/sdk/go/arvados"
16 "git.arvados.org/arvados.git/sdk/go/ctxlog"
17 "github.com/ghodss/yaml"
18 "github.com/sirupsen/logrus"
21 var DumpCommand dumpCommand
23 type dumpCommand struct{}
25 func (dumpCommand) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
29 fmt.Fprintf(stderr, "%s\n", err)
35 Logger: ctxlog.New(stderr, "text", "info"),
38 flags := flag.NewFlagSet("", flag.ContinueOnError)
39 flags.SetOutput(stderr)
40 loader.SetupFlags(flags)
42 err = flags.Parse(args)
43 if err == flag.ErrHelp {
46 } else if err != nil {
50 if len(flags.Args()) != 0 {
55 cfg, err := loader.Load()
59 out, err := yaml.Marshal(cfg)
63 _, err = stdout.Write(out)
70 var CheckCommand checkCommand
72 type checkCommand struct{}
74 func (checkCommand) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
76 var logbuf = &bytes.Buffer{}
78 io.Copy(stderr, logbuf)
80 fmt.Fprintf(stderr, "%s\n", err)
84 logger := logrus.New()
91 flags := flag.NewFlagSet("", flag.ContinueOnError)
92 flags.SetOutput(stderr)
93 loader.SetupFlags(flags)
95 err = flags.Parse(args)
96 if err == flag.ErrHelp {
99 } else if err != nil {
103 if len(flags.Args()) != 0 {
108 // Load the config twice -- once without loading deprecated
109 // keys/files, once with -- and then compare the two resulting
110 // configs. This reveals whether the deprecated keys/files
111 // have any effect on the final configuration.
113 // If they do, show the operator how to update their config
114 // such that the deprecated keys/files are superfluous and can
116 loader.SkipDeprecated = true
117 loader.SkipLegacy = true
118 withoutDepr, err := loader.Load()
122 loader.SkipDeprecated = false
123 loader.SkipLegacy = false
124 withDepr, err := loader.Load()
129 if warnAboutProblems(logger, withDepr) {
132 cmd := exec.Command("diff", "-u", "--label", "without-deprecated-configs", "--label", "relying-on-deprecated-configs", "/dev/fd/3", "/dev/fd/4")
133 for _, obj := range []interface{}{withoutDepr, withDepr} {
134 y, _ := yaml.Marshal(obj)
135 pr, pw, err := os.Pipe()
141 io.Copy(pw, bytes.NewBuffer(y))
144 cmd.ExtraFiles = append(cmd.ExtraFiles, pr)
146 diff, err := cmd.CombinedOutput()
147 if bytes.HasPrefix(diff, []byte("--- ")) {
148 fmt.Fprintln(stdout, "Your configuration is relying on deprecated entries. Suggest making the following changes.")
152 } else if len(diff) > 0 {
153 fmt.Fprintf(stderr, "Unexpected diff output:\n%s", diff)
155 } else if err != nil {
158 if logbuf.Len() > 0 {
169 func warnAboutProblems(logger logrus.FieldLogger, cfg *arvados.Config) bool {
171 for id, cc := range cfg.Clusters {
172 if cc.SystemRootToken == "" {
173 logger.Warnf("Clusters.%s.SystemRootToken is empty; see https://doc.arvados.org/master/install/install-keepstore.html", id)
176 if cc.ManagementToken == "" {
177 logger.Warnf("Clusters.%s.ManagementToken is empty; see https://doc.arvados.org/admin/management-token.html", id)
184 var DumpDefaultsCommand defaultsCommand
186 type defaultsCommand struct{}
188 func (defaultsCommand) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
189 _, err := stdout.Write(DefaultYAML)
191 fmt.Fprintln(stderr, err)