diff options
-rw-r--r-- | RELEASE_NOTES.md | 3 | ||||
-rw-r--r-- | cmd/podman/service.go | 1 | ||||
-rw-r--r-- | pkg/api/handlers/containers.go | 10 | ||||
-rw-r--r-- | pkg/api/handlers/containers_attach.go | 4 | ||||
-rw-r--r-- | pkg/api/handlers/containers_top.go | 3 | ||||
-rw-r--r-- | pkg/api/handlers/generic/containers.go | 4 | ||||
-rw-r--r-- | pkg/api/handlers/generic/containers_stats.go | 3 | ||||
-rw-r--r-- | pkg/api/handlers/generic/images.go | 5 | ||||
-rw-r--r-- | pkg/api/handlers/handler.go | 9 | ||||
-rw-r--r-- | pkg/api/handlers/images.go | 6 | ||||
-rw-r--r-- | pkg/api/handlers/libpod/containers.go | 9 | ||||
-rw-r--r-- | pkg/api/handlers/libpod/healthcheck.go | 6 | ||||
-rw-r--r-- | pkg/api/handlers/libpod/images.go | 12 | ||||
-rw-r--r-- | pkg/api/handlers/libpod/networks.go | 85 | ||||
-rw-r--r-- | pkg/api/handlers/libpod/pods.go | 27 | ||||
-rw-r--r-- | pkg/api/handlers/libpod/volumes.go | 7 | ||||
-rw-r--r-- | pkg/api/handlers/utils/containers.go | 7 | ||||
-rw-r--r-- | pkg/api/handlers/utils/handler.go | 18 | ||||
-rw-r--r-- | pkg/api/server/server.go | 3 | ||||
-rw-r--r-- | pkg/bindings/connection.go | 2 | ||||
-rw-r--r-- | pkg/bindings/test/images_test.go | 6 |
21 files changed, 150 insertions, 80 deletions
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index d2b875967..d961b713e 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -2,7 +2,7 @@ ## 1.8.0 ### Features -- The `podman service` command has been added, providing a preview of Podman's new Docker-compatible API. This is still very early, and not yet ready for use, but is available for early testing +- The `podman service` command has been added, providing a preview of Podman's new Docker-compatible API. This API is still very new, and not yet ready for production use, but is available for early testing - Rootless Podman now uses Rootlesskit for port forwarding, which should greatly improve performance and capabilities - The `podman untag` command has been added to remove tags from images without deleting them - The `podman inspect` command on images now displays previous names they used @@ -28,6 +28,7 @@ - Fixed a bug where named volumes created with containers from pre-1.6.3 releases of Podman would be autoremoved with their containers if the `--rm` flag was given, even if they were given names ([#5009](https://github.com/containers/libpod/issues/5009)) - Fixed a bug where `podman history` was not computing image sizes correctly ([#4916](https://github.com/containers/libpod/issues/4916)) - Fixed a bug where Podman would not error on invalid values to the `--sort` flag to `podman images` +- Fixed a bug where providing a name for the image made by `podman commit` was mandatory, not optional as it should be ([#5027](https://github.com/containers/libpod/issues/5027)) ### Misc - Initial work on version 2 of the Podman remote API has been merged, but is still in an alpha state and not ready for use. Read more [here](https://podman.io/releases/2020/01/17/podman-new-api.html) diff --git a/cmd/podman/service.go b/cmd/podman/service.go index 6e2b4a366..4978b5d51 100644 --- a/cmd/podman/service.go +++ b/cmd/podman/service.go @@ -115,6 +115,7 @@ func runREST(r *libpod.Runtime, uri string, timeout time.Duration) error { if err != nil { return errors.Wrapf(err, "unable to create socket %s", uri) } + defer l.Close() server, err := api.NewServerWithSettings(r, timeout, &l) if err != nil { return err diff --git a/pkg/api/handlers/containers.go b/pkg/api/handlers/containers.go index b5c78ce53..f180fbc2b 100644 --- a/pkg/api/handlers/containers.go +++ b/pkg/api/handlers/containers.go @@ -29,7 +29,7 @@ func StopContainer(w http.ResponseWriter, r *http.Request) { return } - name := getName(r) + name := utils.GetName(r) con, err := runtime.LookupContainer(name) if err != nil { utils.ContainerNotFound(w, name, err) @@ -67,7 +67,7 @@ func UnpauseContainer(w http.ResponseWriter, r *http.Request) { runtime := r.Context().Value("runtime").(*libpod.Runtime) // /{version}/containers/(name)/unpause - name := getName(r) + name := utils.GetName(r) con, err := runtime.LookupContainer(name) if err != nil { utils.ContainerNotFound(w, name, err) @@ -88,7 +88,7 @@ func PauseContainer(w http.ResponseWriter, r *http.Request) { runtime := r.Context().Value("runtime").(*libpod.Runtime) // /{version}/containers/(name)/pause - name := getName(r) + name := utils.GetName(r) con, err := runtime.LookupContainer(name) if err != nil { utils.ContainerNotFound(w, name, err) @@ -121,7 +121,7 @@ func StartContainer(w http.ResponseWriter, r *http.Request) { return } runtime := r.Context().Value("runtime").(*libpod.Runtime) - name := getName(r) + name := utils.GetName(r) con, err := runtime.LookupContainer(name) if err != nil { utils.ContainerNotFound(w, name, err) @@ -159,7 +159,7 @@ func RestartContainer(w http.ResponseWriter, r *http.Request) { return } - name := getName(r) + name := utils.GetName(r) con, err := runtime.LookupContainer(name) if err != nil { utils.ContainerNotFound(w, name, err) diff --git a/pkg/api/handlers/containers_attach.go b/pkg/api/handlers/containers_attach.go index eb306348b..facbd22a5 100644 --- a/pkg/api/handlers/containers_attach.go +++ b/pkg/api/handlers/containers_attach.go @@ -77,7 +77,7 @@ func AttachContainer(w http.ResponseWriter, r *http.Request) { return } - name := getName(r) + name := utils.GetName(r) ctr, err := runtime.LookupContainer(name) if err != nil { utils.ContainerNotFound(w, name, err) @@ -138,7 +138,7 @@ func ResizeContainer(w http.ResponseWriter, r *http.Request) { return } - name := getName(r) + name := utils.GetName(r) ctr, err := runtime.LookupContainer(name) if err != nil { utils.ContainerNotFound(w, name, err) diff --git a/pkg/api/handlers/containers_top.go b/pkg/api/handlers/containers_top.go index 6b7688eb0..06d5dd653 100644 --- a/pkg/api/handlers/containers_top.go +++ b/pkg/api/handlers/containers_top.go @@ -6,7 +6,6 @@ import ( "github.com/containers/libpod/libpod" "github.com/containers/libpod/pkg/api/handlers/utils" - "github.com/gorilla/mux" "github.com/gorilla/schema" "github.com/pkg/errors" ) @@ -30,7 +29,7 @@ func TopContainer(w http.ResponseWriter, r *http.Request) { return } - name := mux.Vars(r)["name"] + name := utils.GetName(r) c, err := runtime.LookupContainer(name) if err != nil { utils.ContainerNotFound(w, name, err) diff --git a/pkg/api/handlers/generic/containers.go b/pkg/api/handlers/generic/containers.go index 8dc73ae14..b16b87e73 100644 --- a/pkg/api/handlers/generic/containers.go +++ b/pkg/api/handlers/generic/containers.go @@ -99,7 +99,7 @@ func ListContainers(w http.ResponseWriter, r *http.Request) { func GetContainer(w http.ResponseWriter, r *http.Request) { runtime := r.Context().Value("runtime").(*libpod.Runtime) - name := mux.Vars(r)["name"] + name := utils.GetName(r) ctnr, err := runtime.LookupContainer(name) if err != nil { utils.ContainerNotFound(w, name, err) @@ -174,7 +174,7 @@ func LogsFromContainer(w http.ResponseWriter, r *http.Request) { return } - name := mux.Vars(r)["name"] + name := utils.GetName(r) ctnr, err := runtime.LookupContainer(name) if err != nil { utils.ContainerNotFound(w, name, err) diff --git a/pkg/api/handlers/generic/containers_stats.go b/pkg/api/handlers/generic/containers_stats.go index e33d37606..f8804b5c0 100644 --- a/pkg/api/handlers/generic/containers_stats.go +++ b/pkg/api/handlers/generic/containers_stats.go @@ -11,7 +11,6 @@ import ( "github.com/containers/libpod/pkg/api/handlers/utils" "github.com/containers/libpod/pkg/cgroups" docker "github.com/docker/docker/api/types" - "github.com/gorilla/mux" "github.com/gorilla/schema" "github.com/pkg/errors" "github.com/sirupsen/logrus" @@ -36,7 +35,7 @@ func StatsContainer(w http.ResponseWriter, r *http.Request) { return } - name := mux.Vars(r)["name"] + name := utils.GetName(r) ctnr, err := runtime.LookupContainer(name) if err != nil { utils.ContainerNotFound(w, name, err) diff --git a/pkg/api/handlers/generic/images.go b/pkg/api/handlers/generic/images.go index ba1cf47b4..20dd84456 100644 --- a/pkg/api/handlers/generic/images.go +++ b/pkg/api/handlers/generic/images.go @@ -16,7 +16,6 @@ import ( "github.com/containers/libpod/pkg/api/handlers/utils" "github.com/containers/libpod/pkg/util" "github.com/docker/docker/api/types" - "github.com/gorilla/mux" "github.com/gorilla/schema" "github.com/pkg/errors" ) @@ -26,7 +25,7 @@ func ExportImage(w http.ResponseWriter, r *http.Request) { // 500 server runtime := r.Context().Value("runtime").(*libpod.Runtime) - name := mux.Vars(r)["name"] + name := utils.GetName(r) newImage, err := runtime.ImageRuntime().NewFromLocal(name) if err != nil { utils.ImageNotFound(w, name, errors.Wrapf(err, "Failed to find image %s", name)) @@ -285,7 +284,7 @@ func GetImage(w http.ResponseWriter, r *http.Request) { // 200 no error // 404 no such // 500 internal - name := mux.Vars(r)["name"] + name := utils.GetName(r) newImage, err := handlers.GetImage(r, name) if err != nil { utils.Error(w, "Something went wrong.", http.StatusNotFound, errors.Wrapf(err, "Failed to find image %s", name)) diff --git a/pkg/api/handlers/handler.go b/pkg/api/handlers/handler.go index d60a5b239..231c11f23 100644 --- a/pkg/api/handlers/handler.go +++ b/pkg/api/handlers/handler.go @@ -4,26 +4,17 @@ import ( "net/http" "github.com/containers/libpod/libpod" - "github.com/gorilla/mux" "github.com/gorilla/schema" "github.com/pkg/errors" ) // Convenience routines to reduce boiler plate in handlers -func getVar(r *http.Request, k string) string { - return mux.Vars(r)[k] -} - // func hasVar(r *http.Request, k string) bool { // _, found := mux.Vars(r)[k] // return found // } -func getName(r *http.Request) string { - return getVar(r, "name") -} - func decodeQuery(r *http.Request, i interface{}) error { decoder := r.Context().Value("decoder").(*schema.Decoder) diff --git a/pkg/api/handlers/images.go b/pkg/api/handlers/images.go index 3f66a63c8..cd3c0b93f 100644 --- a/pkg/api/handlers/images.go +++ b/pkg/api/handlers/images.go @@ -17,7 +17,7 @@ import ( func HistoryImage(w http.ResponseWriter, r *http.Request) { runtime := r.Context().Value("runtime").(*libpod.Runtime) - name := mux.Vars(r)["name"] + name := utils.GetName(r) var allHistory []HistoryResponse newImage, err := runtime.ImageRuntime().NewFromLocal(name) @@ -49,7 +49,7 @@ func TagImage(w http.ResponseWriter, r *http.Request) { runtime := r.Context().Value("runtime").(*libpod.Runtime) // /v1.xx/images/(name)/tag - name := mux.Vars(r)["name"] + name := utils.GetName(r) newImage, err := runtime.ImageRuntime().NewFromLocal(name) if err != nil { utils.ImageNotFound(w, name, errors.Wrapf(err, "Failed to find image %s", name)) @@ -92,7 +92,7 @@ func RemoveImage(w http.ResponseWriter, r *http.Request) { utils.UnSupportedParameter("noprune") } } - name := mux.Vars(r)["name"] + name := utils.GetName(r) newImage, err := runtime.ImageRuntime().NewFromLocal(name) if err != nil { utils.ImageNotFound(w, name, errors.Wrapf(err, "Failed to find image %s", name)) diff --git a/pkg/api/handlers/libpod/containers.go b/pkg/api/handlers/libpod/containers.go index db1cf26ff..54acdbd36 100644 --- a/pkg/api/handlers/libpod/containers.go +++ b/pkg/api/handlers/libpod/containers.go @@ -9,7 +9,6 @@ import ( "github.com/containers/libpod/libpod" "github.com/containers/libpod/pkg/api/handlers" "github.com/containers/libpod/pkg/api/handlers/utils" - "github.com/gorilla/mux" "github.com/gorilla/schema" "github.com/pkg/errors" ) @@ -20,7 +19,7 @@ func StopContainer(w http.ResponseWriter, r *http.Request) { func ContainerExists(w http.ResponseWriter, r *http.Request) { runtime := r.Context().Value("runtime").(*libpod.Runtime) - name := mux.Vars(r)["name"] + name := utils.GetName(r) _, err := runtime.LookupContainer(name) if err != nil { utils.ContainerNotFound(w, name, err) @@ -105,7 +104,7 @@ func GetContainer(w http.ResponseWriter, r *http.Request) { return } runtime := r.Context().Value("runtime").(*libpod.Runtime) - name := mux.Vars(r)["name"] + name := utils.GetName(r) container, err := runtime.LookupContainer(name) if err != nil { utils.ContainerNotFound(w, name, err) @@ -147,7 +146,7 @@ func LogsFromContainer(w http.ResponseWriter, r *http.Request) { func UnmountContainer(w http.ResponseWriter, r *http.Request) { runtime := r.Context().Value("runtime").(*libpod.Runtime) - name := mux.Vars(r)["name"] + name := utils.GetName(r) conn, err := runtime.LookupContainer(name) if err != nil { utils.ContainerNotFound(w, name, err) @@ -163,7 +162,7 @@ func UnmountContainer(w http.ResponseWriter, r *http.Request) { } func MountContainer(w http.ResponseWriter, r *http.Request) { runtime := r.Context().Value("runtime").(*libpod.Runtime) - name := mux.Vars(r)["name"] + name := utils.GetName(r) conn, err := runtime.LookupContainer(name) if err != nil { utils.ContainerNotFound(w, name, err) diff --git a/pkg/api/handlers/libpod/healthcheck.go b/pkg/api/handlers/libpod/healthcheck.go index 0d7bf3ea7..6c74500b9 100644 --- a/pkg/api/handlers/libpod/healthcheck.go +++ b/pkg/api/handlers/libpod/healthcheck.go @@ -5,15 +5,11 @@ import ( "github.com/containers/libpod/libpod" "github.com/containers/libpod/pkg/api/handlers/utils" - "github.com/gorilla/mux" ) func RunHealthCheck(w http.ResponseWriter, r *http.Request) { - // 200 ok - // 404 no such - // 500 internal runtime := r.Context().Value("runtime").(*libpod.Runtime) - name := mux.Vars(r)["name"] + name := utils.GetName(r) status, err := runtime.HealthCheck(name) if err != nil { if status == libpod.HealthCheckContainerNotFound { diff --git a/pkg/api/handlers/libpod/images.go b/pkg/api/handlers/libpod/images.go index 9f0876618..202ed5eaa 100644 --- a/pkg/api/handlers/libpod/images.go +++ b/pkg/api/handlers/libpod/images.go @@ -11,7 +11,6 @@ import ( "github.com/containers/libpod/libpod" "github.com/containers/libpod/pkg/api/handlers" "github.com/containers/libpod/pkg/api/handlers/utils" - "github.com/gorilla/mux" "github.com/gorilla/schema" "github.com/pkg/errors" ) @@ -28,11 +27,8 @@ import ( // create func ImageExists(w http.ResponseWriter, r *http.Request) { - // 200 ok - // 404 no such - // 500 internal runtime := r.Context().Value("runtime").(*libpod.Runtime) - name := mux.Vars(r)["name"] + name := utils.GetName(r) _, err := runtime.ImageRuntime().NewFromLocal(name) if err != nil { @@ -45,7 +41,7 @@ func ImageExists(w http.ResponseWriter, r *http.Request) { func ImageTree(w http.ResponseWriter, r *http.Request) { // tree is a bit of a mess ... logic is in adapter and therefore not callable from here. needs rework - // name := mux.Vars(r)["name"] + // name := utils.GetName(r) // _, layerInfoMap, _, err := s.Runtime.Tree(name) // if err != nil { // Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrapf(err, "Failed to find image information for %q", name)) @@ -57,7 +53,7 @@ func ImageTree(w http.ResponseWriter, r *http.Request) { } func GetImage(w http.ResponseWriter, r *http.Request) { - name := mux.Vars(r)["name"] + name := utils.GetName(r) newImage, err := handlers.GetImage(r, name) if err != nil { utils.Error(w, "Something went wrong.", http.StatusNotFound, errors.Wrapf(err, "Failed to find image %s", name)) @@ -160,7 +156,7 @@ func ExportImage(w http.ResponseWriter, r *http.Request) { utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "unable to close tempfile")) return } - name := mux.Vars(r)["name"] + name := utils.GetName(r) newImage, err := runtime.ImageRuntime().NewFromLocal(name) if err != nil { utils.ImageNotFound(w, name, err) diff --git a/pkg/api/handlers/libpod/networks.go b/pkg/api/handlers/libpod/networks.go new file mode 100644 index 000000000..e3dbe3b35 --- /dev/null +++ b/pkg/api/handlers/libpod/networks.go @@ -0,0 +1,85 @@ +package libpod + +import ( + "net/http" + + "github.com/containers/libpod/libpod" + "github.com/containers/libpod/pkg/api/handlers/utils" + "github.com/containers/libpod/pkg/network" + "github.com/gorilla/schema" + "github.com/pkg/errors" +) + +func CreateNetwork(w http.ResponseWriter, r *http.Request) {} +func ListNetworks(w http.ResponseWriter, r *http.Request) { + runtime := r.Context().Value("runtime").(*libpod.Runtime) + config, err := runtime.GetConfig() + if err != nil { + utils.InternalServerError(w, err) + return + } + configDir := config.CNIConfigDir + if len(configDir) < 1 { + configDir = network.CNIConfigDir + } + networks, err := network.LoadCNIConfsFromDir(configDir) + if err != nil { + utils.InternalServerError(w, err) + return + } + utils.WriteResponse(w, http.StatusOK, networks) +} + +func RemoveNetwork(w http.ResponseWriter, r *http.Request) { + // 200 ok + // 404 no such + // 500 internal + decoder := r.Context().Value("decoder").(*schema.Decoder) + query := struct { + Force bool `schema:"force"` + }{ + // override any golang type defaults + } + if err := decoder.Decode(&query, r.URL.Query()); err != nil { + utils.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest, + errors.Wrapf(err, "Failed to parse parameters for %s", r.URL.String())) + return + } + name := utils.GetName(r) + if err := network.RemoveNetwork(name); err != nil { + // If the network cannot be found, we return a 404. + if errors.Cause(err) == network.ErrNetworkNotFound { + utils.Error(w, "Something went wrong", http.StatusNotFound, err) + return + } + utils.InternalServerError(w, err) + return + } + utils.WriteResponse(w, http.StatusOK, "") +} + +func InspectNetwork(w http.ResponseWriter, r *http.Request) { + decoder := r.Context().Value("decoder").(*schema.Decoder) + query := struct { + Force bool `schema:"force"` + }{ + // override any golang type defaults + } + if err := decoder.Decode(&query, r.URL.Query()); err != nil { + utils.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest, + errors.Wrapf(err, "Failed to parse parameters for %s", r.URL.String())) + return + } + name := utils.GetName(r) + n, err := network.InspectNetwork(name) + if err != nil { + // If the network cannot be found, we return a 404. + if errors.Cause(err) == network.ErrNetworkNotFound { + utils.Error(w, "Something went wrong", http.StatusNotFound, err) + return + } + utils.InternalServerError(w, err) + return + } + utils.WriteResponse(w, http.StatusOK, n) +} diff --git a/pkg/api/handlers/libpod/pods.go b/pkg/api/handlers/libpod/pods.go index 50d763338..091368985 100644 --- a/pkg/api/handlers/libpod/pods.go +++ b/pkg/api/handlers/libpod/pods.go @@ -19,8 +19,6 @@ import ( ) func PodCreate(w http.ResponseWriter, r *http.Request) { - // 200 ok - // 500 internal var ( runtime = r.Context().Value("runtime").(*libpod.Runtime) options []libpod.PodCreateOption @@ -141,7 +139,7 @@ func Pods(w http.ResponseWriter, r *http.Request) { func PodInspect(w http.ResponseWriter, r *http.Request) { runtime := r.Context().Value("runtime").(*libpod.Runtime) - name := mux.Vars(r)["name"] + name := utils.GetName(r) pod, err := runtime.LookupPod(name) if err != nil { utils.PodNotFound(w, name, err) @@ -156,10 +154,6 @@ func PodInspect(w http.ResponseWriter, r *http.Request) { } func PodStop(w http.ResponseWriter, r *http.Request) { - // 200 - // 304 not modified - // 404 no such - // 500 internal var ( stopError error runtime = r.Context().Value("runtime").(*libpod.Runtime) @@ -177,7 +171,7 @@ func PodStop(w http.ResponseWriter, r *http.Request) { return } allContainersStopped := true - name := mux.Vars(r)["name"] + name := utils.GetName(r) pod, err := runtime.LookupPod(name) if err != nil { utils.PodNotFound(w, name, err) @@ -224,7 +218,7 @@ func PodStop(w http.ResponseWriter, r *http.Request) { func PodStart(w http.ResponseWriter, r *http.Request) { runtime := r.Context().Value("runtime").(*libpod.Runtime) allContainersRunning := true - name := mux.Vars(r)["name"] + name := utils.GetName(r) pod, err := runtime.LookupPod(name) if err != nil { utils.PodNotFound(w, name, err) @@ -278,7 +272,7 @@ func PodDelete(w http.ResponseWriter, r *http.Request) { errors.Wrapf(err, "Failed to parse parameters for %s", r.URL.String())) return } - name := mux.Vars(r)["name"] + name := utils.GetName(r) pod, err := runtime.LookupPod(name) if err != nil { utils.PodNotFound(w, name, err) @@ -293,7 +287,7 @@ func PodDelete(w http.ResponseWriter, r *http.Request) { func PodRestart(w http.ResponseWriter, r *http.Request) { runtime := r.Context().Value("runtime").(*libpod.Runtime) - name := mux.Vars(r)["name"] + name := utils.GetName(r) pod, err := runtime.LookupPod(name) if err != nil { utils.PodNotFound(w, name, err) @@ -321,7 +315,7 @@ func PodPrune(w http.ResponseWriter, r *http.Request) { func PodPause(w http.ResponseWriter, r *http.Request) { runtime := r.Context().Value("runtime").(*libpod.Runtime) - name := mux.Vars(r)["name"] + name := utils.GetName(r) pod, err := runtime.LookupPod(name) if err != nil { utils.PodNotFound(w, name, err) @@ -336,11 +330,8 @@ func PodPause(w http.ResponseWriter, r *http.Request) { } func PodUnpause(w http.ResponseWriter, r *http.Request) { - // 200 ok - // 404 no such - // 500 internal runtime := r.Context().Value("runtime").(*libpod.Runtime) - name := mux.Vars(r)["name"] + name := utils.GetName(r) pod, err := runtime.LookupPod(name) if err != nil { utils.PodNotFound(w, name, err) @@ -379,7 +370,7 @@ func PodKill(w http.ResponseWriter, r *http.Request) { if err != nil { utils.InternalServerError(w, errors.Wrapf(err, "unable to parse signal value")) } - name := mux.Vars(r)["name"] + name := utils.GetName(r) pod, err := runtime.LookupPod(name) if err != nil { utils.PodNotFound(w, name, err) @@ -412,7 +403,7 @@ func PodKill(w http.ResponseWriter, r *http.Request) { func PodExists(w http.ResponseWriter, r *http.Request) { runtime := r.Context().Value("runtime").(*libpod.Runtime) - name := mux.Vars(r)["name"] + name := utils.GetName(r) _, err := runtime.LookupPod(name) if err != nil { utils.PodNotFound(w, name, err) diff --git a/pkg/api/handlers/libpod/volumes.go b/pkg/api/handlers/libpod/volumes.go index 3e0e597c6..7e7e46718 100644 --- a/pkg/api/handlers/libpod/volumes.go +++ b/pkg/api/handlers/libpod/volumes.go @@ -8,15 +8,12 @@ import ( "github.com/containers/libpod/libpod" "github.com/containers/libpod/pkg/api/handlers" "github.com/containers/libpod/pkg/api/handlers/utils" - "github.com/gorilla/mux" "github.com/gorilla/schema" "github.com/pkg/errors" log "github.com/sirupsen/logrus" ) func CreateVolume(w http.ResponseWriter, r *http.Request) { - // 200 ok - // 500 internal var ( volumeOptions []libpod.VolumeCreateOption runtime = r.Context().Value("runtime").(*libpod.Runtime) @@ -66,7 +63,7 @@ func InspectVolume(w http.ResponseWriter, r *http.Request) { var ( runtime = r.Context().Value("runtime").(*libpod.Runtime) ) - name := mux.Vars(r)["name"] + name := utils.GetName(r) vol, err := runtime.GetVolume(name) if err != nil { utils.VolumeNotFound(w, name, err) @@ -132,7 +129,7 @@ func RemoveVolume(w http.ResponseWriter, r *http.Request) { errors.Wrapf(err, "Failed to parse parameters for %s", r.URL.String())) return } - name := mux.Vars(r)["name"] + name := utils.GetName(r) vol, err := runtime.LookupVolume(name) if err != nil { utils.VolumeNotFound(w, name, err) diff --git a/pkg/api/handlers/utils/containers.go b/pkg/api/handlers/utils/containers.go index 2c986db3a..74485edf2 100644 --- a/pkg/api/handlers/utils/containers.go +++ b/pkg/api/handlers/utils/containers.go @@ -9,7 +9,6 @@ import ( "github.com/containers/libpod/cmd/podman/shared" "github.com/containers/libpod/libpod" "github.com/containers/libpod/libpod/define" - "github.com/gorilla/mux" "github.com/gorilla/schema" "github.com/pkg/errors" ) @@ -26,7 +25,7 @@ func KillContainer(w http.ResponseWriter, r *http.Request) (*libpod.Container, e Error(w, "Something went wrong.", http.StatusBadRequest, errors.Wrapf(err, "Failed to parse parameters for %s", r.URL.String())) return nil, err } - name := mux.Vars(r)["name"] + name := GetName(r) con, err := runtime.LookupContainer(name) if err != nil { ContainerNotFound(w, name, err) @@ -54,7 +53,7 @@ func KillContainer(w http.ResponseWriter, r *http.Request) (*libpod.Container, e func RemoveContainer(w http.ResponseWriter, r *http.Request, force, vols bool) { runtime := r.Context().Value("runtime").(*libpod.Runtime) - name := mux.Vars(r)["name"] + name := GetName(r) con, err := runtime.LookupContainer(name) if err != nil { ContainerNotFound(w, name, err) @@ -87,7 +86,7 @@ func WaitContainer(w http.ResponseWriter, r *http.Request) (int32, error) { UnSupportedParameter("condition") } - name := mux.Vars(r)["name"] + name := GetName(r) con, err := runtime.LookupContainer(name) if err != nil { ContainerNotFound(w, name, err) diff --git a/pkg/api/handlers/utils/handler.go b/pkg/api/handlers/utils/handler.go index f2ce26f1a..970f93791 100644 --- a/pkg/api/handlers/utils/handler.go +++ b/pkg/api/handlers/utils/handler.go @@ -3,11 +3,14 @@ package utils import ( "encoding/json" "fmt" + "github.com/pkg/errors" "io" "net/http" + "net/url" "os" "strings" + "github.com/gorilla/mux" "github.com/sirupsen/logrus" ) @@ -59,3 +62,18 @@ func FilterMapToString(filters map[string][]string) (string, error) { } return string(f), nil } + +func getVar(r *http.Request, k string) string { + val := mux.Vars(r)[k] + safeVal, err := url.PathUnescape(val) + if err != nil { + logrus.Error(errors.Wrapf(err, "failed to unescape mux key %s, value %s", k, val)) + return val + } + return safeVal +} + +// GetName extracts the name from the mux +func GetName(r *http.Request) string { + return getVar(r, "name") +} diff --git a/pkg/api/server/server.go b/pkg/api/server/server.go index 8c940763e..d030961cb 100644 --- a/pkg/api/server/server.go +++ b/pkg/api/server/server.go @@ -63,8 +63,7 @@ func newServer(runtime *libpod.Runtime, duration time.Duration, listener *net.Li listener = &listeners[0] } - router := mux.NewRouter() - + router := mux.NewRouter().UseEncodedPath() server := APIServer{ Server: http.Server{ Handler: router, diff --git a/pkg/bindings/connection.go b/pkg/bindings/connection.go index 2e5fc9cb8..116af9709 100644 --- a/pkg/bindings/connection.go +++ b/pkg/bindings/connection.go @@ -116,7 +116,7 @@ func (c *Connection) DoRequest(httpBody io.Reader, httpMethod, endpoint string, safePathValues := make([]interface{}, len(pathValues)) // Make sure path values are http url safe for i, pv := range pathValues { - safePathValues[i] = url.QueryEscape(pv) + safePathValues[i] = url.PathEscape(pv) } // Lets eventually use URL for this which might lead to safer // usage diff --git a/pkg/bindings/test/images_test.go b/pkg/bindings/test/images_test.go index 2906d55cd..227f28d16 100644 --- a/pkg/bindings/test/images_test.go +++ b/pkg/bindings/test/images_test.go @@ -67,10 +67,10 @@ var _ = Describe("Podman images", func() { // Inspect with partial ID _, err = images.GetImage(connText, data.ID[0:12], nil) Expect(err).To(BeNil()) - // Inspect by ID + //Inspect by long name should work, it doesnt (yet) i think it needs to be html escaped - //_, err = images.GetImage(connText, alpine, nil) - //Expect(err).To(BeNil()) + _, err = images.GetImage(connText, alpine, nil) + Expect(err).To(BeNil()) }) It("remove image", func() { // Remove invalid image should be a 404 |