add readiness and partial key rotation

This commit is contained in:
Livio Amstutz 2020-02-11 17:17:09 +01:00
parent f0d17fd839
commit 93709a18b6
15 changed files with 254 additions and 132 deletions

View file

@ -10,8 +10,14 @@ import (
"github.com/caos/oidc/pkg/oidc"
)
const (
healthzEndpoint = "/healthz"
readinessEndpoint = "/ready"
)
type OpenIDProvider interface {
Configuration
HandleReady(w http.ResponseWriter, r *http.Request)
HandleDiscovery(w http.ResponseWriter, r *http.Request)
HandleAuthorize(w http.ResponseWriter, r *http.Request)
HandleAuthorizeCallback(w http.ResponseWriter, r *http.Request)
@ -23,19 +29,19 @@ type OpenIDProvider interface {
type HttpInterceptor func(http.HandlerFunc) http.HandlerFunc
var (
DefaultInterceptor = func(h http.HandlerFunc) http.HandlerFunc {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
h(w, r)
})
}
)
var DefaultInterceptor = func(h http.HandlerFunc) http.HandlerFunc {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
h(w, r)
})
}
func CreateRouter(o OpenIDProvider, h HttpInterceptor) *mux.Router {
if h == nil {
h = DefaultInterceptor
}
router := mux.NewRouter()
router.HandleFunc(healthzEndpoint, Healthz)
router.HandleFunc(readinessEndpoint, o.HandleReady)
router.HandleFunc(oidc.DiscoveryEndpoint, o.HandleDiscovery)
router.HandleFunc(o.AuthorizationEndpoint().Relative(), h(o.HandleAuthorize))
router.HandleFunc(o.AuthorizationEndpoint().Relative()+"/{id}", h(o.HandleAuthorizeCallback))