-
Notifications
You must be signed in to change notification settings - Fork 394
Description
Observed
When an enterprise only endpoint is accessed by HVAC and the vault server is not licenced. it will return a specific response of "enterprise-only feature" with a status-code 404.
Expected result
I expect a differentiation between a route that is valid but not accessable versus a route that does not exist, either by warning or exception.
Actual result and reasoning why
In most cases HVAC returns Null. as observed here
Lines 251 to 252 in 097bfde
| except exceptions.InvalidPath: | |
| return None |
Lines 237 to 238 in 097bfde
| except exceptions.InvalidPath: | |
| return None |
The deeper problem however lies in the Adapter:
When a non-OK status is returned, in this case our 404 with the error message. it will be captured here:
Lines 339 to 340 in 097bfde
| if not response.ok and (raise_exception and not self.ignore_exceptions): | |
| self._raise_for_error(method, url, response) |
then it goes into the raise for error code and gets classified as a
InvallidPath exception.
Possible solution
We could add a check on the 404 + specific message to differentiate between the two states in the VaultError from_status code here:
Lines 20 to 33 in 2d2c80e
| def from_status(cls, status_code: int, *args, **kwargs): | |
| _STATUS_EXCEPTION_MAP = { | |
| 400: InvalidRequest, | |
| 401: Unauthorized, | |
| 403: Forbidden, | |
| 404: InvalidPath, | |
| 429: RateLimitExceeded, | |
| 500: InternalServerError, | |
| 501: VaultNotInitialized, | |
| 502: BadGateway, | |
| 503: VaultDown, | |
| } | |
| return _STATUS_EXCEPTION_MAP.get(status_code, UnexpectedError)(*args, **kwargs) |
Or; we could adjust the except catch statements where
Null is only send when the message does not contain enterprise-only.
Would love to help out with the implementation if needed, let me know if this would be implementable and which is the preferred approach.
I personally would prefer the former for example like this:
....
503: VaultDown,
}
exception = _STATUS_EXCEPTION_MAP.get(status_code, UnexpectedError)
if status_code == 404 and kwargs["message"].contains("enterprise-only"):
exception = EnterpriseError
return exception(*args, **kwargs)in that case the existing Null checks do not have to be adjusted.