-
Notifications
You must be signed in to change notification settings - Fork 26
feat(idempotency): add internal powertools JMESPath support #578
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(idempotency): add internal powertools JMESPath support #578
Conversation
…ternal JmesPath implementation. Add internal JmesPath implementation and tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://jmespath.org/specification.html#sort-by
Sort an array using an expression _expr as the sort key. For each element in the array of _resources, the _expr expression is applied and the resulting value is used as the key used when sorting the _resources.
If the result of evaluating the _expr against the current array _resources results in type other than a number or a string, an invalid-type error will occur.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://jmespath.org/specification.html#sort
This function accepts an array arg[0] argument and returns the sorted elements of the arg[0] as an array.
The array must be a list of strings or numbers. Sorting strings is based on code points. Locale is not taken into account.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://jmespath.org/specification.html#sum
Returns the sum of the provided array argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checks if it is number and first tries decimal and later double sum operation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://jmespath.org/specification.html#to-array
If:
- array - Returns the passed in value.
- number/string/object/boolean - Returns a one element array containing the passed in argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://jmespath.org/specification.html#to-number
- string - Returns the parsed number. Any string that conforms to the json-number production is supported. Note that the floating number support will be implementation specific, but implementations should support at least IEEE 754-2008 binary64 (double precision) numbers, as this is generally available and widely used.
- number - Returns the passed in value.
- array - null
- object - null
- boolean - null
- null - null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://jmespath.org/specification.html#to-string
- string - Returns the passed in value.
- number/array/object/boolean - The JSON encoded value of the object. The JSON encoder should emit the encoded JSON value without adding any additional new lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://jmespath.org/specification.html#type
Returns the JavaScript type of the given arg[0] argument as a string value.
The return value MUST be one of the following:
- number
- string
- boolean
- array
- object
- null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://jmespath.org/specification.html#values
Returns the values of the provided object. Note that because JSON hashes are inheritently unordered, the values associated with the provided object obj are inheritently unordered. Implementations are not required to return values in any specific order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the main parser. The file was not modified from the original code. Also similar implementation from the c++ repository https://github.com/danielaparker/jsoncons/blob/master/include/jsoncons/json_parser.hpp
This class is responsible for parsing the string containing the JMESPath expression and creating a stack with the correct objects (Functions, Expressions, Comparers) when a token is found.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Provides functionality for applying a JMESPath expression to transform a JSON document
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://jmespath.org/specification.html#slices
A slice expression allows you to select a contiguous subset of an array. A slice has a start, stop, and step value. The general form of a slice is [start:stop:step], but each component is optional and can be omitted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some tests/examples of using JMESPath
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Full JMesPath tests. There are multiple test files in the test_files folder.
These test files are in the format given and the cases to test
- given is the Json payload
- cases are the JMESTPath expressions and the expected result
The tests will look into these files and compare the expected result with the result of the JMESPath operation result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ready to review, added comments.
Unfortunately GitHub does not do a good job when pushing new commits and removes (outdated) comments from the files changed, best option is to go through the comments here in the conversations tab or in the files changed tab click on the conversations to view old ones (previous commit)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just some nitpick suggestions
libraries/src/AWS.Lambda.Powertools.JMESPath/Expressions/BaseExpression.cs
Outdated
Show resolved
Hide resolved
libraries/src/AWS.Lambda.Powertools.Idempotency/Persistence/BasePersistenceStore.cs
Outdated
Show resolved
Hide resolved
libraries/src/AWS.Lambda.Powertools.Idempotency/Persistence/BasePersistenceStore.cs
Outdated
Show resolved
Hide resolved
libraries/src/AWS.Lambda.Powertools.JMESPath/JsonTransformer.cs
Outdated
Show resolved
Hide resolved
|
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()
, andpowertools_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:
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.