aws-powertools / powertools-lambda-dotnet

Powertools is a developer toolkit to implement Serverless best practices and increase developer velocity.
https://docs.powertools.aws.dev/lambda/dotnet/
MIT No Attribution
152 stars 24 forks source link

feat(idempotency): add internal powertools JMESPath support #578

Closed hjgraca closed 4 months ago

hjgraca commented 4 months ago

Description of your changes

This PR introduces support for Powertools internal JMESPath functions to the Idempotency utility. This PR will remove the 3rd party dependency of JMESPath.NET thus strengthening our project to supply chain attacks and 3rd party maintainers.

With this new feature customers can use the powertools_json(), powertools_base64(), and powertools_base64_gzip() custom functions to deserialize encoded payloads and use the values within them as idempotency key.

This is especially useful when working with API Gateway or SQS messages among others, since oftentimes the customer defined part of the payload is encoded as JSON stringified object or base64 encoded value:

 {
  "body": "eyJjdXN0b21lcklkIjoiZGQ0NjQ5ZTYtMjQ4NC00OTkzLWFjYjgtMGY5MTIzMTAzMzk0In0=",
  "deeply_nested": [
    {
      "some_data": [
        1,
        2,
        3
      ]
    }
  ]
}
var transformer = JsonTransformer.Parse("powertools_base64(body).customerId");
using var result = transformer.Transform(doc.RootElement);
Logger.LogInformation(result.RootElement.GetRawText()); // "dd4649e6-2484-4993-acb8-0f9123103394"

The feature is added by having the Idempotency utility take a dependency on the new AWS.Lambda.Powertools.JMESPath project and replacing the existing, JMESPath.NET external dependency.

To be discussed if we should release AWS.Lambda.Powertools.JMESPath as a new NuGet package, so people can use it outside Idempotency utility.

Related issues, RFCs

Issue number: #568

Checklist


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

sonarcloud[bot] commented 4 months ago

Quality Gate Passed Quality Gate passed

Issues
3 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
2.0% Duplication on New Code

See analysis details on SonarCloud

codecov[bot] commented 4 months ago

Codecov Report

Attention: Patch coverage is 72.32741% with 950 lines in your changes are missing coverage. Please review.

Project coverage is 72.58%. Comparing base (5bc87a0) to head (c744870).

Files Patch % Lines
...c/AWS.Lambda.Powertools.JMESPath/JmesPathParser.cs 88.67% 87 Missing and 45 partials :warning:
...Lambda.Powertools.JMESPath/Values/ValueComparer.cs 13.33% 49 Missing and 3 partials :warning:
....JMESPath/Utilities/JsonElementEqualityComparer.cs 32.39% 40 Missing and 8 partials :warning:
...raries/src/AWS.Lambda.Powertools.JMESPath/Token.cs 64.81% 31 Missing and 7 partials :warning:
...owertools.JMESPath/Values/ValueEqualityComparer.cs 44.77% 32 Missing and 5 partials :warning:
...S.Lambda.Powertools.JMESPath/Values/DoubleValue.cs 0.00% 34 Missing :warning:
...ambda.Powertools.JMESPath/Functions/SumFunction.cs 46.66% 20 Missing and 4 partials :warning:
...Powertools.JMESPath/Expressions/SliceProjection.cs 65.15% 18 Missing and 5 partials :warning:
...WS.Lambda.Powertools.JMESPath/Values/ArrayValue.cs 61.40% 22 Missing :warning:
....Powertools.JMESPath/Functions/EvaluateMinMaxBy.cs 53.33% 15 Missing and 6 partials :warning:
... and 66 more
Additional details and impacted files ```diff @@ Coverage Diff @@ ## develop #578 +/- ## =========================================== - Coverage 72.91% 72.58% -0.33% =========================================== Files 109 190 +81 Lines 4489 7901 +3412 Branches 455 851 +396 =========================================== + Hits 3273 5735 +2462 - Misses 1087 1873 +786 - Partials 129 293 +164 ``` | [Flag](https://app.codecov.io/gh/aws-powertools/powertools-lambda-dotnet/pull/578/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aws-powertools) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/aws-powertools/powertools-lambda-dotnet/pull/578/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aws-powertools) | `72.58% <72.32%> (-0.33%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aws-powertools#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.