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 MaxCollectionEntries: 1000,
49 MaxCollectionBytes: 100000000,
50 MaxPermissionEntries: 1000,
57 // MakeArvadosClient returns an error if this env var isn't
58 // available as a default token (even if we explicitly set a
59 // different token before doing anything with the client). We
60 // set this dummy value during init so it doesn't clobber the
61 // one used by "run test servers".
62 if os.Getenv("ARVADOS_API_TOKEN") == "" {
63 os.Setenv("ARVADOS_API_TOKEN", "xxx")
68 cfg := DefaultConfig()
71 deprecated := " (DEPRECATED -- use config file instead)"
72 flag.StringVar(&configPath, "config", defaultConfigPath,
73 "`path` to JSON or YAML configuration file")
74 flag.StringVar(&cfg.Listen, "listen", "",
75 "address:port or :port to listen on"+deprecated)
76 flag.BoolVar(&cfg.deprecatedAllowAnonymous, "allow-anonymous", false,
77 "Load an anonymous token from the ARVADOS_API_TOKEN environment variable"+deprecated)
78 flag.StringVar(&cfg.AttachmentOnlyHost, "attachment-only-host", "",
79 "Only serve attachments at the given `host:port`"+deprecated)
80 flag.BoolVar(&cfg.TrustAllContent, "trust-all-content", false,
81 "Serve non-public content from a single origin. Dangerous: read docs before using!"+deprecated)
82 flag.StringVar(&cfg.ManagementToken, "management-token", "",
83 "Authorization token to be included in all health check requests.")
85 dumpConfig := flag.Bool("dump-config", false,
86 "write current configuration to stdout and exit")
90 if err := config.LoadFile(cfg, configPath); err != nil {
91 if h := os.Getenv("ARVADOS_API_HOST"); h != "" && configPath == defaultConfigPath {
92 log.Printf("DEPRECATED: Using ARVADOS_API_HOST environment variable. Use config file instead.")
93 cfg.Client.APIHost = h
98 if cfg.deprecatedAllowAnonymous {
99 log.Printf("DEPRECATED: Using -allow-anonymous command line flag with ARVADOS_API_TOKEN environment variable. Use config file instead.")
100 cfg.AnonymousTokens = []string{os.Getenv("ARVADOS_API_TOKEN")}
104 log.Fatal(config.DumpAndExit(cfg))
107 os.Setenv("ARVADOS_API_HOST", cfg.Client.APIHost)
108 srv := &server{Config: cfg}
109 if err := srv.Start(); err != nil {
112 if _, err := daemon.SdNotify(false, "READY=1"); err != nil {
113 log.Printf("Error notifying init daemon: %v", err)
115 log.Println("Listening at", srv.Addr)
116 if err := srv.Wait(); err != nil {