-
Notifications
You must be signed in to change notification settings - Fork 84
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
Add filterSensitiveLog method to Structure namespaces #170
Conversation
f895273
to
74b5da0
Compare
CodeGen PR aws/aws-sdk-js-v3#1130 |
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's a lot of duplicate type checking, casting, and iteration logic in these methods. It also looks like some instances where isIterationRequired
might need to be used are dropped because of this.
You can reduce this surface by implementing a ShapeVisitor.Default<Void>
that writes and recurses only for shapes that sensitive iteration is required. It would look loosely similar to the SmithyIdlModelSerializer
and recurse using something like memberTarget.accept(this);
.
...-codegen/src/main/java/software/amazon/smithy/typescript/codegen/StructuredMemberWriter.java
Outdated
Show resolved
Hide resolved
...-codegen/src/main/java/software/amazon/smithy/typescript/codegen/StructuredMemberWriter.java
Outdated
Show resolved
Hide resolved
...-codegen/src/main/java/software/amazon/smithy/typescript/codegen/StructuredMemberWriter.java
Outdated
Show resolved
Hide resolved
...-codegen/src/main/java/software/amazon/smithy/typescript/codegen/StructuredMemberWriter.java
Outdated
Show resolved
Hide resolved
...-codegen/src/main/java/software/amazon/smithy/typescript/codegen/StructuredMemberWriter.java
Outdated
Show resolved
Hide resolved
31100ca
to
54d883b
Compare
Any Shape has to be call filterSensitiveLog for its members which are not of SimpleShape type, as the work of filtering sensitive values is delegated to the members. Using a ShapeVisitor won't help in this case. From the TypeScript playground example of array of objects, the |
The purpose of
Can you share an example where |
...-codegen/src/main/java/software/amazon/smithy/typescript/codegen/StructuredMemberWriter.java
Outdated
Show resolved
Hide resolved
Noticed while writing TypeScript playground https://tiny.amazon.com/f5o7auri
65be8e6
to
e00a880
Compare
...-codegen/src/main/java/software/amazon/smithy/typescript/codegen/StructuredMemberWriter.java
Outdated
Show resolved
Hide resolved
...-codegen/src/main/java/software/amazon/smithy/typescript/codegen/StructuredMemberWriter.java
Outdated
Show resolved
Hide resolved
...-codegen/src/main/java/software/amazon/smithy/typescript/codegen/StructuredMemberWriter.java
Outdated
Show resolved
Hide resolved
...ript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/StructureGenerator.java
Outdated
Show resolved
Hide resolved
...-codegen/src/main/java/software/amazon/smithy/typescript/codegen/StructuredMemberWriter.java
Outdated
Show resolved
Hide resolved
...-codegen/src/main/java/software/amazon/smithy/typescript/codegen/StructuredMemberWriter.java
Outdated
Show resolved
Hide resolved
...-codegen/src/main/java/software/amazon/smithy/typescript/codegen/StructuredMemberWriter.java
Outdated
Show resolved
Hide resolved
...-codegen/src/main/java/software/amazon/smithy/typescript/codegen/StructuredMemberWriter.java
Outdated
Show resolved
Hide resolved
fd24896
to
1bb22be
Compare
f0dbe61
to
9a31c3d
Compare
...-codegen/src/test/java/software/amazon/smithy/typescript/codegen/StructureGeneratorTest.java
Show resolved
Hide resolved
...-codegen/src/main/java/software/amazon/smithy/typescript/codegen/StructuredMemberWriter.java
Outdated
Show resolved
Hide resolved
...-codegen/src/main/java/software/amazon/smithy/typescript/codegen/StructuredMemberWriter.java
Outdated
Show resolved
Hide resolved
...-codegen/src/test/java/software/amazon/smithy/typescript/codegen/StructureGeneratorTest.java
Show resolved
Hide resolved
...-codegen/src/main/java/software/amazon/smithy/typescript/codegen/StructuredMemberWriter.java
Show resolved
Hide resolved
...test/resources/software/amazon/smithy/typescript/codegen/test-map-with-sensitive-data.smithy
Show resolved
Hide resolved
* Add basic toString function * Add REDACTED to member if it has SensitiveTrait * Use getMemberTrait to find SensitiveTrait * Move code to StructuredMemberWriter * Add SENSITIVE_STRING for optional members only if they're present * chore: remove isRequired check as all members are either undefined or optional * feat: call toString on Structures * chore: rename toString to filterSensitiveLog * feat: add filterSensitiveLog for Array * feat: added support for list of lists * Move map open and end outside if-else block * Fix issues with writeFilterSensitiveLogForArray Noticed while writing TypeScript playground https://tiny.amazon.com/f5o7auri * Fix java.lang.StackOverflowError * Simplify code by storing member shape in memberShape * Use openBlock instead of write * Pass arrayMember in writeFilterSensitiveLogForArray * Fix bug with Array<Array<SimpleShape>> * filterSensitiveLog for MapShape inside Structure * Move reducer function definition outside memberShape comparison * Remove redundant code by doing iteration only for some shapes * Recursively call isIterationRequired to remove redundant code * filterSensitiveLog for Map inside Collection * Explicitly return any from filterSensitiveLog method * filterSensitiveLog for Collection inside Map * filterSensitiveLog for Map inside Map * Fix bug in filterSensitiveLog for Map of Map * chore: rename writeFilterSensitiveLogFor<X> to write<X>FilterSensitiveLog * Simplified method isIterationRequired * Add period at the end of comments * Removed braces for variable writes * Used positional parameters in write() calls * Use destructuring in writeMapFilterSensitiveLog * Throw error in filterSensitiveLog where the path should never reach * Make writeX methods private * Add writeStructureFilterSensitiveLog * Edge case for collection with sensitive trait * Edge case for map with Sensitive trait * Refactor to simplify code * Rename config -> structuredMemberWriter * Move writeFilterSensitiveLog above private functions * Remove shape from writeFilterSensitiveLog * Rename memberShape to memberTarget * Create getSanitizedMemberName method * Fix for ./gradlew test to be successful * Add tests for filterSensitiveLog * Updated documentation to clarify getSanitizedMemberName * Use structureTarget.hasTrait in writeStructureFilterSensitiveLog * Added tests for callsFilterIn<X>WithSensitiveData * Modify tests for sensitive List/Map/Structure * Add tests for member pointing to sensitive structure/list/map
Issue #, if available:
N/A
Description of changes:
This PR covers all cases for filterSensitiveLogs
Testing done prior to code change on TypeScript playground:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.