forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Matchers: Add dynamic metadata to the http inputs (envoyproxy#34891)
fixes: envoyproxy#34092 --------- Signed-off-by: Vikas Choudhary <[email protected]>
- Loading branch information
1 parent
988a6d0
commit 520d88e
Showing
24 changed files
with
599 additions
and
0 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains 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
This file contains 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
This file contains 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
12 changes: 12 additions & 0 deletions
12
api/envoy/extensions/matching/input_matchers/metadata/v3/BUILD
This file contains 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,12 @@ | ||
# DO NOT EDIT. This file is generated by tools/proto_format/proto_sync.py. | ||
|
||
load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package") | ||
|
||
licenses(["notice"]) # Apache 2 | ||
|
||
api_proto_package( | ||
deps = [ | ||
"//envoy/type/matcher/v3:pkg", | ||
"@com_github_cncf_xds//udpa/annotations:pkg", | ||
], | ||
) |
26 changes: 26 additions & 0 deletions
26
api/envoy/extensions/matching/input_matchers/metadata/v3/metadata.proto
This file contains 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,26 @@ | ||
syntax = "proto3"; | ||
|
||
package envoy.extensions.matching.input_matchers.metadata.v3; | ||
|
||
import "envoy/type/matcher/v3/value.proto"; | ||
|
||
import "udpa/annotations/status.proto"; | ||
import "validate/validate.proto"; | ||
|
||
option java_package = "io.envoyproxy.envoy.extensions.matching.input_matchers.metadata.v3"; | ||
option java_outer_classname = "MetadataProto"; | ||
option java_multiple_files = true; | ||
option go_package = "github.com/envoyproxy/go-control-plane/envoy/extensions/matching/input_matchers/metadata/v3;metadatav3"; | ||
option (udpa.annotations.file_status).package_version_status = ACTIVE; | ||
|
||
// [#protodoc-title: metadata matcher] | ||
// [#extension: envoy.matching.matchers.metadata_matcher] | ||
|
||
// Metadata matcher for metadata from http matching input data. | ||
message Metadata { | ||
// The Metadata is matched if the value retrieved by metadata matching input is matched to this value. | ||
type.matcher.v3.ValueMatcher value = 1 [(validate.rules).message = {required: true}]; | ||
|
||
// If true, the match result will be inverted. | ||
bool invert = 4; | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,22 @@ | ||
load( | ||
"//bazel:envoy_build_system.bzl", | ||
"envoy_cc_extension", | ||
"envoy_extension_package", | ||
) | ||
|
||
licenses(["notice"]) # Apache 2 | ||
|
||
envoy_extension_package() | ||
|
||
envoy_cc_extension( | ||
name = "metadata_input_lib", | ||
srcs = ["meta_input.cc"], | ||
hdrs = ["meta_input.h"], | ||
deps = [ | ||
"//envoy/http:filter_interface", | ||
"//envoy/matcher:matcher_interface", | ||
"//envoy/registry", | ||
"//source/common/config:metadata_lib", | ||
"@envoy_api//envoy/extensions/matching/common_inputs/network/v3:pkg_cc_proto", | ||
], | ||
) |
20 changes: 20 additions & 0 deletions
20
source/extensions/matching/http/metadata_input/meta_input.cc
This file contains 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,20 @@ | ||
#include "source/extensions/matching/http/metadata_input/meta_input.h" | ||
|
||
#include "envoy/registry/registry.h" | ||
|
||
namespace Envoy { | ||
namespace Extensions { | ||
namespace Matching { | ||
namespace Http { | ||
namespace MetadataInput { | ||
|
||
class HttpDynamicMetadataInputFactory | ||
: public DynamicMetadataInputBaseFactory<Envoy::Http::HttpMatchingData> {}; | ||
REGISTER_FACTORY(HttpDynamicMetadataInputFactory, | ||
Matcher::DataInputFactory<Envoy::Http::HttpMatchingData>); | ||
|
||
} // namespace MetadataInput | ||
} // namespace Http | ||
} // namespace Matching | ||
} // namespace Extensions | ||
} // namespace Envoy |
82 changes: 82 additions & 0 deletions
82
source/extensions/matching/http/metadata_input/meta_input.h
This file contains 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,82 @@ | ||
#pragma once | ||
|
||
#include "envoy/extensions/matching/common_inputs/network/v3/network_inputs.pb.h" | ||
#include "envoy/extensions/matching/common_inputs/network/v3/network_inputs.pb.validate.h" | ||
#include "envoy/http/filter.h" | ||
#include "envoy/matcher/matcher.h" | ||
|
||
#include "source/common/config/metadata.h" | ||
|
||
namespace Envoy { | ||
namespace Extensions { | ||
namespace Matching { | ||
namespace Http { | ||
namespace MetadataInput { | ||
|
||
class MetadataMatchData : public ::Envoy::Matcher::CustomMatchData { | ||
public: | ||
explicit MetadataMatchData(const ProtobufWkt::Value& value) : value_(value) {} | ||
const ProtobufWkt::Value& value_; | ||
}; | ||
|
||
template <class MatchingDataType> | ||
class DynamicMetadataInput : public Matcher::DataInput<MatchingDataType> { | ||
public: | ||
DynamicMetadataInput( | ||
const envoy::extensions::matching::common_inputs::network::v3::DynamicMetadataInput& | ||
input_config) | ||
: filter_(input_config.filter()), path_(initializePath(input_config.path())) {} | ||
|
||
Matcher::DataInputGetResult get(const MatchingDataType& data) const override { | ||
return {Matcher::DataInputGetResult::DataAvailability::AllDataAvailable, | ||
std::make_unique<MetadataMatchData>( | ||
Envoy::Config::Metadata::metadataValue(&data.metadata(), filter_, path_))}; | ||
} | ||
|
||
private: | ||
static std::vector<std::string> initializePath( | ||
const Protobuf::RepeatedPtrField<envoy::extensions::matching::common_inputs::network::v3:: | ||
DynamicMetadataInput::PathSegment>& segments) { | ||
std::vector<std::string> path; | ||
for (const auto& seg : segments) { | ||
path.push_back(seg.key()); | ||
} | ||
return path; | ||
} | ||
|
||
const std::string filter_; | ||
const std::vector<std::string> path_; | ||
}; | ||
|
||
template <class MatchingDataType> | ||
class DynamicMetadataInputBaseFactory : public Matcher::DataInputFactory<MatchingDataType> { | ||
public: | ||
std::string name() const override { return "envoy.matching.inputs.dynamic_metadata"; } | ||
|
||
Matcher::DataInputFactoryCb<MatchingDataType> | ||
createDataInputFactoryCb(const Protobuf::Message& message, | ||
ProtobufMessage::ValidationVisitor& validation_visitor) override { | ||
const auto& typed_config = MessageUtil::downcastAndValidate< | ||
const envoy::extensions::matching::common_inputs::network::v3::DynamicMetadataInput&>( | ||
message, validation_visitor); | ||
auto config_ptr = std::make_shared< | ||
envoy::extensions::matching::common_inputs::network::v3::DynamicMetadataInput>( | ||
typed_config); | ||
return [config_ptr] { | ||
return std::make_unique<DynamicMetadataInput<MatchingDataType>>(*config_ptr); | ||
}; | ||
}; | ||
|
||
ProtobufTypes::MessagePtr createEmptyConfigProto() override { | ||
return std::make_unique< | ||
envoy::extensions::matching::common_inputs::network::v3::DynamicMetadataInput>(); | ||
} | ||
}; | ||
|
||
DECLARE_FACTORY(HttpDymanicMetadataInputFactory); | ||
|
||
} // namespace MetadataInput | ||
} // namespace Http | ||
} // namespace Matching | ||
} // namespace Extensions | ||
} // namespace Envoy |
This file contains 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,36 @@ | ||
load( | ||
"//bazel:envoy_build_system.bzl", | ||
"envoy_cc_extension", | ||
"envoy_cc_library", | ||
"envoy_extension_package", | ||
) | ||
|
||
licenses(["notice"]) # Apache 2 | ||
|
||
envoy_extension_package() | ||
|
||
envoy_cc_library( | ||
name = "metadata_lib", | ||
srcs = ["matcher.cc"], | ||
hdrs = ["matcher.h"], | ||
deps = [ | ||
"//envoy/matcher:matcher_interface", | ||
"//source/common/common:matchers_lib", | ||
"//source/extensions/matching/http/metadata_input:metadata_input_lib", | ||
"@envoy_api//envoy/extensions/matching/input_matchers/metadata/v3:pkg_cc_proto", | ||
"@envoy_api//envoy/type/matcher/v3:pkg_cc_proto", | ||
], | ||
) | ||
|
||
envoy_cc_extension( | ||
name = "config", | ||
srcs = ["config.cc"], | ||
hdrs = ["config.h"], | ||
deps = [ | ||
":metadata_lib", | ||
"//envoy/matcher:matcher_interface", | ||
"//envoy/registry", | ||
"//envoy/server:factory_context_interface", | ||
"@envoy_api//envoy/extensions/matching/input_matchers/metadata/v3:pkg_cc_proto", | ||
], | ||
) |
Oops, something went wrong.