def convert_flask_to_httpretty_response_call(*args, **kwargs): try: return convert_flask_to_httpretty_response_call_orig( *args, **kwargs) except NotImplementedError as e: action = request.headers.get("X-Amz-Target") action = action or f"{request.method} {urlparse(request.url).path}" if action == "POST /": # try to extract action from exception string match = re.match( r"The ([a-zA-Z0-9_-]+) action has not been implemented", str(e)) if match: action = snake_to_camel_case(match.group(1)) service = extract_service_name_from_auth_header(request.headers) msg = f"API action '{action}' for service '{service}' not yet implemented" response = requests_error_response(request.headers, msg, code=501) if config.MOCK_UNIMPLEMENTED: is_json = is_json_request(request.headers) headers = { HEADER_CONTENT_TYPE: APPLICATION_JSON if is_json else APPLICATION_XML } content = "{}" if is_json else "<Response />" # TODO: return proper mocked response response = requests_response(content, headers=headers) LOG.info( f"{msg}. Returning mocked response due to MOCK_UNIMPLEMENTED=1" ) else: LOG.info(msg) # TODO: publish analytics event ... return requests_to_flask_response(response)
def _response(action, result): if isinstance(result, (dict, str)): result = requests_response_xml(action, result, xmlns=XMLNS_CF) if isinstance(result, Response): result = requests_to_flask_response(result) return result