17106: Improve handling of bare tokens issued by remote clusters.
[arvados.git] / services / keep-web / server.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package main
6
7 import (
8         "context"
9         "net/http"
10
11         "git.arvados.org/arvados.git/sdk/go/arvados"
12         "git.arvados.org/arvados.git/sdk/go/ctxlog"
13         "git.arvados.org/arvados.git/sdk/go/httpserver"
14         "github.com/prometheus/client_golang/prometheus"
15         "github.com/sirupsen/logrus"
16 )
17
18 type server struct {
19         httpserver.Server
20         Config *Config
21 }
22
23 func (srv *server) Start(logger *logrus.Logger) error {
24         h := &handler{Config: srv.Config}
25         reg := prometheus.NewRegistry()
26         h.Config.Cache.registry = reg
27         ctx := ctxlog.Context(context.Background(), logger)
28         mh := httpserver.Instrument(reg, logger, httpserver.HandlerWithContext(ctx, httpserver.AddRequestIDs(httpserver.LogRequests(h))))
29         h.MetricsAPI = mh.ServeAPI(h.Config.cluster.ManagementToken, http.NotFoundHandler())
30         srv.Handler = mh
31         var listen arvados.URL
32         for listen = range srv.Config.cluster.Services.WebDAV.InternalURLs {
33                 break
34         }
35         if len(srv.Config.cluster.Services.WebDAV.InternalURLs) > 1 {
36                 logrus.Warn("Services.WebDAV.InternalURLs has more than one key; picked: ", listen)
37         }
38         srv.Addr = listen.Host
39         return srv.Server.Start()
40 }