mirror of https://github.com/docker/docs.git
unify the timestamp handler with the handler for getting other tuf metadata
Signed-off-by: David Lawrence <david.lawrence@docker.com> (github: endophage)
This commit is contained in:
parent
5593112f85
commit
a1ec8c69e0
|
@ -96,6 +96,10 @@ func GetHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) err
|
||||||
|
|
||||||
logger := ctxu.GetLoggerWithFields(ctx, map[string]interface{}{"gun": gun, "tufRole": tufRole})
|
logger := ctxu.GetLoggerWithFields(ctx, map[string]interface{}{"gun": gun, "tufRole": tufRole})
|
||||||
|
|
||||||
|
if data.CanonicalRole(tufRole) == data.CanonicalTimestampRole {
|
||||||
|
return getTimestamp(ctx, w, logger, store, gun)
|
||||||
|
}
|
||||||
|
|
||||||
out, err := store.GetCurrent(gun, tufRole)
|
out, err := store.GetCurrent(gun, tufRole)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if _, ok := err.(*storage.ErrNotFound); ok {
|
if _, ok := err.(*storage.ErrNotFound); ok {
|
||||||
|
@ -132,23 +136,14 @@ func DeleteHandler(ctx context.Context, w http.ResponseWriter, r *http.Request)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetTimestampHandler returns a timestamp.json given a GUN
|
// getTimestampHandler returns a timestamp.json given a GUN
|
||||||
func GetTimestampHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
|
func getTimestamp(ctx context.Context, w http.ResponseWriter, logger ctxu.Logger, store storage.MetaStore, gun string) error {
|
||||||
s := ctx.Value("metaStore")
|
|
||||||
store, ok := s.(storage.MetaStore)
|
|
||||||
if !ok {
|
|
||||||
return errors.ErrNoStorage.WithDetail(nil)
|
|
||||||
}
|
|
||||||
cryptoServiceVal := ctx.Value("cryptoService")
|
cryptoServiceVal := ctx.Value("cryptoService")
|
||||||
cryptoService, ok := cryptoServiceVal.(signed.CryptoService)
|
cryptoService, ok := cryptoServiceVal.(signed.CryptoService)
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.ErrNoCryptoService.WithDetail(nil)
|
return errors.ErrNoCryptoService.WithDetail(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
vars := mux.Vars(r)
|
|
||||||
gun := vars["imageName"]
|
|
||||||
logger := ctxu.GetLoggerWithField(ctx, gun, "gun")
|
|
||||||
|
|
||||||
out, err := timestamp.GetOrCreateTimestamp(gun, store, cryptoService)
|
out, err := timestamp.GetOrCreateTimestamp(gun, store, cryptoService)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
switch err.(type) {
|
switch err.(type) {
|
||||||
|
|
|
@ -89,14 +89,10 @@ func RootHandler(ac auth.AccessController, ctx context.Context, trust signed.Cry
|
||||||
prometheus.InstrumentHandlerWithOpts(
|
prometheus.InstrumentHandlerWithOpts(
|
||||||
prometheusOpts("UpdateTuf"),
|
prometheusOpts("UpdateTuf"),
|
||||||
hand(handlers.AtomicUpdateHandler, "push", "pull")))
|
hand(handlers.AtomicUpdateHandler, "push", "pull")))
|
||||||
r.Methods("GET").Path("/v2/{imageName:.*}/_trust/tuf/{tufRole:(root|targets|snapshot)}.json").Handler(
|
r.Methods("GET").Path("/v2/{imageName:.*}/_trust/tuf/{tufRole:(root|targets|snapshot|timestamp)}.json").Handler(
|
||||||
prometheus.InstrumentHandlerWithOpts(
|
prometheus.InstrumentHandlerWithOpts(
|
||||||
prometheusOpts("GetRole"),
|
prometheusOpts("GetRole"),
|
||||||
hand(handlers.GetHandler, "pull")))
|
hand(handlers.GetHandler, "pull")))
|
||||||
r.Methods("GET").Path("/v2/{imageName:.*}/_trust/tuf/timestamp.json").Handler(
|
|
||||||
prometheus.InstrumentHandlerWithOpts(
|
|
||||||
prometheusOpts("GetTimestamp"),
|
|
||||||
hand(handlers.GetTimestampHandler, "pull")))
|
|
||||||
r.Methods("GET").Path("/v2/{imageName:.*}/_trust/tuf/timestamp.key").Handler(
|
r.Methods("GET").Path("/v2/{imageName:.*}/_trust/tuf/timestamp.key").Handler(
|
||||||
prometheus.InstrumentHandlerWithOpts(
|
prometheus.InstrumentHandlerWithOpts(
|
||||||
prometheusOpts("GetTimestampKey"),
|
prometheusOpts("GetTimestampKey"),
|
||||||
|
|
Loading…
Reference in New Issue