Merge branch '3115-keep-disk-create-surprise'
[arvados.git] / services / keepproxy / keepproxy.go
index 24df531fa4ab434fea7652503db1d44f1ba04a9b..76a8a1551fb867f5258221f1f22692656039d97a 100644 (file)
@@ -1,7 +1,6 @@
 package main
 
 import (
-       "encoding/json"
        "errors"
        "flag"
        "fmt"
@@ -22,6 +21,7 @@ import (
        "git.curoverse.com/arvados.git/sdk/go/config"
        "git.curoverse.com/arvados.git/sdk/go/keepclient"
        "github.com/coreos/go-systemd/daemon"
+       "github.com/ghodss/yaml"
        "github.com/gorilla/mux"
 )
 
@@ -62,6 +62,7 @@ func main() {
        var cfgPath string
        const defaultCfgPath = "/etc/arvados/keepproxy/keepproxy.yml"
        flagset.StringVar(&cfgPath, "config", defaultCfgPath, "Configuration file `path`")
+       dumpConfig := flagset.Bool("dump-config", false, "write current configuration to stdout and exit")
        flagset.Parse(os.Args[1:])
 
        err := config.LoadFile(cfg, cfgPath)
@@ -77,12 +78,16 @@ func main() {
                if regexp.MustCompile("^(?i:1|yes|true)$").MatchString(os.Getenv("ARVADOS_API_HOST_INSECURE")) {
                        cfg.Client.Insecure = true
                }
-               if j, err := json.MarshalIndent(cfg, "", "    "); err == nil {
-                       log.Print("Current configuration:\n", string(j))
+               if y, err := yaml.Marshal(cfg); err == nil && !*dumpConfig {
+                       log.Print("Current configuration:\n", string(y))
                }
                cfg.Timeout = arvados.Duration(time.Duration(*timeoutSeconds) * time.Second)
        }
 
+       if *dumpConfig {
+               log.Fatal(config.DumpAndExit(cfg))
+       }
+
        arv, err := arvadosclient.New(&cfg.Client)
        if err != nil {
                log.Fatalf("Error setting up arvados client %s", err.Error())