Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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': []})
# 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)})
operationId: 'deleteFunction'
parameters:
- name: 'request'
in: body
"""
arn = func_arn(function)
# Stop/remove any containers that this arn uses.
LAMBDA_EXECUTOR.cleanup(arn)
try:
arn_to_lambda.pop(arn)
except KeyError:
return not_found_error(func_arn(function))
event_publisher.fire_event(event_publisher.EVENT_LAMBDA_DELETE_FUNC,
payload={'n': event_publisher.get_hash(function)})
i = 0
while i < len(event_source_mappings):
mapping = event_source_mappings[i]
if mapping['FunctionArn'] == arn:
del event_source_mappings[i]
i -= 1
i += 1
result = {}
return jsonify(result)
def forward_request(self, method, path, data, headers):
if method == 'OPTIONS':
return 200
req_data = None
if method == 'POST' and path == '/':
req_data = urlparse.parse_qs(to_str(data))
req_data = dict([(k, v[0]) for k, v in req_data.items()])
action = req_data.get('Action')
stack_name = req_data.get('StackName')
if action == 'CreateStack':
event_publisher.fire_event(event_publisher.EVENT_CLOUDFORMATION_CREATE_STACK,
payload={'n': event_publisher.get_hash(stack_name)})
if action == 'DeleteStack':
client = aws_stack.connect_to_service('cloudformation')
stack_resources = client.list_stack_resources(StackName=stack_name)['StackResourceSummaries']
template_deployer.delete_stack(stack_name, stack_resources)
if action == 'DescribeStackEvents':
# fix an issue where moto cannot handle ARNs as stack names (or missing names)
run_fix = not stack_name
if stack_name:
if stack_name.startswith('arn:aws:cloudformation'):
run_fix = True
stack_name = re.sub(r'arn:aws:cloudformation:[^:]+:[^:]+:stack/([^/]+)(/.+)?',
r'\1', stack_name)
if run_fix:
def stop_infra():
if common.INFRA_STOPPED:
return
common.INFRA_STOPPED = True
event_publisher.fire_event(event_publisher.EVENT_STOP_INFRA)
generic_proxy.QUIET = True
common.cleanup(files=True, quiet=True)
common.cleanup_resources()
lambda_api.cleanup()
time.sleep(2)
# TODO: optimize this (takes too long currently)
def publish_event(time_before, result, kwargs):
event_publisher.fire_event(
event_publisher.EVENT_LAMBDA_INVOKE_FUNC,
payload={'f': _func_name(kwargs), 'd': now_utc() - time_before, 'r': result[0]})
attributes = get_subscribe_attributes(req_data)
sub_arn = response_data['SubscribeResponse']['SubscribeResult']['SubscriptionArn']
do_subscribe(
topic_arn,
req_data['Endpoint'][0],
req_data['Protocol'][0],
sub_arn,
attributes,
filter_policy
)
if req_action == 'CreateTopic' and response.status_code < 400:
response_data = xmltodict.parse(response.content)
topic_arn = response_data['CreateTopicResponse']['CreateTopicResult']['TopicArn']
do_create_topic(topic_arn)
# publish event
event_publisher.fire_event(event_publisher.EVENT_SNS_CREATE_TOPIC,
payload={'t': event_publisher.get_hash(topic_arn)})
if req_action == 'DeleteTopic' and response.status_code < 400:
# publish event
topic_arn = (req_data.get('TargetArn') or req_data.get('TopicArn'))[0]
event_publisher.fire_event(event_publisher.EVENT_SNS_DELETE_TOPIC,
payload={'t': event_publisher.get_hash(topic_arn)})