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
39 // DefaultConfig returns the default configuration.
40 func DefaultConfig() *Config {
44 TTL: arvados.Duration(5 * time.Minute),
45 MaxCollectionEntries: 1000,
46 MaxCollectionBytes: 100000000,
47 MaxPermissionEntries: 1000,
54 // MakeArvadosClient returns an error if this env var isn't
55 // available as a default token (even if we explicitly set a
56 // different token before doing anything with the client). We
57 // set this dummy value during init so it doesn't clobber the
58 // one used by "run test servers".
59 if os.Getenv("ARVADOS_API_TOKEN") == "" {
60 os.Setenv("ARVADOS_API_TOKEN", "xxx")
65 cfg := DefaultConfig()
68 deprecated := " (DEPRECATED -- use config file instead)"
69 flag.StringVar(&configPath, "config", defaultConfigPath,
70 "`path` to JSON or YAML configuration file")
71 flag.StringVar(&cfg.Listen, "listen", "",
72 "address:port or :port to listen on"+deprecated)
73 flag.BoolVar(&cfg.deprecatedAllowAnonymous, "allow-anonymous", false,
74 "Load an anonymous token from the ARVADOS_API_TOKEN environment variable"+deprecated)
75 flag.StringVar(&cfg.AttachmentOnlyHost, "attachment-only-host", "",
76 "Only serve attachments at the given `host:port`"+deprecated)
77 flag.BoolVar(&cfg.TrustAllContent, "trust-all-content", false,
78 "Serve non-public content from a single origin. Dangerous: read docs before using!"+deprecated)
79 dumpConfig := flag.Bool("dump-config", false,
80 "write current configuration to stdout and exit")
84 if err := config.LoadFile(cfg, configPath); err != nil {
85 if h := os.Getenv("ARVADOS_API_HOST"); h != "" && configPath == defaultConfigPath {
86 log.Printf("DEPRECATED: Using ARVADOS_API_HOST environment variable. Use config file instead.")
87 cfg.Client.APIHost = h
92 if cfg.deprecatedAllowAnonymous {
93 log.Printf("DEPRECATED: Using -allow-anonymous command line flag with ARVADOS_API_TOKEN environment variable. Use config file instead.")
94 cfg.AnonymousTokens = []string{os.Getenv("ARVADOS_API_TOKEN")}
98 log.Fatal(config.DumpAndExit(cfg))
101 os.Setenv("ARVADOS_API_HOST", cfg.Client.APIHost)
102 srv := &server{Config: cfg}
103 if err := srv.Start(); err != nil {
106 if _, err := daemon.SdNotify(false, "READY=1"); err != nil {
107 log.Printf("Error notifying init daemon: %v", err)
109 log.Println("Listening at", srv.Addr)
110 if err := srv.Wait(); err != nil {