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 "github.com/coreos/go-systemd/daemon"
19 defaultConfigPath = "/etc/arvados/keep-web/keep-web.yml"
22 // Config specifies server configuration.
28 AnonymousTokens []string
29 AttachmentOnlyHost string
34 // Hack to support old command line flag, which is a bool
35 // meaning "get actual token from environment".
36 deprecatedAllowAnonymous bool
38 //Authorization token to be included in all health check requests.
39 ManagementToken string
42 // DefaultConfig returns the default configuration.
43 func DefaultConfig() *Config {
47 TTL: arvados.Duration(5 * time.Minute),
48 UUIDTTL: arvados.Duration(5 * time.Second),
49 MaxCollectionEntries: 1000,
50 MaxCollectionBytes: 100000000,
51 MaxPermissionEntries: 1000,
58 // MakeArvadosClient returns an error if this env var isn't
59 // available as a default token (even if we explicitly set a
60 // different token before doing anything with the client). We
61 // set this dummy value during init so it doesn't clobber the
62 // one used by "run test servers".
63 if os.Getenv("ARVADOS_API_TOKEN") == "" {
64 os.Setenv("ARVADOS_API_TOKEN", "xxx")
69 cfg := DefaultConfig()
72 deprecated := " (DEPRECATED -- use config file instead)"
73 flag.StringVar(&configPath, "config", defaultConfigPath,
74 "`path` to JSON or YAML configuration file")
75 flag.StringVar(&cfg.Listen, "listen", "",
76 "address:port or :port to listen on"+deprecated)
77 flag.BoolVar(&cfg.deprecatedAllowAnonymous, "allow-anonymous", false,
78 "Load an anonymous token from the ARVADOS_API_TOKEN environment variable"+deprecated)
79 flag.StringVar(&cfg.AttachmentOnlyHost, "attachment-only-host", "",
80 "Only serve attachments at the given `host:port`"+deprecated)
81 flag.BoolVar(&cfg.TrustAllContent, "trust-all-content", false,
82 "Serve non-public content from a single origin. Dangerous: read docs before using!"+deprecated)
83 flag.StringVar(&cfg.ManagementToken, "management-token", "",
84 "Authorization token to be included in all health check requests.")
86 dumpConfig := flag.Bool("dump-config", false,
87 "write current configuration to stdout and exit")
91 if err := config.LoadFile(cfg, configPath); err != nil {
92 if h := os.Getenv("ARVADOS_API_HOST"); h != "" && configPath == defaultConfigPath {
93 log.Printf("DEPRECATED: Using ARVADOS_API_HOST environment variable. Use config file instead.")
94 cfg.Client.APIHost = h
99 if cfg.deprecatedAllowAnonymous {
100 log.Printf("DEPRECATED: Using -allow-anonymous command line flag with ARVADOS_API_TOKEN environment variable. Use config file instead.")
101 cfg.AnonymousTokens = []string{os.Getenv("ARVADOS_API_TOKEN")}
105 log.Fatal(config.DumpAndExit(cfg))
108 os.Setenv("ARVADOS_API_HOST", cfg.Client.APIHost)
109 srv := &server{Config: cfg}
110 if err := srv.Start(); err != nil {
113 if _, err := daemon.SdNotify(false, "READY=1"); err != nil {
114 log.Printf("Error notifying init daemon: %v", err)
116 log.Println("Listening at", srv.Addr)
117 if err := srv.Wait(); err != nil {