9 "git.curoverse.com/arvados.git/sdk/go/arvados"
10 "git.curoverse.com/arvados.git/sdk/go/config"
11 "github.com/coreos/go-systemd/daemon"
15 defaultConfigPath = "/etc/arvados/keep-web/keep-web.yml"
18 // Config specifies server configuration.
24 AnonymousTokens []string
25 AttachmentOnlyHost string
30 // Hack to support old command line flag, which is a bool
31 // meaning "get actual token from environment".
32 deprecatedAllowAnonymous bool
35 // DefaultConfig returns the default configuration.
36 func DefaultConfig() *Config {
40 TTL: arvados.Duration(5 * time.Minute),
41 MaxCollectionEntries: 1000,
42 MaxCollectionBytes: 100000000,
43 MaxPermissionEntries: 1000,
50 // MakeArvadosClient returns an error if this env var isn't
51 // available as a default token (even if we explicitly set a
52 // different token before doing anything with the client). We
53 // set this dummy value during init so it doesn't clobber the
54 // one used by "run test servers".
55 if os.Getenv("ARVADOS_API_TOKEN") == "" {
56 os.Setenv("ARVADOS_API_TOKEN", "xxx")
61 cfg := DefaultConfig()
64 deprecated := " (DEPRECATED -- use config file instead)"
65 flag.StringVar(&configPath, "config", defaultConfigPath,
66 "`path` to JSON or YAML configuration file")
67 flag.StringVar(&cfg.Listen, "listen", "",
68 "address:port or :port to listen on"+deprecated)
69 flag.BoolVar(&cfg.deprecatedAllowAnonymous, "allow-anonymous", false,
70 "Load an anonymous token from the ARVADOS_API_TOKEN environment variable"+deprecated)
71 flag.StringVar(&cfg.AttachmentOnlyHost, "attachment-only-host", "",
72 "Only serve attachments at the given `host:port`"+deprecated)
73 flag.BoolVar(&cfg.TrustAllContent, "trust-all-content", false,
74 "Serve non-public content from a single origin. Dangerous: read docs before using!"+deprecated)
75 dumpConfig := flag.Bool("dump-config", false,
76 "write current configuration to stdout and exit")
80 if err := config.LoadFile(cfg, configPath); err != nil {
81 if h := os.Getenv("ARVADOS_API_HOST"); h != "" && configPath == defaultConfigPath {
82 log.Printf("DEPRECATED: Using ARVADOS_API_HOST environment variable. Use config file instead.")
83 cfg.Client.APIHost = h
88 if cfg.deprecatedAllowAnonymous {
89 log.Printf("DEPRECATED: Using -allow-anonymous command line flag with ARVADOS_API_TOKEN environment variable. Use config file instead.")
90 cfg.AnonymousTokens = []string{os.Getenv("ARVADOS_API_TOKEN")}
94 log.Fatal(config.DumpAndExit(cfg))
97 os.Setenv("ARVADOS_API_HOST", cfg.Client.APIHost)
98 srv := &server{Config: cfg}
99 if err := srv.Start(); err != nil {
102 if _, err := daemon.SdNotify(false, "READY=1"); err != nil {
103 log.Printf("Error notifying init daemon: %v", err)
105 log.Println("Listening at", srv.Addr)
106 if err := srv.Wait(); err != nil {