def return_response(self, method, path, data, headers, response): # fix backend issue (missing support for API documentation) if re.match(r'/restapis/[^/]+/documentation/versions', path): if response.status_code == 404: return requests_response({'position': '1', 'items': []}) # add missing implementations if response.status_code == 404: data = data and json.loads(to_str(data)) result = None if path == '/account': result = handle_accounts(method, path, data, headers) if path.startswith('/vpclinks'): result = handle_vpc_links(method, path, data, headers) if re.match(PATH_REGEX_PATH_MAPPINGS, path): result = hande_base_path_mappings(method, path, data, headers) if result is not None: response.status_code = 200 aws_responses.set_response_content( response, result, getattr(result, 'headers', {})) # publish event if method == 'POST' and path == '/restapis': content = json.loads(to_str(response.content)) event_publisher.fire_event( event_publisher.EVENT_APIGW_CREATE_API, payload={'a': event_publisher.get_hash(content['id'])}) api_regex = r'^/restapis/([a-zA-Z0-9\-]+)$' if method == 'DELETE' and re.match(api_regex, path): api_id = re.sub(api_regex, r'\1', path) event_publisher.fire_event( event_publisher.EVENT_APIGW_DELETE_API, payload={'a': event_publisher.get_hash(api_id)})
def return_response(self, method, path, data, headers, response): # fix backend issue (missing support for API documentation) if re.match(r"/restapis/[^/]+/documentation/versions", path): if response.status_code == 404: return requests_response({"position": "1", "items": []}) # add missing implementations if response.status_code == 404: data = data and json.loads(to_str(data)) result = None if path == "/account": result = handle_accounts(method, path, data, headers) elif path.startswith("/vpclinks"): result = handle_vpc_links(method, path, data, headers) elif re.match(PATH_REGEX_PATH_MAPPINGS, path): result = handle_base_path_mappings(method, path, data, headers) elif re.match(PATH_REGEX_CLIENT_CERTS, path): result = handle_client_certificates(method, path, data, headers) if result is not None: response.status_code = 200 aws_responses.set_response_content( response, result, getattr(result, "headers", {})) # keep track of API regions for faster lookup later on if method == "POST" and path == "/restapis": content = json.loads(to_str(response.content)) api_id = content["id"] region = aws_stack.extract_region_from_auth_header(headers) API_REGIONS[api_id] = region # publish event if method == "POST" and path == "/restapis": content = json.loads(to_str(response.content)) event_publisher.fire_event( event_publisher.EVENT_APIGW_CREATE_API, payload={"a": event_publisher.get_hash(content["id"])}, ) api_regex = r"^/restapis/([a-zA-Z0-9\-]+)$" if method == "DELETE" and re.match(api_regex, path): api_id = re.sub(api_regex, r"\1", path) event_publisher.fire_event( event_publisher.EVENT_APIGW_DELETE_API, payload={"a": event_publisher.get_hash(api_id)}, )