var Command cmd.Handler = service.Command(arvados.ServiceNameController, newHandler)
-func newHandler(_ context.Context, cluster *arvados.Cluster, np *arvados.NodeProfile) service.Handler {
+func newHandler(_ context.Context, cluster *arvados.Cluster, np *arvados.NodeProfile, _ string) service.Handler {
return &Handler{Cluster: cluster, NodeProfile: np}
}
},
}
node := s.cluster.NodeProfiles["*"]
- s.handler = newHandler(s.ctx, s.cluster, &node)
+ s.handler = newHandler(s.ctx, s.cluster, &node, "")
}
func (s *HandlerSuite) TearDownTest(c *check.C) {
"Keep-Alive": true,
"Proxy-Authenticate": true,
"Proxy-Authorization": true,
+ // this line makes gofmt 1.10 and 1.11 agree
"TE": true,
"Trailer": true,
"Transfer-Encoding": true, // *-Encoding headers interfer with Go's automatic compression/decompression
var Command cmd.Handler = service.Command(arvados.ServiceNameDispatchCloud, newHandler)
-func newHandler(ctx context.Context, cluster *arvados.Cluster, _ *arvados.NodeProfile) service.Handler {
+func newHandler(ctx context.Context, cluster *arvados.Cluster, _ *arvados.NodeProfile, token string) service.Handler {
d := &dispatcher{
Cluster: cluster,
Context: ctx,
- AuthToken: service.Token(ctx),
+ AuthToken: token,
}
go d.Start()
return d
CheckHealth() error
}
-type NewHandlerFunc func(context.Context, *arvados.Cluster, *arvados.NodeProfile) Handler
+type NewHandlerFunc func(_ context.Context, _ *arvados.Cluster, _ *arvados.NodeProfile, token string) Handler
type command struct {
newHandler NewHandlerFunc
})
ctx := ctxlog.Context(context.Background(), log)
- // Currently all components use SystemRootToken if configured,
- // otherwise ARVADOS_API_TOKEN. In future, per-process tokens
- // will be generated/obtained here.
- token := cluster.SystemRootToken
- if token == "" {
- log.Warn("SystemRootToken missing from cluster config, falling back to ARVADOS_API_TOKEN environment variable")
- token = os.Getenv("ARVADOS_API_TOKEN")
- }
- ctx = tokenContext(ctx, token)
-
profileName := *nodeProfile
if profileName == "" {
profileName = os.Getenv("ARVADOS_NODE_PROFILE")
err = fmt.Errorf("configuration does not enable the %s service on this host", c.svcName)
return 1
}
- handler := c.newHandler(ctx, cluster, profile)
+
+ // Currently all components use SystemRootToken if configured,
+ // otherwise ARVADOS_API_TOKEN. In future, per-process tokens
+ // will be generated/obtained here.
+ token := cluster.SystemRootToken
+ if token == "" {
+ log.Warn("SystemRootToken missing from cluster config, falling back to ARVADOS_API_TOKEN environment variable")
+ token = os.Getenv("ARVADOS_API_TOKEN")
+ }
+
+ handler := c.newHandler(ctx, cluster, profile, token)
if err = handler.CheckHealth(); err != nil {
return 1
}
+++ /dev/null
-// Copyright (C) The Arvados Authors. All rights reserved.
-//
-// SPDX-License-Identifier: Apache-2.0
-
-package service
-
-import (
- "context"
-)
-
-type contextKey string
-
-var contextKeyServiceToken contextKey = "serviceToken"
-
-// Token returns the privileged system token suitable for the given
-// service context.
-//
-// It only works on contexts that were generated by Command() and
-// passed to a Handler. For other contexts it returns the empty
-// string.
-func Token(ctx context.Context) string {
- t, _ := ctx.Value(contextKeyServiceToken).(string)
- return t
-}
-
-// tokenContext returns a child context with the given token attached
-// so it can be retrieved by Token().
-func tokenContext(ctx context.Context, t string) context.Context {
- return context.WithValue(ctx, contextKeyServiceToken, t)
-}