def make_json_response(data, status_code=200, add_headers=None): """Make json response from response data. """ if data is not None: if current_app.config['AUDIT_VERBOSITY'] > 0: if status_code >= 400 and 'message' in data: g.audit_data['message'] = data['message'] if current_app.config.get('PRETTY_PRINT_JSON'): data = json.dumps(data, indent=4, sort_keys=True, default=_json_default) data += '\n' else: data = json.dumps(data, separators=(',', ':'), default=_json_default) else: data = "" response = current_app.make_response((data, status_code)) if add_headers: for header, value in add_headers: response.headers[header] = value response.headers['Content-Type'] = _JSON if is_authenticated(): response.headers['X-GD-Altai-Implementation'] = _IMPLEMENTATION return response
def get_v1_endpoint(): """Entry point for API v1""" if not auth.is_authenticated(): return make_json_response(v1_root) result = v1_root.copy() result['services'] = { 'keystone': app.config['KEYSTONE_URI'], 'nova-billing': _get_os_service_url('nova-billing') } return make_json_response(result)
def _exception_response(self, error, response, code, add_headers): if not isinstance(response, dict): # pragma: nocover response = { 'message': str(response) } response['path'] = flask.request.path response['method'] = flask.request.method tb_mode = self.config['TRACEBACK_IN_RESPONSE'] if tb_mode == 'always' or (tb_mode == 'auth_500' and code == 500 and auth.is_authenticated()): tb = _traceback_to_json(error) if tb: response['traceback'] = tb return make_json_response(response, code, add_headers)