1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
14 "git.curoverse.com/arvados.git/sdk/go/arvados"
15 "git.curoverse.com/arvados.git/sdk/go/config"
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")
71 cfg := DefaultConfig()
74 deprecated := " (DEPRECATED -- use config file instead)"
75 flag.StringVar(&configPath, "config", defaultConfigPath,
76 "`path` to JSON or YAML configuration file")
77 flag.StringVar(&cfg.Listen, "listen", "",
78 "address:port or :port to listen on"+deprecated)
79 flag.BoolVar(&cfg.deprecatedAllowAnonymous, "allow-anonymous", false,
80 "Load an anonymous token from the ARVADOS_API_TOKEN environment variable"+deprecated)
81 flag.StringVar(&cfg.AttachmentOnlyHost, "attachment-only-host", "",
82 "Only serve attachments at the given `host:port`"+deprecated)
83 flag.BoolVar(&cfg.TrustAllContent, "trust-all-content", false,
84 "Serve non-public content from a single origin. Dangerous: read docs before using!"+deprecated)
85 flag.StringVar(&cfg.ManagementToken, "management-token", "",
86 "Authorization token to be included in all health check requests.")
88 dumpConfig := flag.Bool("dump-config", false,
89 "write current configuration to stdout and exit")
90 getVersion := flag.Bool("version", false,
91 "print version information and exit.")
95 // Print version information if requested
97 fmt.Printf("keep-web %s\n", version)
101 if err := config.LoadFile(cfg, configPath); err != nil {
102 if h := os.Getenv("ARVADOS_API_HOST"); h != "" && configPath == defaultConfigPath {
103 log.Printf("DEPRECATED: Using ARVADOS_API_HOST environment variable. Use config file instead.")
104 cfg.Client.APIHost = h
109 if cfg.deprecatedAllowAnonymous {
110 log.Printf("DEPRECATED: Using -allow-anonymous command line flag with ARVADOS_API_TOKEN environment variable. Use config file instead.")
111 cfg.AnonymousTokens = []string{os.Getenv("ARVADOS_API_TOKEN")}
115 log.Fatal(config.DumpAndExit(cfg))
118 log.Printf("keep-web %s started", version)
120 os.Setenv("ARVADOS_API_HOST", cfg.Client.APIHost)
121 srv := &server{Config: cfg}
122 if err := srv.Start(); err != nil {
125 if _, err := daemon.SdNotify(false, "READY=1"); err != nil {
126 log.Printf("Error notifying init daemon: %v", err)
128 log.Println("Listening at", srv.Addr)
129 if err := srv.Wait(); err != nil {