[ProtoApiScrubber] Initialize and store descriptor in FilterConfig to be used later for scrubbing. - #39815
Conversation
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
# Conflicts: # source/extensions/filters/http/proto_api_scrubber/BUILD # source/extensions/filters/http/proto_api_scrubber/filter_config.cc # source/extensions/filters/http/proto_api_scrubber/filter_config.h Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
# Conflicts: # source/extensions/filters/http/proto_api_scrubber/filter_config.cc # source/extensions/filters/http/proto_api_scrubber/filter_config.h # test/extensions/filters/http/proto_api_scrubber/filter_config_test.cc Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
# Conflicts: # source/extensions/filters/http/proto_api_scrubber/filter.cc # source/extensions/filters/http/proto_api_scrubber/filter.h Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
# Conflicts: # source/extensions/filters/http/proto_api_scrubber/filter.cc # source/extensions/filters/http/proto_api_scrubber/filter.h Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
# Conflicts: # test/extensions/filters/http/proto_api_scrubber/filter_test.cc Signed-off-by: Sumit Kumar <sumitkmr@google.com>
| } | ||
| break; | ||
| } | ||
|
|
There was a problem hiding this comment.
style-nit: please remove empty lines in switch-case.
| break; | ||
| } | ||
|
|
||
| default: { |
There was a problem hiding this comment.
style-nit: remove curly brackets when not needed.
There was a problem hiding this comment.
I added those since some style-guides expect all the switch cases to be enclosed in curly braces. Removed now.
| auto file_or_error = api.fileSystem().fileReadToEnd(data_source.filename()); | ||
| if (!file_or_error.status().ok() || !descriptor_set.ParseFromString(file_or_error.value())) { | ||
| std::cout << "File_or_Error_Status: " << file_or_error.status() << std::endl; | ||
| std::cout << "File_or_Error_Status message: " << file_or_error.status().message() |
There was a problem hiding this comment.
Seems that this doesn't capture the case where file_or_error is valid (but ParseFromString fails).
Please fix to capture the correct error.
There was a problem hiding this comment.
Done, thanks for pointing out.
| absl::Status ProtoApiScrubberFilterConfig::initializeDescriptorPool( | ||
| Api::Api& api, const ::envoy::config::core::v3::DataSource& data_source) { | ||
| Envoy::Protobuf::FileDescriptorSet descriptor_set; | ||
| auto pool = std::make_unique<Envoy::Protobuf::DescriptorPool>(); |
There was a problem hiding this comment.
nit: move after the switch block.
| } | ||
|
|
||
| for (const auto& file : descriptor_set.file()) { | ||
| pool->BuildFile(file); |
There was a problem hiding this comment.
Can this fail?
If so, should a failure be returned?
There was a problem hiding this comment.
Yes, it can fail. Added the error handling. Thanks for pointing it out.
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
sumitkmr2
left a comment
There was a problem hiding this comment.
Addressed comments, thanks!
| absl::Status ProtoApiScrubberFilterConfig::initializeDescriptorPool( | ||
| Api::Api& api, const ::envoy::config::core::v3::DataSource& data_source) { | ||
| Envoy::Protobuf::FileDescriptorSet descriptor_set; | ||
| auto pool = std::make_unique<Envoy::Protobuf::DescriptorPool>(); |
| auto file_or_error = api.fileSystem().fileReadToEnd(data_source.filename()); | ||
| if (!file_or_error.status().ok() || !descriptor_set.ParseFromString(file_or_error.value())) { | ||
| std::cout << "File_or_Error_Status: " << file_or_error.status() << std::endl; | ||
| std::cout << "File_or_Error_Status message: " << file_or_error.status().message() |
There was a problem hiding this comment.
Done, thanks for pointing out.
| break; | ||
| } | ||
|
|
||
| default: { |
There was a problem hiding this comment.
I added those since some style-guides expect all the switch cases to be enclosed in curly braces. Removed now.
| } | ||
| break; | ||
| } | ||
|
|
| } | ||
|
|
||
| for (const auto& file : descriptor_set.file()) { | ||
| pool->BuildFile(file); |
There was a problem hiding this comment.
Yes, it can fail. Added the error handling. Thanks for pointing it out.
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
Signed-off-by: Sumit Kumar <sumitkmr@google.com>
adisuissa
left a comment
There was a problem hiding this comment.
LGTM, thanks.
BTW: just saw that there's a missing coverage (https://storage.googleapis.com/envoy-pr/d7f4e90/coverage/source/extensions/filters/http/proto_api_scrubber/filter.cc.html). Can you add some tests that validate that this code is WAI?
Yeah sure, I'll add test to cover these lines as well. |
Commit Message: Initialize and store descriptor in FilterConfig to be used later for scrubbing.
Additional Description: N/A
Risk Level: NONE
Testing: UTs added
Docs Changes: NONE
Release Notes: N/A
Platform Specific Features: NONE
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Fixes commit #PR or SHA]
[Optional Deprecated:]
[Optional API Considerations:]