[ARVADOS] created: 1.3.0-1081-g49ca4b9e9
Git user
git at public.curoverse.com
Wed Jun 12 20:27:55 UTC 2019
at 49ca4b9e9d96d35f704216bda401cc20cd972ca8 (commit)
commit 49ca4b9e9d96d35f704216bda401cc20cd972ca8
Author: Tom Clegg <tclegg at veritasgenetics.com>
Date: Wed Jun 12 16:27:07 2019 -0400
15003: Load config from default location or -config arg, not stdin.
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg at veritasgenetics.com>
diff --git a/lib/config/cmd.go b/lib/config/cmd.go
index 41a1d7d21..858bfc2b2 100644
--- a/lib/config/cmd.go
+++ b/lib/config/cmd.go
@@ -6,6 +6,7 @@ package config
import (
"bytes"
+ "flag"
"fmt"
"io"
"io/ioutil"
@@ -13,6 +14,7 @@ import (
"os/exec"
"git.curoverse.com/arvados.git/lib/cmd"
+ "git.curoverse.com/arvados.git/sdk/go/arvados"
"git.curoverse.com/arvados.git/sdk/go/ctxlog"
"github.com/ghodss/yaml"
)
@@ -28,12 +30,24 @@ func (dumpCommand) RunCommand(prog string, args []string, stdin io.Reader, stdou
fmt.Fprintf(stderr, "%s\n", err)
}
}()
- if len(args) != 0 {
- err = fmt.Errorf("usage: %s <config-src.yaml >config-min.yaml", prog)
+
+ flags := flag.NewFlagSet("", flag.ContinueOnError)
+ flags.SetOutput(stderr)
+ configFile := flags.String("config", arvados.DefaultConfigFile, "Site configuration `file`")
+ err = flags.Parse(args)
+ if err == flag.ErrHelp {
+ err = nil
+ return 0
+ } else if err != nil {
+ return 2
+ }
+
+ if len(flags.Args()) != 0 {
+ flags.Usage()
return 2
}
log := ctxlog.New(stderr, "text", "info")
- cfg, err := Load(stdin, log)
+ cfg, err := loadFileOrStdin(*configFile, stdin, log)
if err != nil {
return 1
}
@@ -59,12 +73,29 @@ func (checkCommand) RunCommand(prog string, args []string, stdin io.Reader, stdo
fmt.Fprintf(stderr, "%s\n", err)
}
}()
- if len(args) != 0 {
- err = fmt.Errorf("usage: %s <config-src.yaml && echo 'no changes needed'", prog)
+
+ flags := flag.NewFlagSet("", flag.ContinueOnError)
+ flags.SetOutput(stderr)
+ configFile := flags.String("config", arvados.DefaultConfigFile, "Site configuration `file`")
+ err = flags.Parse(args)
+ if err == flag.ErrHelp {
+ err = nil
+ return 0
+ } else if err != nil {
+ return 2
+ }
+
+ if len(flags.Args()) != 0 {
+ flags.Usage()
return 2
}
log := &plainLogger{w: stderr}
- buf, err := ioutil.ReadAll(stdin)
+ var buf []byte
+ if *configFile == "-" {
+ buf, err = ioutil.ReadAll(stdin)
+ } else {
+ buf, err = ioutil.ReadFile(*configFile)
+ }
if err != nil {
return 1
}
diff --git a/lib/config/cmd_test.go b/lib/config/cmd_test.go
index e4d838f85..d77003b47 100644
--- a/lib/config/cmd_test.go
+++ b/lib/config/cmd_test.go
@@ -18,12 +18,12 @@ func (s *CommandSuite) TestBadArg(c *check.C) {
var stderr bytes.Buffer
code := DumpCommand.RunCommand("arvados config-dump", []string{"-badarg"}, bytes.NewBuffer(nil), bytes.NewBuffer(nil), &stderr)
c.Check(code, check.Equals, 2)
- c.Check(stderr.String(), check.Matches, `(?ms)usage: .*`)
+ c.Check(stderr.String(), check.Matches, `(?ms)flag provided but not defined: -badarg\nUsage:\n.*`)
}
func (s *CommandSuite) TestEmptyInput(c *check.C) {
var stdout, stderr bytes.Buffer
- code := DumpCommand.RunCommand("arvados config-dump", nil, &bytes.Buffer{}, &stdout, &stderr)
+ code := DumpCommand.RunCommand("arvados config-dump", []string{"-config", "-"}, &bytes.Buffer{}, &stdout, &stderr)
c.Check(code, check.Equals, 1)
c.Check(stderr.String(), check.Matches, `config does not define any clusters\n`)
}
@@ -36,7 +36,7 @@ Clusters:
API:
MaxItemsPerResponse: 1234
`
- code := CheckCommand.RunCommand("arvados config-check", nil, bytes.NewBufferString(in), &stdout, &stderr)
+ code := CheckCommand.RunCommand("arvados config-check", []string{"-config", "-"}, bytes.NewBufferString(in), &stdout, &stderr)
c.Check(code, check.Equals, 0)
c.Check(stdout.String(), check.Equals, "")
c.Check(stderr.String(), check.Equals, "")
@@ -50,7 +50,7 @@ Clusters:
RequestLimits:
MaxItemsPerResponse: 1234
`
- code := CheckCommand.RunCommand("arvados config-check", nil, bytes.NewBufferString(in), &stdout, &stderr)
+ code := CheckCommand.RunCommand("arvados config-check", []string{"-config", "-"}, bytes.NewBufferString(in), &stdout, &stderr)
c.Check(code, check.Equals, 1)
c.Check(stdout.String(), check.Matches, `(?ms).*API:\n\- +.*MaxItemsPerResponse: 1000\n\+ +MaxItemsPerResponse: 1234\n.*`)
}
@@ -70,7 +70,7 @@ Clusters:
ConnectionPool:
{Bogus5: true}
`
- code := CheckCommand.RunCommand("arvados config-check", nil, bytes.NewBufferString(in), &stdout, &stderr)
+ code := CheckCommand.RunCommand("arvados config-check", []string{"-config", "-"}, bytes.NewBufferString(in), &stdout, &stderr)
c.Log(stderr.String())
c.Check(code, check.Equals, 1)
c.Check(stderr.String(), check.Matches, `(?ms).*deprecated or unknown config entry: Clusters.z1234.Bogus1\n.*`)
@@ -92,7 +92,7 @@ Clusters:
InternalURLs:
http://localhost:12345: {}
`
- code := DumpCommand.RunCommand("arvados config-dump", nil, bytes.NewBufferString(in), &stdout, &stderr)
+ code := DumpCommand.RunCommand("arvados config-dump", []string{"-config", "-"}, bytes.NewBufferString(in), &stdout, &stderr)
c.Check(code, check.Equals, 0)
c.Check(stdout.String(), check.Matches, `(?ms).*TimeoutBooting: 10m\n.*`)
c.Check(stdout.String(), check.Matches, `(?ms).*http://localhost:12345: {}\n.*`)
@@ -106,7 +106,7 @@ Clusters:
UnknownKey: foobar
ManagementToken: secret
`
- code := DumpCommand.RunCommand("arvados config-dump", nil, bytes.NewBufferString(in), &stdout, &stderr)
+ code := DumpCommand.RunCommand("arvados config-dump", []string{"-config", "-"}, bytes.NewBufferString(in), &stdout, &stderr)
c.Check(code, check.Equals, 0)
c.Check(stderr.String(), check.Matches, `(?ms).*deprecated or unknown config entry: Clusters.z1234.UnknownKey.*`)
c.Check(stdout.String(), check.Matches, `(?ms)Clusters:\n z1234:\n.*`)
diff --git a/lib/config/load.go b/lib/config/load.go
index 3ed2b9928..a0c769537 100644
--- a/lib/config/load.go
+++ b/lib/config/load.go
@@ -23,6 +23,14 @@ type logger interface {
Warnf(string, ...interface{})
}
+func loadFileOrStdin(path string, stdin io.Reader, log logger) (*arvados.Config, error) {
+ if path == "-" {
+ return load(stdin, log, true)
+ } else {
+ return LoadFile(path, log)
+ }
+}
+
func LoadFile(path string, log logger) (*arvados.Config, error) {
f, err := os.Open(path)
if err != nil {
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list