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})
|
||||
|
||||
if data.CanonicalRole(tufRole) == data.CanonicalTimestampRole {
|
||||
return getTimestamp(ctx, w, logger, store, gun)
|
||||
}
|
||||
|
||||
out, err := store.GetCurrent(gun, tufRole)
|
||||
if err != nil {
|
||||
if _, ok := err.(*storage.ErrNotFound); ok {
|
||||
|
@ -132,23 +136,14 @@ func DeleteHandler(ctx context.Context, w http.ResponseWriter, r *http.Request)
|
|||
return nil
|
||||
}
|
||||
|
||||
// GetTimestampHandler returns a timestamp.json given a GUN
|
||||
func GetTimestampHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
|
||||
s := ctx.Value("metaStore")
|
||||
store, ok := s.(storage.MetaStore)
|
||||
if !ok {
|
||||
return errors.ErrNoStorage.WithDetail(nil)
|
||||
}
|
||||
// getTimestampHandler returns a timestamp.json given a GUN
|
||||
func getTimestamp(ctx context.Context, w http.ResponseWriter, logger ctxu.Logger, store storage.MetaStore, gun string) error {
|
||||
cryptoServiceVal := ctx.Value("cryptoService")
|
||||
cryptoService, ok := cryptoServiceVal.(signed.CryptoService)
|
||||
if !ok {
|
||||
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)
|
||||
if err != nil {
|
||||
switch err.(type) {
|
||||
|
|
|
@ -89,14 +89,10 @@ func RootHandler(ac auth.AccessController, ctx context.Context, trust signed.Cry
|
|||
prometheus.InstrumentHandlerWithOpts(
|
||||
prometheusOpts("UpdateTuf"),
|
||||
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(
|
||||
prometheusOpts("GetRole"),
|
||||
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(
|
||||
prometheus.InstrumentHandlerWithOpts(
|
||||
prometheusOpts("GetTimestampKey"),
|
||||
|
|
Loading…
Reference in New Issue