Skip to content

API return network-list if no network-name or id is provided#24634

Merged
vdemeester merged 1 commit intomoby:masterfrom
thaJeztah:make-network-name-required
Sep 27, 2016
Merged

API return network-list if no network-name or id is provided#24634
vdemeester merged 1 commit intomoby:masterfrom
thaJeztah:make-network-name-required

Conversation

@thaJeztah
Copy link
Copy Markdown
Member

@thaJeztah thaJeztah commented Jul 14, 2016

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

@thaJeztah
Copy link
Copy Markdown
Member Author

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;

/ # curl -sv --unix-socket /var/run/docker.sock http:/networks/
*   Trying /var/run/docker.sock...
* Connected to http (/var/run/docker.sock) port 80 (#0)
> GET /networks/ HTTP/1.1
> Host: http
> User-Agent: curl/7.49.1
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Content-Type: application/json
< Date: Thu, 14 Jul 2016 12:38:29 GMT
< Content-Length: 29
<
{"message":"page not found"}
* Connection #0 to host http left intact

So I'm open to suggestions what the better approach is 😄

ping @mgoelzer @aboch

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could use

libnetwork.ErrNoSuchNetwork("(empty string)")

to be more explicit

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this should be an impossibility.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing to {id} instead of {id:.*} seems to do the trick.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@justincormack
Copy link
Copy Markdown
Contributor

cc @bfirsh who obsesses details of API behaviour...

@bfirsh
Copy link
Copy Markdown
Contributor

bfirsh commented Jul 14, 2016

👍

Changing the route to .+ seems neater but for consistency with other routes your approach seems best.

Are POST /networks/id/connect, POST /networks/id/disconnect, DELETE /networks/id affected by this too?

@thaJeztah
Copy link
Copy Markdown
Member Author

Are POST /networks/id/connect, /networks/id/disconnect, DELETE /networks/id affected by this too?

@bfirsh I'll check, but looking at those I think we can change those to ../{id:.+}/disconnect, as I don't think supporting /network//disconnect would make a lot of sense (having a standard 404 for those should be okay). I'll check those

@LK4D4
Copy link
Copy Markdown
Contributor

LK4D4 commented Aug 5, 2016

@thaJeztah what's up here?

@thaJeztah
Copy link
Copy Markdown
Member Author

I think we can merge, but perhaps @cpuguy83 wants the other approach

@vdemeester
Copy link
Copy Markdown
Member

I do agree with @cpuguy83 on that one

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.

@thaJeztah thaJeztah force-pushed the make-network-name-required branch from 4cf2d66 to 6081c71 Compare September 12, 2016 14:23
@thaJeztah thaJeztah changed the title API return error if no network-name or id is provided API return network-list if no network-name or id is provided Sep 12, 2016
@thaJeztah
Copy link
Copy Markdown
Member Author

Updated the PR to make /networks and /networks/ return the same results

@thaJeztah thaJeztah force-pushed the make-network-name-required branch from 6081c71 to f90f749 Compare September 16, 2016 22:54
@thaJeztah
Copy link
Copy Markdown
Member Author

ping @cpuguy83 @vdemeester PTAL

Copy link
Copy Markdown
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🐸

@thaJeztah thaJeztah force-pushed the make-network-name-required branch from f90f749 to cff56e4 Compare September 26, 2016 16:41
@thaJeztah
Copy link
Copy Markdown
Member Author

rebased. ping @cpuguy83 PTAL

@cpuguy83
Copy link
Copy Markdown
Member

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>
@thaJeztah thaJeztah force-pushed the make-network-name-required branch from cff56e4 to 6ad4bf0 Compare September 26, 2016 19:44
@thaJeztah
Copy link
Copy Markdown
Member Author

rebased (again) 😅

@thaJeztah
Copy link
Copy Markdown
Member Author

boo, flaky test?

20:08:46 ----------------------------------------------------------------------
20:08:46 FAIL: docker_cli_attach_unix_test.go:18: DockerSuite.TestAttachClosedOnContainerStop
20:08:46 
20:08:46 docker_cli_attach_unix_test.go:51:
20:08:46     c.Assert(err, check.IsNil)
20:08:46 ... value *exec.ExitError = &exec.ExitError{ProcessState:(*os.ProcessState)(0xc4204f20a0), Stderr:[]uint8(nil)} ("exit status 1")
20:08:46 
20:08:47 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GET /networks/ inspects the bridge network

7 participants