diff options
Diffstat (limited to 'pkg/api/handlers/utils')
-rw-r--r-- | pkg/api/handlers/utils/containers.go | 13 | ||||
-rw-r--r-- | pkg/api/handlers/utils/images.go | 7 |
2 files changed, 11 insertions, 9 deletions
diff --git a/pkg/api/handlers/utils/containers.go b/pkg/api/handlers/utils/containers.go index fb1f8b7c1..5cdb31de1 100644 --- a/pkg/api/handlers/utils/containers.go +++ b/pkg/api/handlers/utils/containers.go @@ -8,6 +8,7 @@ import ( "time" "github.com/containers/podman/v3/libpod/events" + api "github.com/containers/podman/v3/pkg/api/types" "github.com/containers/podman/v3/pkg/domain/entities" "github.com/containers/podman/v3/pkg/domain/infra/abi" @@ -36,7 +37,7 @@ func WaitContainerDocker(w http.ResponseWriter, r *http.Request) { query := waitQueryDocker{} - decoder := ctx.Value("decoder").(*schema.Decoder) + decoder := ctx.Value(api.DecoderKey).(*schema.Decoder) if err = decoder.Decode(&query, r.URL.Query()); err != nil { Error(w, "Something went wrong.", http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String())) return @@ -68,7 +69,7 @@ func WaitContainerDocker(w http.ResponseWriter, r *http.Request) { // In docker compatibility mode we have to send headers in advance, // otherwise docker client would freeze. - w.Header().Add("Content-Type", "application/json") + w.Header().Set("Content-Type", "application/json") w.WriteHeader(200) if flusher, ok := w.(http.Flusher); ok { flusher.Flush() @@ -103,7 +104,7 @@ func WaitContainerLibpod(w http.ResponseWriter, r *http.Request) { interval = time.Millisecond * 250 conditions = []define.ContainerStatus{define.ContainerStateStopped, define.ContainerStateExited} ) - decoder := r.Context().Value("decoder").(*schema.Decoder) + decoder := r.Context().Value(api.DecoderKey).(*schema.Decoder) query := waitQueryLibpod{} if err := decoder.Decode(&query, r.URL.Query()); err != nil { Error(w, "Something went wrong.", http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String())) @@ -143,7 +144,7 @@ func WaitContainerLibpod(w http.ResponseWriter, r *http.Request) { type containerWaitFn func(conditions ...define.ContainerStatus) (int32, error) func createContainerWaitFn(ctx context.Context, containerName string, interval time.Duration) containerWaitFn { - runtime := ctx.Value("runtime").(*libpod.Runtime) + runtime := ctx.Value(api.RuntimeKey).(*libpod.Runtime) var containerEngine entities.ContainerEngine = &abi.ContainerEngine{Libpod: runtime} return func(conditions ...define.ContainerStatus) (int32, error) { @@ -205,7 +206,7 @@ func waitRemoved(ctrWait containerWaitFn) (int32, error) { } func waitNextExit(ctx context.Context, containerName string) (int32, error) { - runtime := ctx.Value("runtime").(*libpod.Runtime) + runtime := ctx.Value(api.RuntimeKey).(*libpod.Runtime) containerEngine := &abi.ContainerEngine{Libpod: runtime} eventChannel := make(chan *events.Event) errChannel := make(chan error) @@ -237,7 +238,7 @@ func waitNotRunning(ctrWait containerWaitFn) (int32, error) { } func containerExists(ctx context.Context, name string) (bool, error) { - runtime := ctx.Value("runtime").(*libpod.Runtime) + runtime := ctx.Value(api.RuntimeKey).(*libpod.Runtime) var containerEngine entities.ContainerEngine = &abi.ContainerEngine{Libpod: runtime} var ctrExistsOpts entities.ContainerExistsOptions diff --git a/pkg/api/handlers/utils/images.go b/pkg/api/handlers/utils/images.go index 1e3647a3e..d5eb71aa1 100644 --- a/pkg/api/handlers/utils/images.go +++ b/pkg/api/handlers/utils/images.go @@ -11,6 +11,7 @@ import ( "github.com/containers/image/v5/transports/alltransports" "github.com/containers/image/v5/types" "github.com/containers/podman/v3/libpod" + api "github.com/containers/podman/v3/pkg/api/types" "github.com/gorilla/schema" "github.com/pkg/errors" ) @@ -51,8 +52,8 @@ func ParseStorageReference(name string) (types.ImageReference, error) { // GetImages is a common function used to get images for libpod and other compatibility // mechanisms func GetImages(w http.ResponseWriter, r *http.Request) ([]*libimage.Image, error) { - decoder := r.Context().Value("decoder").(*schema.Decoder) - runtime := r.Context().Value("runtime").(*libpod.Runtime) + decoder := r.Context().Value(api.DecoderKey).(*schema.Decoder) + runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime) query := struct { All bool Digests bool @@ -87,7 +88,7 @@ func GetImages(w http.ResponseWriter, r *http.Request) ([]*libimage.Image, error } func GetImage(r *http.Request, name string) (*libimage.Image, error) { - runtime := r.Context().Value("runtime").(*libpod.Runtime) + runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime) image, _, err := runtime.LibimageRuntime().LookupImage(name, nil) if err != nil { return nil, err |