-
Notifications
You must be signed in to change notification settings - Fork 5.3k
config: allow unknown fields flag (take 2) #4096
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -133,6 +133,8 @@ class ProtoValidationException : public EnvoyException { | |
| ProtoValidationException(const std::string& validation_error, const Protobuf::Message& message); | ||
| }; | ||
|
|
||
| enum class ProtoUnknownFieldsMode { Strict, Allow }; | ||
|
|
||
| class MessageUtil { | ||
| public: | ||
| // std::hash | ||
|
|
@@ -158,7 +160,19 @@ class MessageUtil { | |
| return HashUtil::xxHash64(text); | ||
| } | ||
|
|
||
| static ProtoUnknownFieldsMode proto_unknown_fields; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: For readability, can you do an explicit initialization to Strict here.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you give me an example how to initialize a non-const static in the header?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, missed that, LGTM, thanks. |
||
|
|
||
| static void checkUnknownFields(const Protobuf::Message& message) { | ||
| if (MessageUtil::proto_unknown_fields == ProtoUnknownFieldsMode::Strict && | ||
| !message.GetReflection()->GetUnknownFields(message).empty()) { | ||
| throw EnvoyException("Protobuf message (type " + message.GetTypeName() + | ||
| ") has unknown fields"); | ||
| } | ||
| } | ||
|
|
||
| static void loadFromJson(const std::string& json, Protobuf::Message& message); | ||
| static void loadFromJsonEx(const std::string& json, Protobuf::Message& message, | ||
| ProtoUnknownFieldsMode proto_unknown_fields); | ||
| static void loadFromYaml(const std::string& yaml, Protobuf::Message& message); | ||
| static void loadFromFile(const std::string& path, Protobuf::Message& message); | ||
|
|
||
|
|
@@ -214,6 +228,7 @@ class MessageUtil { | |
| if (!message.UnpackTo(&typed_message)) { | ||
| throw EnvoyException("Unable to unpack " + message.DebugString()); | ||
| } | ||
| checkUnknownFields(typed_message); | ||
| return typed_message; | ||
| }; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,12 +46,7 @@ class ThriftConnManagerIntegrationTest | |
| route_config: | ||
| name: "routes" | ||
| routes: | ||
| - match: | ||
| method_name: "execute" | ||
| route: | ||
| cluster: "cluster_0" | ||
| - match: | ||
| method_name: "poke" | ||
| - match: {} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops. Could you revert the original and switch method_name to method? That should eliminate the unknown fields. (I'll circle back and add a second cluster to this test and use it for the one of the routes.)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, that'll just make half the tests fail. You can leave this and I'll fix it myself.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I am getting errors if I put it back... |
||
| route: | ||
| cluster: "cluster_0" | ||
| )EOF"; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,7 +78,6 @@ def _proto_doc_aspect_impl(target, ctx): | |
| return [OutputGroupInfo(rst = transitive_outputs)] | ||
|
|
||
| proto_doc_aspect = aspect( | ||
| implementation = _proto_doc_aspect_impl, | ||
| attr_aspects = ["deps"], | ||
| attrs = { | ||
| "_protoc": attr.label( | ||
|
|
@@ -92,4 +91,5 @@ proto_doc_aspect = aspect( | |
| cfg = "host", | ||
| ), | ||
| }, | ||
| implementation = _proto_doc_aspect_impl, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume this is just some Buildifier artifact..
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, not sure why |
||
| ) | ||
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.
note: we were ignoring mismatched type errors during unpacking.