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)
94 strict := flags.Bool("strict", true, "Strict validation of configuration file (warnings result in non-zero exit code)")
96 err = flags.Parse(args)
97 if err == flag.ErrHelp {
100 } else if err != nil {
104 if len(flags.Args()) != 0 {
109 // Load the config twice -- once without loading deprecated
110 // keys/files, once with -- and then compare the two resulting
111 // configs. This reveals whether the deprecated keys/files
112 // have any effect on the final configuration.
114 // If they do, show the operator how to update their config
115 // such that the deprecated keys/files are superfluous and can
117 loader.SkipDeprecated = true
118 loader.SkipLegacy = true
119 withoutDepr, err := loader.Load()
123 loader.SkipDeprecated = false
124 loader.SkipLegacy = false
125 withDepr, err := loader.Load()
130 if warnAboutProblems(logger, withDepr) {
133 cmd := exec.Command("diff", "-u", "--label", "without-deprecated-configs", "--label", "relying-on-deprecated-configs", "/dev/fd/3", "/dev/fd/4")
134 for _, obj := range []interface{}{withoutDepr, withDepr} {
135 y, _ := yaml.Marshal(obj)
136 pr, pw, err := os.Pipe()
142 io.Copy(pw, bytes.NewBuffer(y))
145 cmd.ExtraFiles = append(cmd.ExtraFiles, pr)
147 diff, err := cmd.CombinedOutput()
148 if bytes.HasPrefix(diff, []byte("--- ")) {
149 fmt.Fprintln(stdout, "Your configuration is relying on deprecated entries. Suggest making the following changes.")
155 } else if len(diff) > 0 {
156 fmt.Fprintf(stderr, "Unexpected diff output:\n%s", diff)
160 } else if err != nil {
163 if logbuf.Len() > 0 {
175 func warnAboutProblems(logger logrus.FieldLogger, cfg *arvados.Config) bool {
177 for id, cc := range cfg.Clusters {
178 if cc.SystemRootToken == "" {
179 logger.Warnf("Clusters.%s.SystemRootToken is empty; see https://doc.arvados.org/master/install/install-keepstore.html", id)
182 if cc.ManagementToken == "" {
183 logger.Warnf("Clusters.%s.ManagementToken is empty; see https://doc.arvados.org/admin/management-token.html", id)
190 var DumpDefaultsCommand defaultsCommand
192 type defaultsCommand struct{}
194 func (defaultsCommand) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
195 _, err := stdout.Write(DefaultYAML)
197 fmt.Fprintln(stderr, err)