8 "git.curoverse.com/arvados.git/sdk/go/arvados"
9 "git.curoverse.com/arvados.git/sdk/go/config"
10 "github.com/coreos/go-systemd/daemon"
14 defaultConfigPath = "/etc/arvados/keep-web/keep-web.yml"
17 // Config specifies server configuration.
23 AnonymousTokens []string
24 AttachmentOnlyHost string
27 // Hack to support old command line flag, which is a bool
28 // meaning "get actual token from environment".
29 deprecatedAllowAnonymous bool
32 // DefaultConfig returns the default configuration.
33 func DefaultConfig() *Config {
40 // MakeArvadosClient returns an error if this env var isn't
41 // available as a default token (even if we explicitly set a
42 // different token before doing anything with the client). We
43 // set this dummy value during init so it doesn't clobber the
44 // one used by "run test servers".
45 if os.Getenv("ARVADOS_API_TOKEN") == "" {
46 os.Setenv("ARVADOS_API_TOKEN", "xxx")
51 cfg := DefaultConfig()
54 deprecated := " (DEPRECATED -- use config file instead)"
55 flag.StringVar(&configPath, "config", defaultConfigPath,
56 "`path` to JSON or YAML configuration file")
57 flag.StringVar(&cfg.Listen, "listen", "",
58 "address:port or :port to listen on"+deprecated)
59 flag.BoolVar(&cfg.deprecatedAllowAnonymous, "allow-anonymous", false,
60 "Load an anonymous token from the ARVADOS_API_TOKEN environment variable"+deprecated)
61 flag.StringVar(&cfg.AttachmentOnlyHost, "attachment-only-host", "",
62 "Only serve attachments at the given `host:port`"+deprecated)
63 flag.BoolVar(&cfg.TrustAllContent, "trust-all-content", false,
64 "Serve non-public content from a single origin. Dangerous: read docs before using!"+deprecated)
68 if err := config.LoadFile(cfg, configPath); err != nil {
69 if h := os.Getenv("ARVADOS_API_HOST"); h != "" && configPath == defaultConfigPath {
70 log.Printf("DEPRECATED: Using ARVADOS_API_HOST environment variable. Use config file instead.")
71 cfg.Client.APIHost = h
76 if cfg.deprecatedAllowAnonymous {
77 log.Printf("DEPRECATED: Using -allow-anonymous command line flag with ARVADOS_API_TOKEN environment variable. Use config file instead.")
78 cfg.AnonymousTokens = []string{os.Getenv("ARVADOS_API_TOKEN")}
81 os.Setenv("ARVADOS_API_HOST", cfg.Client.APIHost)
82 srv := &server{Config: cfg}
83 if err := srv.Start(); err != nil {
86 if _, err := daemon.SdNotify("READY=1"); err != nil {
87 log.Printf("Error notifying init daemon: %v", err)
89 log.Println("Listening at", srv.Addr)
90 if err := srv.Wait(); err != nil {