1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
13 "git.arvados.org/arvados.git/lib/cmd"
14 "git.arvados.org/arvados.git/lib/config"
15 "git.arvados.org/arvados.git/sdk/go/ctxlog"
18 // sudoCommand runs another command using API connection info and
19 // SystemRootToken from the system config file instead of the caller's
21 type sudoCommand struct{}
23 func (sudoCommand) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
24 ldr := config.NewLoader(stdin, ctxlog.New(stderr, "text", "info"))
25 flags := flag.NewFlagSet(prog, flag.ContinueOnError)
27 if ok, code := cmd.ParseFlags(flags, prog, args, "subcommand ...", stderr); !ok {
30 cfg, err := ldr.Load()
32 fmt.Fprintln(stderr, err)
35 cluster, err := cfg.GetCluster("")
37 fmt.Fprintln(stderr, err)
40 os.Setenv("ARVADOS_API_HOST", cluster.Services.Controller.ExternalURL.Host)
41 os.Setenv("ARVADOS_API_TOKEN", cluster.SystemRootToken)
42 if cluster.TLS.Insecure {
43 os.Setenv("ARVADOS_API_HOST_INSECURE", "1")
45 os.Unsetenv("ARVADOS_API_HOST_INSECURE")
47 return handler.RunCommand(prog, flags.Args(), stdin, stdout, stderr)