From d5070ecf31b5c1c268a8e9f0243d6f240c6e3738 Mon Sep 17 00:00:00 2001 From: Mariano Cano Date: Wed, 27 Apr 2022 11:06:55 -0700 Subject: [PATCH] Use server BaseContext Instead of using the authority middleware this change adds the authority in the base context of the server. --- ca/ca.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/ca/ca.go b/ca/ca.go index 24da6311..795fa77a 100644 --- a/ca/ca.go +++ b/ca/ca.go @@ -1,10 +1,12 @@ package ca import ( + "context" "crypto/tls" "crypto/x509" "fmt" "log" + "net" "net/http" "net/url" "reflect" @@ -279,10 +281,12 @@ func (ca *CA) Init(cfg *config.Config) (*CA, error) { } // Add authority handler - handler = auth.Middleware(handler) - insecureHandler = auth.Middleware(insecureHandler) + baseContext := buildContext(auth) ca.srv = server.New(cfg.Address, handler, tlsConfig) + ca.srv.BaseContext = func(net.Listener) context.Context { + return baseContext + } // only start the insecure server if the insecure address is configured // and, currently, also only when it should serve SCEP endpoints. @@ -292,11 +296,20 @@ func (ca *CA) Init(cfg *config.Config) (*CA, error) { // will probably introduce more complexity in terms of graceful // reload. ca.insecureSrv = server.New(cfg.InsecureAddress, insecureHandler, nil) + ca.insecureSrv.BaseContext = func(net.Listener) context.Context { + return baseContext + } } return ca, nil } +func buildContext(a *authority.Authority) context.Context { + ctx := authority.NewContext(context.Background(), a) + + return ctx +} + // Run starts the CA calling to the server ListenAndServe method. func (ca *CA) Run() error { var wg sync.WaitGroup