1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
13 "git.curoverse.com/arvados.git/sdk/go/arvados"
14 "git.curoverse.com/arvados.git/sdk/go/config"
15 log "github.com/Sirupsen/logrus"
16 "github.com/coreos/go-systemd/daemon"
20 defaultConfigPath = "/etc/arvados/keep-web/keep-web.yml"
24 // Config specifies server configuration.
30 AnonymousTokens []string
31 AttachmentOnlyHost string
36 // Hack to support old command line flag, which is a bool
37 // meaning "get actual token from environment".
38 deprecatedAllowAnonymous bool
40 //Authorization token to be included in all health check requests.
41 ManagementToken string
44 // DefaultConfig returns the default configuration.
45 func DefaultConfig() *Config {
49 TTL: arvados.Duration(5 * time.Minute),
50 UUIDTTL: arvados.Duration(5 * time.Second),
51 MaxCollectionEntries: 1000,
52 MaxCollectionBytes: 100000000,
53 MaxPermissionEntries: 1000,
60 // MakeArvadosClient returns an error if this env var isn't
61 // available as a default token (even if we explicitly set a
62 // different token before doing anything with the client). We
63 // set this dummy value during init so it doesn't clobber the
64 // one used by "run test servers".
65 if os.Getenv("ARVADOS_API_TOKEN") == "" {
66 os.Setenv("ARVADOS_API_TOKEN", "xxx")
69 log.SetFormatter(&log.JSONFormatter{
70 TimestampFormat: "2006-01-02T15:04:05.000000000Z07:00",
75 cfg := DefaultConfig()
78 deprecated := " (DEPRECATED -- use config file instead)"
79 flag.StringVar(&configPath, "config", defaultConfigPath,
80 "`path` to JSON or YAML configuration file")
81 flag.StringVar(&cfg.Listen, "listen", "",
82 "address:port or :port to listen on"+deprecated)
83 flag.BoolVar(&cfg.deprecatedAllowAnonymous, "allow-anonymous", false,
84 "Load an anonymous token from the ARVADOS_API_TOKEN environment variable"+deprecated)
85 flag.StringVar(&cfg.AttachmentOnlyHost, "attachment-only-host", "",
86 "Only serve attachments at the given `host:port`"+deprecated)
87 flag.BoolVar(&cfg.TrustAllContent, "trust-all-content", false,
88 "Serve non-public content from a single origin. Dangerous: read docs before using!"+deprecated)
89 flag.StringVar(&cfg.ManagementToken, "management-token", "",
90 "Authorization token to be included in all health check requests.")
92 dumpConfig := flag.Bool("dump-config", false,
93 "write current configuration to stdout and exit")
94 getVersion := flag.Bool("version", false,
95 "print version information and exit.")
99 // Print version information if requested
101 fmt.Printf("keep-web %s\n", version)
105 if err := config.LoadFile(cfg, configPath); err != nil {
106 if h := os.Getenv("ARVADOS_API_HOST"); h != "" && configPath == defaultConfigPath {
107 log.Printf("DEPRECATED: Using ARVADOS_API_HOST environment variable. Use config file instead.")
108 cfg.Client.APIHost = h
113 if cfg.deprecatedAllowAnonymous {
114 log.Printf("DEPRECATED: Using -allow-anonymous command line flag with ARVADOS_API_TOKEN environment variable. Use config file instead.")
115 cfg.AnonymousTokens = []string{os.Getenv("ARVADOS_API_TOKEN")}
119 log.Fatal(config.DumpAndExit(cfg))
122 log.Printf("keep-web %s started", version)
124 os.Setenv("ARVADOS_API_HOST", cfg.Client.APIHost)
125 srv := &server{Config: cfg}
126 if err := srv.Start(); err != nil {
129 if _, err := daemon.SdNotify(false, "READY=1"); err != nil {
130 log.Printf("Error notifying init daemon: %v", err)
132 log.Println("Listening at", srv.Addr)
133 if err := srv.Wait(); err != nil {