Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions api/bazel/repository_locations.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ REPOSITORY_LOCATIONS_SPEC = dict(
project_desc = "xDS API Working Group (xDS-WG)",
project_url = "https://github.com/cncf/xds",
# During the UDPA -> xDS migration, we aren't working with releases.
version = "cb28da3451f158a947dfc45090fe92b07b243bc1",
sha256 = "5bc8365613fe2f8ce6cc33959b7667b13b7fe56cb9d16ba740c06e1a7c4242fc",
release_date = "2021-10-11",
version = "a8f946100490e3c4aef5c069e41b58d1a8705836",
sha256 = "9822cb9550064c7575ca07516b7a2290808ccef8c311c486a295a41a323369ea",
release_date = "2021-11-30",
strip_prefix = "xds-{version}",
urls = ["https://github.com/cncf/xds/archive/{version}.tar.gz"],
use_category = ["api"],
Expand Down
1 change: 1 addition & 0 deletions docs/root/version_history/current.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ New Features
* listener: added API for extensions to access :ref:`typed_filter_metadata <envoy_v3_api_field_config.core.v3.Metadata.typed_filter_metadata>` configured in the listener's :ref:`metadata <envoy_v3_api_field_config.listener.v3.Listener.metadata>` field.
* listener: added support for :ref:`MPTCP <envoy_v3_api_field_config.listener.v3.Listener.enable_mptcp>` (multipath TCP).
* listener: added support for opting out listeners from the globally set downstream connection limit via :ref:`ignore_global_conn_limit <envoy_v3_api_field_config.listener.v3.Listener.ignore_global_conn_limit>`.
* matching: the matching API can now express a match tree that will always match by omitting a matcher at the top level.
* oauth filter: added :ref:`cookie_names <envoy_v3_api_field_extensions.filters.http.oauth2.v3.OAuth2Credentials.cookie_names>` to allow overriding (default) cookie names (``BearerToken``, ``OauthHMAC``, and ``OauthExpires``) set by the filter.
* oauth filter: setting IdToken and RefreshToken cookies if they are provided by Identity provider along with AccessToken.
* perf: added support for [Perfetto](https://perfetto.dev) performance tracing.
Expand Down
23 changes: 21 additions & 2 deletions source/common/matcher/matcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ using MatchTreeFactoryCb = std::function<std::unique_ptr<MatchTree<DataType>>()>
template <class DataType> using OnMatchFactoryCb = std::function<OnMatch<DataType>()>;
template <class DataType> using DataInputFactoryCb = std::function<DataInputPtr<DataType>()>;

template <class DataType> class AnyMatcher : public MatchTree<DataType> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add some comments.

public:
explicit AnyMatcher(absl::optional<OnMatch<DataType>> on_no_match)
: on_no_match_(std::move(on_no_match)) {}

typename MatchTree<DataType>::MatchResult match(const DataType&) override {
return {MatchState::MatchComplete, on_no_match_};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not an expert here, but should the 2nd param (on_no_match_ object) be returned by ref?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in other use cases this always does a copy, since the Action object is generally small (lambda + pointer). We could probably change this around but would be a bigger refactor I think

}
const absl::optional<OnMatch<DataType>> on_no_match_;
};

/**
* Recursively constructs a MatchTree from a protobuf configuration.
* @param DataType the type used as a source for DataInputs
Expand All @@ -86,12 +97,20 @@ template <class DataType, class ActionFactoryContext> class MatchTreeFactory {
case MatcherType::kMatcherList:
return createListMatcher(config);
default:
NOT_REACHED_GCOVR_EXCL_LINE;
return nullptr;
return createAnyMatcher(config);
}
}

private:
template <class MatcherType>
MatchTreeFactoryCb<DataType> createAnyMatcher(const MatcherType& config) {
auto on_no_match = createOnMatch(config.on_no_match());

return [on_no_match]() {
return std::make_unique<AnyMatcher<DataType>>(
on_no_match ? absl::make_optional((*on_no_match)()) : absl::nullopt);
};
}
template <class MatcherType>
MatchTreeFactoryCb<DataType> createListMatcher(const MatcherType& config) {
std::vector<std::pair<FieldMatcherFactoryCb<DataType>, OnMatchFactoryCb<DataType>>>
Expand Down
24 changes: 24 additions & 0 deletions test/common/matcher/matcher_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "test/test_common/utility.h"

#include "gtest/gtest.h"
#include "xds/type/matcher/v3/matcher.pb.validate.h"

namespace Envoy {
namespace Matcher {
Expand Down Expand Up @@ -83,6 +84,29 @@ TEST_F(MatcherTest, TestMatcher) {
EXPECT_NE(result.on_match_->action_cb_, nullptr);
}

TEST_F(MatcherTest, TestAnyMatcher) {
const std::string yaml = R"EOF(
on_no_match:
action:
name: test_action
typed_config:
"@type": type.googleapis.com/google.protobuf.StringValue
value: match!!
)EOF";

xds::type::matcher::v3::Matcher matcher;
MessageUtil::loadFromYaml(yaml, matcher, ProtobufMessage::getStrictValidationVisitor());

TestUtility::validate(matcher);

auto match_tree = factory_.create(matcher);

const auto result = match_tree()->match(TestData());
EXPECT_EQ(result.match_state_, MatchState::MatchComplete);
EXPECT_TRUE(result.on_match_.has_value());
EXPECT_NE(result.on_match_->action_cb_, nullptr);
}

TEST_F(MatcherTest, CustomGenericInput) {
const std::string yaml = R"EOF(
matcher_list:
Expand Down