Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Successful requests with intended empty body should return 204 #1811

Closed
anthraxn8b opened this issue Apr 13, 2018 · 4 comments
Closed

Successful requests with intended empty body should return 204 #1811

anthraxn8b opened this issue Apr 13, 2018 · 4 comments
Labels
area/api kind/enhancement Applied to Feature Requests
Milestone

Comments

@anthraxn8b
Copy link

anthraxn8b commented Apr 13, 2018

Description

I wrote a script that creates a new stack via the portainer API.
I noticed that the stack is always public - no matter which type of user creates it.

So I tried to create a new resource control object for the stack (Yes. The documentation does not mention "stack" as a valid type...)

Steps to reproduce the issue:

curl
   --verbose
   --header  'Authorization: Bearer ey...'
   --header 'Content-Type:  application/json'
   --header 'Accept:        application/json'
   --data '{
      "ResourceID": "tmp000_08154711...",
      "Type": "stack",
      "AdministratorsOnly": false,
      "Teams": [
        3
      ]
   }'
   --request POST
   http://myhost:9000/api/resource_controls
   
Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying 10.111.112.113...
* Connected to myhost (10.111.112.113) port 9000 (#0)
> POST /api/resource_controls HTTP/1.1
> Host: myhost:9000
> User-Agent: curl/7.47.0
> Authorization: Bearer ey...
> Content-Type:  application/json
> Accept:        application/json
> Content-Length: 142
> 
* upload completely sent off: 142 out of 142 bytes
< HTTP/1.1 200 OK
< X-Content-Type-Options: nosniff
< X-Frame-Options: DENY
< Date: Fri, 13 Apr 2018 11:29:13 GMT
< Content-Length: 0
< Content-Type: text/plain; charset=utf-8
< 
* Connection #0 to host myhost left intact

Why do you consider this to be a bug?

In this request I see multiple buggy things:

  1. The response type is incorrect. I requested "application/json". As far as I saw there is already another bug mentioning that so ignore it here.
  2. The response is "200 OK" which says "[...] In a POST request, the response will contain an entity describing or containing the result of the action. [...]". But the response is empty.

What did you expect to happen instead?

Either (if "stack" is a valid type - regardeless of the swagger documentation) you can solve this by providing useful information or by changing the return code to "204 NO CONTENT" which says "[...] The server successfully processed the request and is not returning any content. [...]" or (if "stack" is an invalid type) by returning a "400 BAD REQUEST" explaining that there is inappropriate data in the request (and what is the exact problem...).

Technical details:

  • Portainer version: 1.16.5
  • Target Docker version: 17.12.0-ce
  • Platform: linux
  • Command used to start Portainer: Inside of a compose file:
  portainer:
    image: docker.repo.my/portainer/portainer:1.16.5
    ports:
     - "9000:9000"
    volumes:
     - /var/run/docker.sock:/var/run/docker.sock
     - ${NFS_SHARE}/portainer:/data:rw
    command: -H unix:///var/run/docker.sock
    dns:
     - ${DNS1}
     - ${DNS2}
    deploy:
     placement:
        constraints:
          - node.role == manager
     mode: replicated
     replicas: 1
  • Target Swarm version (if applicable): Docker Swarm matching server version.
  • Browser: Firefox Quantum 59.0.2 (64-bit)

I would really appreciate if "stack" would be a valid type... :-)

@anthraxn8b anthraxn8b changed the title Create new resource control on stack Buggy response when creating a new resource control on type "stack" Apr 13, 2018
@deviantony
Copy link
Member

The response type is incorrect. I requested "application/json". As far as I saw there is already another bug mentioning that so ignore it here.

Indeed, #1808 was just fixed and should be available via portainer/portainer:develop.

The response is "200 OK" which says "[...] In a POST request, the response will contain an entity describing or containing the result of the action. [...]". But the response is empty.

Agree, the API reponse code should 204 instead of 200 when no content is actually returned.

Feel free to submit a PR for this.

We'll track the evolution to 204 for requests no returning content in this issue. I'll tackle the missing resource controls type in the documentation in another PR.

@deviantony
Copy link
Member

deviantony commented Apr 13, 2018

API documentation updated via #1812

Changes have been reflected on Swaggerhub.

@deviantony deviantony changed the title Buggy response when creating a new resource control on type "stack" Successful requests with intended empty body should return 204 Apr 14, 2018
@anthraxn8b
Copy link
Author

Info: Also empty body and 200 when updating stacks.

@deviantony deviantony added this to the 1.17.x milestone Jun 11, 2018
@deviantony
Copy link
Member

Closed via #1963

@deviantony deviantony modified the milestones: 1.17.x, 1.18.0 Jun 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api kind/enhancement Applied to Feature Requests
Projects
None yet
Development

No branches or pull requests

2 participants