API return network-list if no network-name or id is provided#24634
API return network-list if no network-name or id is provided#24634vdemeester merged 1 commit intomoby:masterfrom
Conversation
|
Note that I also tried a different approach, and changing the route; https://github.com/docker/docker/blob/v1.12.0-rc4/api/server/router/network/network.go#L33-L34 diff --git a/api/server/router/network/network.go b/api/server/router/network/network.go
index 8688c3e..45548b5 100644
--- a/api/server/router/network/network.go
+++ b/api/server/router/network/network.go
@@ -31,7 +31,7 @@ func (r *networkRouter) initRoutes() {
r.routes = []router.Route{
// GET
router.NewGetRoute("/networks", r.getNetworksList),
- router.NewGetRoute("/networks/{id:.*}", r.getNetwork),
+ router.NewGetRoute("/networks/{id:.+}", r.getNetwork),
// POST
router.NewPostRoute("/networks/create", r.postNetworkCreate),
router.NewPostRoute("/networks/{id:.*}/connect", r.postNetworkConnect),This gives a different result (a 404 error with a "page not found"); perhaps doing that would break more clients that look for the return message, so I didn't use that; So I'm open to suggestions what the better approach is 😄 ping @mgoelzer @aboch |
There was a problem hiding this comment.
we could use
libnetwork.ErrNoSuchNetwork("(empty string)")to be more explicit
There was a problem hiding this comment.
I feel like this should be an impossibility.
There was a problem hiding this comment.
See the repro case at the top; probably not possible through the CLI, but it's possible to get there when directly using the API
There was a problem hiding this comment.
Changing to {id} instead of {id:.*} seems to do the trick.
There was a problem hiding this comment.
@cpuguy83 yes, see above (#24634 (comment)), but that would change the response from the current error (if an invalid name is provided); I wasn't sure if we wanted to risk that. Also see #24634 (comment)
There was a problem hiding this comment.
We can just add an explicit route for the trailing slash:
router.NewGetRoute("/networks/", r.getNetworksList),
Displaying the bridge inspect for /networks/ is a bug.
|
cc @bfirsh who obsesses details of API behaviour... |
|
👍 Changing the route to Are |
@bfirsh I'll check, but looking at those I think we can change those to |
|
@thaJeztah what's up here? |
|
I think we can merge, but perhaps @cpuguy83 wants the other approach |
|
I do agree with @cpuguy83 on that one
|
4cf2d66 to
6081c71
Compare
|
Updated the PR to make |
6081c71 to
f90f749
Compare
|
ping @cpuguy83 @vdemeester PTAL |
f90f749 to
cff56e4
Compare
|
rebased. ping @cpuguy83 PTAL |
|
LGTM |
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 <github@gone.nl>
cff56e4 to
6ad4bf0
Compare
|
rebased (again) 😅 |
|
boo, flaky test? |
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.
Also updated the description for GetNetworkByName to
explain that the "default" network is returned if
no name or id is provided.
closes #24595