-
Notifications
You must be signed in to change notification settings - Fork 1k
(Thrift Field Masker Pt2) Implement field masking for thrift #6311
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
Merged
jrhee17
merged 11 commits into
line:main
from
jrhee17:feat/thrift-log-maskers-tproto-part2
Jul 28, 2025
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7fa60bf
remove redundant thrift files
jrhee17 b962556
remove the compare script
jrhee17 6dba570
implement field masking for thrift
jrhee17 052e677
Merge branch 'main' into feat/thrift-log-maskers-tproto-part2
jrhee17 7dfe95e
cleanup
jrhee17 0c2fc3b
cleanup
jrhee17 6feccb7
address comments by @ikhoon
jrhee17 e13279e
address comment by @ikhoon
jrhee17 7daa41f
Merge branch 'main' into feat/thrift-log-maskers-tproto-part2
jrhee17 41ade08
address comments by @minwoox
jrhee17 67a0386
address comments by @ikhoon
jrhee17 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
core/src/main/java/com/linecorp/armeria/internal/server/annotation/RpcRequestSerializer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /* | ||
| * Copyright 2025 LY Corporation | ||
| * | ||
| * LY Corporation licenses this file to you under the Apache License, | ||
| * version 2.0 (the "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at: | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| * License for the specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package com.linecorp.armeria.internal.server.annotation; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| import com.fasterxml.jackson.core.JsonGenerator; | ||
| import com.fasterxml.jackson.databind.JsonSerializer; | ||
| import com.fasterxml.jackson.databind.SerializerProvider; | ||
|
|
||
| import com.linecorp.armeria.common.RpcRequest; | ||
|
|
||
| final class RpcRequestSerializer extends JsonSerializer<RpcRequest> { | ||
|
|
||
| static final RpcRequestSerializer INSTANCE = new RpcRequestSerializer(); | ||
|
|
||
| @Override | ||
| public Class<RpcRequest> handledType() { | ||
| return RpcRequest.class; | ||
| } | ||
|
|
||
| @Override | ||
| public void serialize(RpcRequest value, JsonGenerator jsonGenerator, SerializerProvider serializers) | ||
| throws IOException { | ||
| jsonGenerator.writeStartObject(); | ||
| jsonGenerator.writeStringField("service", value.serviceName()); | ||
| jsonGenerator.writeStringField("method", value.method()); | ||
| jsonGenerator.writeArrayFieldStart("params"); | ||
| for (Object param : value.params()) { | ||
| jsonGenerator.writeObject(param); | ||
| } | ||
| jsonGenerator.writeEndArray(); | ||
| jsonGenerator.writeEndObject(); | ||
| } | ||
| } |
45 changes: 45 additions & 0 deletions
45
.../src/main/java/com/linecorp/armeria/internal/server/annotation/RpcResponseSerializer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /* | ||
| * Copyright 2025 LY Corporation | ||
| * | ||
| * LY Corporation licenses this file to you under the Apache License, | ||
| * version 2.0 (the "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at: | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| * License for the specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package com.linecorp.armeria.internal.server.annotation; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| import com.fasterxml.jackson.core.JsonGenerator; | ||
| import com.fasterxml.jackson.databind.JsonSerializer; | ||
| import com.fasterxml.jackson.databind.SerializerProvider; | ||
|
|
||
| import com.linecorp.armeria.common.RpcResponse; | ||
|
|
||
| final class RpcResponseSerializer extends JsonSerializer<RpcResponse> { | ||
|
|
||
| static final RpcResponseSerializer INSTANCE = new RpcResponseSerializer(); | ||
| private static final Object DEFAULT = new Object(); | ||
|
|
||
| @Override | ||
| public Class<RpcResponse> handledType() { | ||
| return RpcResponse.class; | ||
| } | ||
|
|
||
| @Override | ||
| public void serialize(RpcResponse value, JsonGenerator jsonGenerator, SerializerProvider serializers) | ||
| throws IOException { | ||
| jsonGenerator.writeStartObject(); | ||
| final Object res = value.getNow(DEFAULT); | ||
| jsonGenerator.writeObjectField("res", res); | ||
| jsonGenerator.writeEndObject(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
.../thrift0.13/src/main/java/com/linecorp/armeria/common/thrift/logging/ThriftFieldInfo.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /* | ||
| * Copyright 2025 LY Corporation | ||
| * | ||
| * LY Corporation licenses this file to you under the Apache License, | ||
| * version 2.0 (the "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at: | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| * License for the specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package com.linecorp.armeria.common.thrift.logging; | ||
|
|
||
| import org.apache.thrift.meta_data.FieldMetaData; | ||
|
|
||
| import com.linecorp.armeria.common.annotation.UnstableApi; | ||
| import com.linecorp.armeria.common.logging.FieldMasker; | ||
|
|
||
| /** | ||
| * Holds information about a thrift struct field. | ||
| * Users may use the information conveyed in this object to decide whether to mask a field | ||
| * via {@link FieldMasker}. | ||
| */ | ||
| @UnstableApi | ||
| @FunctionalInterface | ||
| public interface ThriftFieldInfo { | ||
|
jrhee17 marked this conversation as resolved.
|
||
|
|
||
| /** | ||
| * The {@link FieldMetaData} for a field that can be obtained via | ||
| * {@link FieldMetaData#getStructMetaDataMap(Class)}. | ||
| */ | ||
| FieldMetaData fieldMetaData(); | ||
| } | ||
69 changes: 69 additions & 0 deletions
69
...3/src/main/java/com/linecorp/armeria/common/thrift/logging/ThriftFieldMaskerSelector.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /* | ||
| * Copyright 2025 LY Corporation | ||
| * | ||
| * LY Corporation licenses this file to you under the Apache License, | ||
| * version 2.0 (the "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at: | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| * License for the specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package com.linecorp.armeria.common.thrift.logging; | ||
|
|
||
| import static java.util.Objects.requireNonNull; | ||
|
|
||
| import java.util.function.Function; | ||
|
|
||
| import com.linecorp.armeria.common.annotation.UnstableApi; | ||
| import com.linecorp.armeria.common.logging.FieldMasker; | ||
| import com.linecorp.armeria.common.logging.FieldMaskerSelector; | ||
|
|
||
| /** | ||
| * A {@link FieldMaskerSelector} implementation for masking thrift struct types. | ||
| * A simple use-case may look like the following: | ||
| * <pre>{@code | ||
| * | ||
| * ThriftFieldMaskSelector selector = | ||
| * ThriftFieldMaskSelector.of(fieldInfo -> { | ||
| * Map<String, String> annotations = fieldInfo.fieldMetaData().getFieldAnnotations() | ||
| * if (!annotations.containsKey("sensitive")) { | ||
| * return FieldMasker.fallthrough(); | ||
| * } | ||
| * return FieldMasker.nullify(); | ||
| * }); | ||
| * }</pre> | ||
| * Note that the {@code annotations_as_metadata} thrift compiler option must be used to use field annotations. | ||
| */ | ||
| @UnstableApi | ||
| @FunctionalInterface | ||
| public interface ThriftFieldMaskerSelector extends FieldMaskerSelector<ThriftFieldInfo> { | ||
|
|
||
| /** | ||
| * A helper method to create a {@link ThriftFieldMaskerSelector}. | ||
| */ | ||
| static ThriftFieldMaskerSelector of(Function<ThriftFieldInfo, FieldMasker> fieldMaskerFunction) { | ||
| requireNonNull(fieldMaskerFunction, "fieldMaskerFunction"); | ||
| return fieldMaskerFunction::apply; | ||
| } | ||
|
|
||
| /** | ||
| * Delegates {@link FieldMasker} selection to a different {@link ThriftFieldMaskerSelector} | ||
| * if the current {@link ThriftFieldMaskerSelector} returns {@link FieldMasker#fallthrough()}. | ||
| */ | ||
| default ThriftFieldMaskerSelector orElse(ThriftFieldMaskerSelector other) { | ||
| requireNonNull(other, "other"); | ||
| return fieldInfo -> { | ||
| final FieldMasker fieldMasker = fieldMasker(fieldInfo); | ||
| if (fieldMasker != FieldMasker.fallthrough()) { | ||
| return fieldMasker; | ||
| } | ||
| return other.fieldMasker(fieldInfo); | ||
| }; | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
thrift/thrift0.13/src/main/java/com/linecorp/armeria/common/thrift/logging/package-info.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| /* | ||
| * Copyright 2025 LY Corporation | ||
| * | ||
| * LY Corporation licenses this file to you under the Apache License, | ||
| * version 2.0 (the "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at: | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| * License for the specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| /** | ||
| * Thrift-related classes for logging. | ||
| */ | ||
| @NonNullByDefault | ||
| package com.linecorp.armeria.common.thrift.logging; | ||
|
|
||
| import com.linecorp.armeria.common.annotation.NonNullByDefault; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.