From 6352e3e7767fd4f72f539e3c793b9bedb23035e1 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 14 Jul 2016 15:07:00 +0200 Subject: [PATCH] API return network-list if no network-name or id is provided When calling the /networks/ endpoint with a trailing slash, the default network was returned. This changes the endpoint to return the list of networks instead (same response as `/networks` without trailing slash). Also updated the description for GetNetworkByName to explain that the "default" network is returned if no name or id is provided. Signed-off-by: Sebastiaan van Stijn Upstream-commit: 6ad4bf0a533f8851b0ddccb56fe3b457819f6146 Component: engine --- components/engine/api/server/router/network/network.go | 3 ++- components/engine/daemon/network.go | 1 + components/engine/docs/reference/api/docker_remote_api.md | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/components/engine/api/server/router/network/network.go b/components/engine/api/server/router/network/network.go index 8688c3ed1f..f940ae0a26 100644 --- a/components/engine/api/server/router/network/network.go +++ b/components/engine/api/server/router/network/network.go @@ -31,7 +31,8 @@ func (r *networkRouter) initRoutes() { r.routes = []router.Route{ // GET router.NewGetRoute("/networks", r.getNetworksList), - router.NewGetRoute("/networks/{id:.*}", r.getNetwork), + router.NewGetRoute("/networks/", r.getNetworksList), + router.NewGetRoute("/networks/{id:.+}", r.getNetwork), // POST router.NewPostRoute("/networks/create", r.postNetworkCreate), router.NewPostRoute("/networks/{id:.*}/connect", r.postNetworkConnect), diff --git a/components/engine/daemon/network.go b/components/engine/daemon/network.go index 57547993ed..65631bc71a 100644 --- a/components/engine/daemon/network.go +++ b/components/engine/daemon/network.go @@ -59,6 +59,7 @@ func (daemon *Daemon) GetNetworkByID(partialID string) (libnetwork.Network, erro } // GetNetworkByName function returns a network for a given network name. +// If no network name is given, the default network is returned. func (daemon *Daemon) GetNetworkByName(name string) (libnetwork.Network, error) { c := daemon.netController if c == nil { diff --git a/components/engine/docs/reference/api/docker_remote_api.md b/components/engine/docs/reference/api/docker_remote_api.md index 6053db96d6..33441f7857 100644 --- a/components/engine/docs/reference/api/docker_remote_api.md +++ b/components/engine/docs/reference/api/docker_remote_api.md @@ -125,6 +125,9 @@ This section lists each version from latest to oldest. Each listing includes a * `POST /containers/create` now takes a `Mounts` field in `HostConfig` which replaces `Binds` and `Volumes`. *note*: `Binds` and `Volumes` are still available but are exclusive with `Mounts` * `POST /build` now performs a preliminary validation of the `Dockerfile` before starting the build, and returns an error if the syntax is incorrect. Note that this change is _unversioned_ and applied to all API versions. * `POST /build` accepts `cachefrom` parameter to specify images used for build cache. +* `GET /networks/` endpoint now correctly returns a list of *all* networks, + instead of the default network if a trailing slash is provided, but no `name` + or `id`. ### v1.24 API changes