hvac / hvac

:lock: Python 3.X client for HashiCorp Vault
https://python-hvac.org
Apache License 2.0
1.22k stars 385 forks source link

The JSON adapter should return an empty response on 204 rather than the response object #797

Open briantist opened 2 years ago

briantist commented 2 years ago

https://github.com/hvac/hvac/blob/ec048ded30d21c13c21cfa950d148c8bfc1467b0/hvac/adapters.py#L365-L371

On a 204 response, the entire response object is returned, but I think it should be an empty dict instead (or maybe None would be fine as well), to be more consistent, since Vault is known to return 204 responses when it has nothing to say, and that result is more appropriate to deal with as a client.

As an example, if I want to test for this case, I need to import requests and test the the type of the response, or I can try checking for a status_code field, but if the vault request returned some data with a status_code field, then I can't rely on that.

There's a number of workarounds I can think of to handle this, but it'd be better for this common response type to be handled by the adapter in a way that's friendlier to deal with on the client side.

briantist commented 2 years ago

A fix for this should also close out these I think: