forked from TrueCloudLab/certificates
Use server BaseContext
Instead of using the authority middleware this change adds the authority in the base context of the server.
This commit is contained in:
parent
817af3d696
commit
d5070ecf31
1 changed files with 15 additions and 2 deletions
17
ca/ca.go
17
ca/ca.go
|
@ -1,10 +1,12 @@
|
||||||
package ca
|
package ca
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
@ -279,10 +281,12 @@ func (ca *CA) Init(cfg *config.Config) (*CA, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add authority handler
|
// Add authority handler
|
||||||
handler = auth.Middleware(handler)
|
baseContext := buildContext(auth)
|
||||||
insecureHandler = auth.Middleware(insecureHandler)
|
|
||||||
|
|
||||||
ca.srv = server.New(cfg.Address, handler, tlsConfig)
|
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
|
// only start the insecure server if the insecure address is configured
|
||||||
// and, currently, also only when it should serve SCEP endpoints.
|
// 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
|
// will probably introduce more complexity in terms of graceful
|
||||||
// reload.
|
// reload.
|
||||||
ca.insecureSrv = server.New(cfg.InsecureAddress, insecureHandler, nil)
|
ca.insecureSrv = server.New(cfg.InsecureAddress, insecureHandler, nil)
|
||||||
|
ca.insecureSrv.BaseContext = func(net.Listener) context.Context {
|
||||||
|
return baseContext
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ca, nil
|
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.
|
// Run starts the CA calling to the server ListenAndServe method.
|
||||||
func (ca *CA) Run() error {
|
func (ca *CA) Run() error {
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
|
|
Loading…
Add table
Reference in a new issue