Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add UnescapeMappingTemplate to state machine Api event #2495

Closed
wants to merge 7 commits into from
Closed

feat: add UnescapeMappingTemplate to state machine Api event #2495

wants to merge 7 commits into from

Conversation

hoffa
Copy link
Contributor

@hoffa hoffa commented Sep 10, 2022

Issue #, if available

#1895

Description of changes

Adds UnescapeMappingTemplate boolean to state machine Api event, which unescapes singles quotes in state machine input escaped by escapeJavaScript (which isn't valid JSON).

The final mapping template isn't JSON by design, so can't use json.dumps(). For example:

{"input": "$util.escapeJavaScript($input.json('$')).replaceAll("\\'","'")", "stateMachineArn": "arn:aws:states:us-east-1:792766875239:stateMachine:Post-n7ZKNljUJsZZ"}

Originally done in #2253, but using an opt-in property instead to avoid large-scale redeployments.

Description of how you validated changes

pytest integration --no-cov -k test_state_machine_with_api_single_quotes_input -s
pytest --no-cov samtranslator -n auto tests/translator/test_translator.py -k state_machine_with_api

Checklist

  • Add/update unit tests using:
  • Add/update integration tests
  • make pr passes
  • Update documentation
  • Verify transformed template deploys and application functions as expected
  • Do these changes include any template validations?
    • Did the newly validated properties support intrinsics prior to adding the validations? (If unsure, please review Intrinsic Functions before proceeding).
      • Does the pull request ensure that intrinsics remain functional with the new validations?

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.

@hoffa hoffa changed the title feat: add Unescape feat: add Unescape to AWS::Serverless::StateMachine Api event Sep 10, 2022
@hoffa hoffa changed the title feat: add Unescape to AWS::Serverless::StateMachine Api event feat: add Unescape to state machine Api event Sep 10, 2022
@codecov-commenter
Copy link

codecov-commenter commented Sep 10, 2022

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.51%. Comparing base (e7a1496) to head (1bd1d4f).
Report is 1099 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2495      +/-   ##
===========================================
+ Coverage    93.58%   94.51%   +0.93%     
===========================================
  Files           90       97       +7     
  Lines         6124     7311    +1187     
  Branches      1260     1526     +266     
===========================================
+ Hits          5731     6910    +1179     
- Misses         183      193      +10     
+ Partials       210      208       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@hoffa hoffa changed the title feat: add Unescape to state machine Api event feat: add UnescapeMappingTemplate to state machine Api event Sep 12, 2022
@hoffa hoffa marked this pull request as ready for review September 12, 2022 17:16
@@ -356,12 +357,18 @@ def _add_swagger_integration(self, api, resource, role, intrinsics_resolver):
if CONDITION in resource.resource_attributes:
condition = resource.resource_attributes[CONDITION]

request_template = (
self._generate_request_template_unescaped(resource)
if self.UnescapeMappingTemplate
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably a very rare use case - If this is a Fn::If, the new behavior will be used regardless (as SAM-T can't/doesn't resolve Fn::If). Is that wanted?

We had a similar discussion for PassthroughCondition under DeploymentPreference in #1578

Copy link
Contributor Author

@hoffa hoffa Nov 3, 2022

Choose a reason for hiding this comment

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

Doesn't

        "UnescapeMappingTemplate": PropertyType(False, is_type(bool)),

already guarantee it's a bool?

Edit: for posterity, no. We've deprecated PropertyType since it's a footgun and we don't need to resolve intrinsics anymore.

api_endpoint = stack_output.get("ApiEndpoint")

input_json = {"f'oo": {"hello": "'wor'l'd'''"}}
response = requests.post(api_endpoint, json=input_json)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add something similar to this so we will log the request too?

This will help us investigate in case of flaky test runs

@hoffa hoffa closed this by deleting the head repository Oct 12, 2022
@hoffa hoffa reopened this Oct 31, 2022
@hoffa hoffa closed this Nov 15, 2022
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.

3 participants