Skip to content

Conversation

@mndeveci
Copy link
Contributor

Issue #, if available:
N/A

Description of changes:
When setting path for default authorizers, SAM Transform tries to access specific method information from path definition inside swagger in this line; https://github.com/aws/serverless-application-model/blob/develop/samtranslator/swagger/swagger.py#L534

Since it is trying to access this dictionary directly, it might raise exception when a method is defined in function's event definition but not in swagger definition.

Description of how you validated changes:
Before setting up path for default authorizer, we first try to see if that path has the expected method definition, if not we are going to raise an invalid document exception rather than getting item not found exception from dictionary.

Checklist:

  • Write/update tests
  • make pr passes
  • Update documentation
  • Verify transformed template deploys and application functions as expected

Examples?

Please reach out in the comments, if you want to add an example. Examples will be
added to sam init through https://github.com/awslabs/aws-sam-cli-app-templates/

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link
Contributor

@hawflau hawflau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

normalized_method_name = self._normalize_method_name(method_name)
# It is possible that the method could have two definitions in a Fn::If block.
for method_definition in self.get_method_contents(self.get_path(path)[normalized_method_name]):
method_dict = self.get_path(path).get(normalized_method_name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some additional questions which may have already been considered.

can normalized_method_name be anything other than a string?
can path be anything other than a string?

Could we have intrinsics which resolve each of them to a dict instead of a string?

@mndeveci
Copy link
Contributor Author

Thanks for the reviews everyone, I find out that Ahmed has an earlier PR which is addressing same issue in a different way. Since it is not polluting our code with extra validation and using what information we have there, I would suggest to move forward with that. You can check it here; #2031

Closing this PR.

@mndeveci mndeveci closed this Jun 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants