salt icon indicating copy to clipboard operation
salt copied to clipboard

salt-api local_async HTTP status 200 vs 201 vs 202

Open kevinquinnyo opened this issue 10 years ago • 4 comments

Description of Issue/Question

This is not a critical issue at all. I just happened to notice that when issuing a salt-api request with client=local_async, the HTTP status is 200. I am not sure at all, but at first glance, it seems like the more technically appropriate HTTP response would be either 201 Created, or 202 Accepted. (I'm not sure which?)

The reasoning is that when using local_async, salt-api's response body contains a jid (job id) which is technically a newly created resource of the /jobs api one could argue.

https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

This truly doesn't affect me in any way, but I just thought I would make note of it in case it does matter to someone.

Keep in mind that changing this has a small potential for breaking backwards compatibility, for example if someone has a project that utilizes salt-api and does something like if status_code == 200: #...

Setup

Just need salt-api running to test this.

Steps to Reproduce Issue

curl https://salt-master.your-server.com/ \
  -X POST \
  --data-urlencode "client=local_async" \
  --data-urlencode "fun=cmd.run" \
  --data-urlencode "tgt=web1-*" \
  --data-urlencode "arg=sleep 20 && echo OK" \
  -H 'X-Auth-Token: this-is-an-auth-token' \
  -w "%{http_code}"

Versions Report

( I know I need to update ) Salt Version: Salt: 2015.8.8.2

Dependency Versions: Jinja2: 2.8 M2Crypto: Not Installed Mako: 0.9.1 PyYAML: 3.11 PyZMQ: 14.0.1 Python: 2.7.6 (default, Jun 22 2015, 17:58:13) RAET: Not Installed Tornado: 4.2.1 ZMQ: 4.0.4 cffi: 1.7.0 cherrypy: 3.2.2 dateutil: 1.5 gitdb: 0.5.4 gitpython: 0.3.2 RC1 ioflo: Not Installed libgit2: Not Installed libnacl: Not Installed msgpack-pure: Not Installed msgpack-python: 0.3.0 mysql-python: 1.2.3 pycparser: 2.14 pycrypto: 2.6.1 pygit2: Not Installed python-gnupg: Not Installed smmap: 0.8.2 timelib: Not Installed

System Versions: dist: Ubuntu 14.04 trusty machine: x86_64 release: 3.13.0-45-generic system: Ubuntu 14.04 trusty

kevinquinnyo avatar Aug 26 '16 17:08 kevinquinnyo

Well said. I agree. 😄

I'm reluctant to change the existing interfaces for the reason that you mentioned. This behavior has been out in the wild for ~4 years now. There's always the chance that new async interfaces will be added, for example an endpoint that adds the job metadata to the return has been requested. This would be a good change for any new work done.

whiteinge avatar Aug 26 '16 20:08 whiteinge

I understand the reluctance to change the code for 4 years but I think it is always earlier than later for this type of case. If we wait another 4 years and all the upstream logic are built up solid to expect 200 from POST, it will be extremely difficult at that point.

So, let me know if you need any help 😄 @whiteinge

hu-dabao avatar Aug 26 '16 22:08 hu-dabao

Thanks for the offer @hu-dabao but I don't think there's a compelling enough reason to change it at all -- now or four years from now. The reason is a 200 response is not incorrect. A 201 or 202 would be more specific, and thus preferable, but the current behavior is plenty usable.

whiteinge avatar Aug 27 '16 22:08 whiteinge

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

stale[bot] avatar Jun 25 '18 14:06 stale[bot]