Add handler for Bad Request error during Vault authentication
Vault returns Bad Request error if invalid secret ID is provided. It's
better to have such errors handled instad of generic "KeyError: 'auth'"
execption.
Change-Id: Ibc068af70de4022f544d394ec4b014443a9c16b5
Ivan Kolodyazhny
3 years ago
172 | 172 | if resp.status_code == requests.codes['forbidden']: |
173 | 173 | raise exception.Forbidden() |
174 | 174 | |
175 | resp = resp.json() | |
176 | self._cached_approle_token_id = resp['auth']['client_token'] | |
175 | resp_data = resp.json() | |
176 | ||
177 | if resp.status_code == requests.codes['bad_request']: | |
178 | raise exception.KeyManagerError(', '.join(resp_data['errors'])) | |
179 | ||
180 | self._cached_approle_token_id = resp_data['auth']['client_token'] | |
177 | 181 | self._approle_token_issue = token_issue_utc |
178 | self._approle_token_ttl = resp['auth']['lease_duration'] | |
182 | self._approle_token_ttl = resp_data['auth']['lease_duration'] | |
179 | 183 | return {'X-Vault-Token': self._approle_token_id} |
180 | 184 | |
181 | 185 | return {} |