in samtranslator/open_api/open_api.py [0:0]
def is_integration_function_logical_id_match(self, path_name, method_name, logical_id): # type: ignore[no-untyped-def]
"""
Returns True if the function logical id in a lambda integration matches the passed
in logical_id.
If there are conditionals (paths, methods, uri), returns True only
if they all match the passed in logical_id. False otherwise.
If the integration doesn't exist, returns False
:param path_name: name of the path
:param method_name: name of the method
:param logical_id: logical id to compare against
"""
if not self.has_integration(path_name, method_name):
return False
method_name = self._normalize_method_name(method_name)
for method_definition in self.iter_on_method_definitions_for_path_at_method(path_name, method_name, False):
integration = method_definition.get(self._X_APIGW_INTEGRATION, Py27Dict())
if not isinstance(integration, dict):
raise InvalidDocumentException(
[
InvalidTemplateException(
f"Value of '{self._X_APIGW_INTEGRATION}' must be a dictionary according to Swagger spec."
)
]
)
# Extract the integration uri out of a conditional if necessary
uri = integration.get("uri")
if not isinstance(uri, dict):
return False
for uri_content in self.get_conditional_contents(uri):
arn = uri_content.get("Fn::Sub", "")
# Extract lambda integration (${LambdaName.Arn}) and split ".Arn" off from it
regex = r"([A-Za-z0-9]+\.Arn)"
matches = re.findall(regex, arn)
# Prevent IndexError when integration URI doesn't contain .Arn (e.g. a Function with
# AutoPublishAlias translates to AWS::Lambda::Alias, which make_shorthand represents
# as LogicalId instead of LogicalId.Arn).
# TODO: Consistent handling of Functions with and without AutoPublishAlias (see #1901)
if not matches or matches[0].split(".Arn")[0] != logical_id:
return False
return True