-
Notifications
You must be signed in to change notification settings - Fork 104
Add filterSensitiveLog for Union types #190
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 for Union types #190
Conversation
Converted to draft as it's blocked on #191 |
7b70ddf
to
2f8681f
Compare
...-codegen/src/main/java/software/amazon/smithy/typescript/codegen/StructuredMemberWriter.java
Outdated
Show resolved
Hide resolved
writer.write("};"); | ||
} | ||
} | ||
writer.write("if (${1L}.$$unknown !== undefined) return {[${1L}.$$unknown[0]]: ${1L}.$$unknown[1]};", |
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.
You may want to not log the value of an unknown union member, as there's no way to know if it is sensitive or not.
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.
Logged the value of an unknown union member as 'UNKNOWN'
in 0382f0e
...pescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/UnionGenerator.java
Outdated
Show resolved
Hide resolved
...pescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/UnionGenerator.java
Outdated
Show resolved
Hide resolved
Shape memberTarget = model.expectShape(member.getTarget()); | ||
String memberName = symbolProvider.toMemberName(member); | ||
|
||
if (member.getMemberTrait(model, SensitiveTrait.class).isPresent()) { |
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.
A lot of this code, specifically the branching, looks similar to that of writing this function for structures (StructuredMemberWriter.writeFilterSensitiveLog
.) Can it be consolidated cleanly at all?
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.
Can it be consolidated cleanly at all?
I'm open to suggestions for modifications.
The branching can't be consolidated between Union and Structure, as there's a check for SimpleShape in case of CollectionShape/MapShape members in case of Union which doesn't exist in latter.
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.
Consolidated by creating new method writeMemberFilterSensitiveLog in e1fd23c, and calling it from Union in e5361be 🎉
It was done by moving SimpleShape check inside write<Collection|Map>FilterSensitiveLog
It's redundant for Structure as it'll never reach because of isMemberOverwriteRequired call, but is required for Union.
|
||
@sensitive | ||
sensitiveBar: String | ||
} |
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.
Can you please add newlines to the end of these files? There are quite a few without them.
If you use IntelliJ, you can set this automatically under Preferences -> Editor -> General -> Ensure an empty line at the end of a file on Save
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.
Added in commit 481a425
b67715f
to
0382f0e
Compare
String itemParam = "item"; | ||
Shape collectionMemberTarget = model.expectShape(collectionMember.getTarget()); | ||
writer.write("$L => ", itemParam); | ||
if (collectionMemberTarget.isStructureShape() || collectionMemberTarget.isUnionShape()) { |
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 looks really similar to the code in writeMemberFilterSensitiveLog
, is it possible to refactor this chunk of if/else
to instead use that? I might be missing something, but the final else
is the only thing that looks different to me here.
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.
The purpose of the else
block is to throw CodegenException in case redundant code is being written for provided models at Runtime for SimpleShape.
But let me verify that in a Unit test instead, and reuse code from writeMemberFilterSensitiveLog
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.
But let me verify that in a Unit test instead, and reuse code from
writeMemberFilterSensitiveLog
Code reused in commit 4d94416
Unit test test-insensitive-list
already checks for redundant code not being present.
writer.write("...$L,", accParam); | ||
Shape mapMemberTarget = model.expectShape(mapMember.getTarget()); | ||
writer.openBlock("[$L]: ", ",", keyParam, () -> { | ||
if (mapMemberTarget.isStructureShape() || mapMemberTarget.isUnionShape()) { |
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 looks really similar to the code in writeMemberFilterSensitiveLog
, is it possible to refactor this chunk of if/else
to instead use that? I might be missing something, but the final else
is the only thing that looks different to me here.
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.
Done in commit 4d94416
Can be fixed by adding es2017 in lib https://stackoverflow.com/questions/45422573 But waiting for root TSConfig to be pushed
e5361be
to
4d94416
Compare
* Add writeFilterSensitiveLog to UnionGenerator with check for sensitive member * Return $undefined if no value matched in filterSensitiveLog * Remove fromEntries as TSConfig doesn't have it on type ObjectConstructor Can be fixed by adding es2017 in lib https://stackoverflow.com/questions/45422573 But waiting for root TSConfig to be pushed * Non-sensitive SimpleShape in Union.filterSensitiveLog * Add check for obj.$unknown defined in Union.filterSensitiveLog * Call writeStructureFilterSensitiveLog from Union * Union.filterSensitiveLog for complex members * Add check for UnionShape in filterSensitiveLog * Update documentation for UnionGenerator * Add newlines within Union components * Fix checkstyle errors * Test callsFilterForUnionWithSensitiveData * Test callsFilterInUnionWithSensitiveData * Test filtersSensitiveUnion * Test callsFilterForUnionWithoutSensitiveData * Test callsFilterInUnionWithoutSensitiveData * rename test-insensitive-structure * Test filtersSensitiveMemberPointingToUnion * Test callsFilterForListWithUnionWithSensitiveData * Test callsFilterInListWithUnionWithSensitiveData * Test callsFilterForMapWithUnionWithSensitiveData * Test callsFilterInMapWithUnionWithSensitiveData * Fix ordering of objects in callsFilterInUnionWithoutSensitiveData * Remove unused memberTarget instanceof UnionShape * Disable filterSensitiveLog for event stream * Rename STREAMING_TRAIT to STREAMING_CONTENT * Log unknown union member as 'UNKNOWN' * Use isStructureShape() and isUnionShape() instead of instanceof * Added newline at the end of .smithy test files * Add tests for complex shapes inside Union * Create new function writeMemberFilterSensitiveLog * Call writeMemberFilterSensitiveLog from Union * Call writeMemberFilterSensitiveLog from Collection/Member * Throw CodegenException in the else block of writeMemberFilterSensitiveLog
Issue #, if available:
Follow up #170
Description of changes:
This PR adds filterSensitiveLog for Union types
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.