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

51
pkg/op/probes.go Normal file
View file

@ -0,0 +1,51 @@
package op
import (
"context"
"errors"
"net/http"
"github.com/caos/oidc/pkg/utils"
)
type ProbesFn func(context.Context) error
func Healthz(w http.ResponseWriter, r *http.Request) {
ok(w)
}
func Readiness(w http.ResponseWriter, r *http.Request, probes ...ProbesFn) {
ctx := r.Context()
for _, probe := range probes {
if err := probe(ctx); err != nil {
http.Error(w, "not ready", http.StatusInternalServerError)
return
}
}
ok(w)
}
func ReadySigner(s Signer) ProbesFn {
return func(ctx context.Context) error {
if s == nil {
return errors.New("no signer")
}
return s.Health(ctx)
}
}
func ReadyStorage(s Storage) ProbesFn {
return func(ctx context.Context) error {
if s == nil {
return errors.New("no storage")
}
return s.Health(ctx)
}
}
func ok(w http.ResponseWriter) {
utils.MarshalJSON(w, status{"ok"})
}
type status struct {
Status string `json:"status,omitempty"`
}