Skip to content
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

cleanup: move filter wrappers into Network and Http namespaces. #3267

Merged
merged 11 commits into from
May 2, 2018
Merged
5 changes: 3 additions & 2 deletions ci/build_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,14 @@ if [[ -d /bazel-prebuilt-output && ! -d "${TEST_TMPDIR}/_bazel_${USER}" ]]; then
fi

# Setup Envoy consuming project.
rm -rf "${ENVOY_FILTER_EXAMPLE_SRCDIR}"
if [[ ! -a "${ENVOY_FILTER_EXAMPLE_SRCDIR}" ]]
then
git clone https://github.com/envoyproxy/envoy-filter-example.git "${ENVOY_FILTER_EXAMPLE_SRCDIR}"
git clone https://github.com/PiotrSikora/envoy-filter-example.git "${ENVOY_FILTER_EXAMPLE_SRCDIR}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Filter example is merged now; please fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, thanks for quick turnaround!

fi

# This is the hash on https://github.com/envoyproxy/envoy-filter-example.git we pin to.
(cd "${ENVOY_FILTER_EXAMPLE_SRCDIR}" && git fetch origin && git checkout -f c3a7c5588bb9588279e962c8d1243cd9b10c23d9)
(cd "${ENVOY_FILTER_EXAMPLE_SRCDIR}" && git fetch origin && git checkout -f 62f0cf9786689af8ee3f8c09f7111375175ee7f8)
cp -f "${ENVOY_SRCDIR}"/ci/WORKSPACE.filter.example "${ENVOY_FILTER_EXAMPLE_SRCDIR}"/WORKSPACE

# Also setup some space for building Envoy standalone.
Expand Down
20 changes: 20 additions & 0 deletions include/envoy/network/filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@ class FilterManager {
virtual bool initializeReadFilters() PURE;
};

/**
* This function is used to wrap the creation of a network filter chain for new connections as
* they come in. Filter factories create the lambda at configuration initialization time, and then
* they are used at runtime.
* @param filter_manager supplies the filter manager for the connection to install filters
* to. Typically the function will install a single filter, but it's technically possibly to
* install more than one if desired.
*/
typedef std::function<void(FilterManager& filter_manager)> NetworkFilterFactoryCb;

/**
* Callbacks used by individual listener filter instances to communicate with the listener filter
* manager.
Expand Down Expand Up @@ -212,6 +222,16 @@ class ListenerFilterManager {
virtual void addAcceptFilter(ListenerFilterPtr&& filter) PURE;
};

/**
* This function is used to wrap the creation of a listener filter chain for new sockets as they are
* created. Filter factories create the lambda at configuration initialization time, and then they
* are used at runtime.
* @param filter_manager supplies the filter manager for the listener to install filters to.
* Typically the function will install a single filter, but it's technically possibly to install
* more than one if desired.
*/
typedef std::function<void(ListenerFilterManager& filter_manager)> ListenerFilterFactoryCb;

/**
* Creates a chain of network filters for a new connection.
*/
Expand Down
34 changes: 7 additions & 27 deletions include/envoy/server/filter_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,6 @@ class ListenerFactoryContext : public FactoryContext {
virtual void addListenSocketOptions(const Network::Socket::OptionsSharedPtr& options) PURE;
};

/**
* This function is used to wrap the creation of a listener filter chain for new sockets as they are
* created. Filter factories create the lambda at configuration initialization time, and then they
* are used at runtime.
* @param filter_manager supplies the filter manager for the listener to install filters to.
* Typically the function will install a single filter, but it's technically possibly to install
* more than one if desired.
*/
typedef std::function<void(Network::ListenerFilterManager& filter_manager)> ListenerFilterFactoryCb;

/**
* Implemented by each listener filter and registered via Registry::registerFactory()
* or the convenience class RegisterFactory.
Expand All @@ -165,9 +155,9 @@ class NamedListenerFilterConfigFactory {
* callback should always be initialized.
* @param config supplies the general protobuf configuration for the filter
* @param context supplies the filter's context.
* @return ListenerFilterFactoryCb the factory creation function.
* @return Network::ListenerFilterFactoryCb the factory creation function.
*/
virtual ListenerFilterFactoryCb
virtual Network::ListenerFilterFactoryCb
createFilterFactoryFromProto(const Protobuf::Message& config,
ListenerFactoryContext& context) PURE;

Expand All @@ -185,16 +175,6 @@ class NamedListenerFilterConfigFactory {
virtual std::string name() PURE;
};

/**
* This function is used to wrap the creation of a network filter chain for new connections as
* they come in. Filter factories create the lambda at configuration initialization time, and then
* they are used at runtime.
* @param filter_manager supplies the filter manager for the connection to install filters
* to. Typically the function will install a single filter, but it's technically possibly to
* install more than one if desired.
*/
typedef std::function<void(Network::FilterManager& filter_manager)> NetworkFilterFactoryCb;

/**
* Implemented by each network filter and registered via Registry::registerFactory()
* or the convenience class RegisterFactory.
Expand All @@ -210,17 +190,17 @@ class NamedNetworkFilterConfigFactory {
* callback should always be initialized.
* @param config supplies the general json configuration for the filter
* @param context supplies the filter's context.
* @return NetworkFilterFactoryCb the factory creation function.
* @return Network::NetworkFilterFactoryCb the factory creation function.
*/
virtual NetworkFilterFactoryCb createFilterFactory(const Json::Object& config,
FactoryContext& context) PURE;
virtual Network::NetworkFilterFactoryCb createFilterFactory(const Json::Object& config,
FactoryContext& context) PURE;

/**
* v2 variant of createFilterFactory(..), where filter configs are specified as proto. This may be
* optionally implemented today, but will in the future become compulsory once v1 is deprecated.
*/
virtual NetworkFilterFactoryCb createFilterFactoryFromProto(const Protobuf::Message& config,
FactoryContext& context) {
virtual Network::NetworkFilterFactoryCb
createFilterFactoryFromProto(const Protobuf::Message& config, FactoryContext& context) {
UNREFERENCED_PARAMETER(config);
UNREFERENCED_PARAMETER(context);
NOT_IMPLEMENTED;
Expand Down
8 changes: 4 additions & 4 deletions include/envoy/server/listener_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ class ListenerComponentFactory {
* Creates a list of filter factories.
* @param filters supplies the proto configuration.
* @param context supplies the factory creation context.
* @return std::vector<Configuration::NetworkFilterFactoryCb> the list of filter factories.
* @return std::vector<Network::NetworkFilterFactoryCb> the list of filter factories.
*/
virtual std::vector<Configuration::NetworkFilterFactoryCb> createNetworkFilterFactoryList(
virtual std::vector<Network::NetworkFilterFactoryCb> createNetworkFilterFactoryList(
Copy link
Member

Choose a reason for hiding this comment

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

Sorry related to my other comment, can you rename to Network::FilterFactoryCb?

const Protobuf::RepeatedPtrField<envoy::api::v2::listener::Filter>& filters,
Configuration::FactoryContext& context) PURE;

/**
* Creates a list of listener filter factories.
* @param filters supplies the JSON configuration.
* @param context supplies the factory creation context.
* @return std::vector<Configuration::ListenerFilterFactoryCb> the list of filter factories.
* @return std::vector<Network::ListenerFilterFactoryCb> the list of filter factories.
*/
virtual std::vector<Configuration::ListenerFilterFactoryCb> createListenerFilterFactoryList(
virtual std::vector<Network::ListenerFilterFactoryCb> createListenerFilterFactoryList(
const Protobuf::RepeatedPtrField<envoy::api::v2::listener::ListenerFilter>& filters,
Configuration::ListenerFactoryContext& context) PURE;

Expand Down
2 changes: 1 addition & 1 deletion source/extensions/filters/listener/original_dst/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace OriginalDst {
class OriginalDstConfigFactory : public Server::Configuration::NamedListenerFilterConfigFactory {
public:
// NamedListenerFilterConfigFactory
Server::Configuration::ListenerFilterFactoryCb
Network::ListenerFilterFactoryCb
createFilterFactoryFromProto(const Protobuf::Message&,
Server::Configuration::ListenerFactoryContext&) override {
return [](Network::ListenerFilterManager& filter_manager) -> void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace ProxyProtocol {
class ProxyProtocolConfigFactory : public Server::Configuration::NamedListenerFilterConfigFactory {
public:
// NamedListenerFilterConfigFactory
Server::Configuration::ListenerFilterFactoryCb
Network::ListenerFilterFactoryCb
createFilterFactoryFromProto(const Protobuf::Message&,
Server::Configuration::ListenerFactoryContext& context) override {
ConfigSharedPtr config(new Config(context.scope()));
Expand Down
2 changes: 1 addition & 1 deletion source/extensions/filters/listener/tls_inspector/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace TlsInspector {
class TlsInspectorConfigFactory : public Server::Configuration::NamedListenerFilterConfigFactory {
public:
// NamedListenerFilterConfigFactory
Server::Configuration::ListenerFilterFactoryCb
Network::ListenerFilterFactoryCb
createFilterFactoryFromProto(const Protobuf::Message&,
Server::Configuration::ListenerFactoryContext& context) override {
ConfigSharedPtr config(new Config(context.scope()));
Expand Down
7 changes: 3 additions & 4 deletions source/extensions/filters/network/client_ssl_auth/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ namespace Extensions {
namespace NetworkFilters {
namespace ClientSslAuth {

Server::Configuration::NetworkFilterFactoryCb
Network::NetworkFilterFactoryCb
ClientSslAuthConfigFactory::createFilterFactory(const Json::Object& json_config,
Server::Configuration::FactoryContext& context) {
envoy::config::filter::network::client_ssl_auth::v2::ClientSSLAuth proto_config;
Config::FilterJson::translateClientSslAuthFilter(json_config, proto_config);
return createFilter(proto_config, context);
}

Server::Configuration::NetworkFilterFactoryCb
ClientSslAuthConfigFactory::createFilterFactoryFromProto(
Network::NetworkFilterFactoryCb ClientSslAuthConfigFactory::createFilterFactoryFromProto(
const Protobuf::Message& proto_config, Server::Configuration::FactoryContext& context) {
return createFilter(
MessageUtil::downcastAndValidate<
Expand All @@ -37,7 +36,7 @@ ProtobufTypes::MessagePtr ClientSslAuthConfigFactory::createEmptyConfigProto() {

std::string ClientSslAuthConfigFactory::name() { return NetworkFilterNames::get().CLIENT_SSL_AUTH; }

Server::Configuration::NetworkFilterFactoryCb ClientSslAuthConfigFactory::createFilter(
Network::NetworkFilterFactoryCb ClientSslAuthConfigFactory::createFilter(
const envoy::config::filter::network::client_ssl_auth::v2::ClientSSLAuth& proto_config,
Server::Configuration::FactoryContext& context) {
ASSERT(!proto_config.auth_api_cluster().empty());
Expand Down
6 changes: 3 additions & 3 deletions source/extensions/filters/network/client_ssl_auth/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ namespace ClientSslAuth {
class ClientSslAuthConfigFactory : public Server::Configuration::NamedNetworkFilterConfigFactory {
public:
// NamedNetworkFilterConfigFactory
Server::Configuration::NetworkFilterFactoryCb
Network::NetworkFilterFactoryCb
createFilterFactory(const Json::Object& json_config,
Server::Configuration::FactoryContext& context) override;
Server::Configuration::NetworkFilterFactoryCb
Network::NetworkFilterFactoryCb
createFilterFactoryFromProto(const Protobuf::Message& proto_config,
Server::Configuration::FactoryContext& context) override;
ProtobufTypes::MessagePtr createEmptyConfigProto() override;
std::string name() override;

private:
Server::Configuration::NetworkFilterFactoryCb createFilter(
Network::NetworkFilterFactoryCb createFilter(
const envoy::config::filter::network::client_ssl_auth::v2::ClientSSLAuth& proto_config,
Server::Configuration::FactoryContext& context);
};
Expand Down
4 changes: 2 additions & 2 deletions source/extensions/filters/network/echo/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ namespace Echo {
class EchoConfigFactory : public Server::Configuration::NamedNetworkFilterConfigFactory {
public:
// NamedNetworkFilterConfigFactory
Server::Configuration::NetworkFilterFactoryCb
Network::NetworkFilterFactoryCb
createFilterFactory(const Json::Object&, Server::Configuration::FactoryContext&) override {
return [](Network::FilterManager& filter_manager) -> void {
filter_manager.addReadFilter(std::make_shared<EchoFilter>());
};
}

Server::Configuration::NetworkFilterFactoryCb
Network::NetworkFilterFactoryCb
createFilterFactoryFromProto(const Protobuf::Message&,
Server::Configuration::FactoryContext&) override {
return [](Network::FilterManager& filter_manager) -> void {
Expand Down
6 changes: 3 additions & 3 deletions source/extensions/filters/network/ext_authz/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Extensions {
namespace NetworkFilters {
namespace ExtAuthz {

Server::Configuration::NetworkFilterFactoryCb ExtAuthzConfigFactory::createFilter(
Network::NetworkFilterFactoryCb ExtAuthzConfigFactory::createFilter(
const envoy::config::filter::network::ext_authz::v2::ExtAuthz& proto_config,
Server::Configuration::FactoryContext& context) {
ConfigSharedPtr ext_authz_config(new Config(proto_config, context.scope()));
Expand All @@ -39,13 +39,13 @@ Server::Configuration::NetworkFilterFactoryCb ExtAuthzConfigFactory::createFilte
};
}

Server::Configuration::NetworkFilterFactoryCb
Network::NetworkFilterFactoryCb
ExtAuthzConfigFactory::createFilterFactory(const Json::Object&,
Server::Configuration::FactoryContext&) {
NOT_IMPLEMENTED;
}

Server::Configuration::NetworkFilterFactoryCb ExtAuthzConfigFactory::createFilterFactoryFromProto(
Network::NetworkFilterFactoryCb ExtAuthzConfigFactory::createFilterFactoryFromProto(
const Protobuf::Message& proto_config, Server::Configuration::FactoryContext& context) {
return createFilter(
MessageUtil::downcastAndValidate<
Expand Down
6 changes: 3 additions & 3 deletions source/extensions/filters/network/ext_authz/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ namespace ExtAuthz {
class ExtAuthzConfigFactory : public Server::Configuration::NamedNetworkFilterConfigFactory {
public:
// NamedNetworkFilterConfigFactory
Server::Configuration::NetworkFilterFactoryCb
Network::NetworkFilterFactoryCb
createFilterFactory(const Json::Object& json_config,
Server::Configuration::FactoryContext& context) override;

Server::Configuration::NetworkFilterFactoryCb
Network::NetworkFilterFactoryCb
createFilterFactoryFromProto(const Protobuf::Message& proto_config,
Server::Configuration::FactoryContext& context) override;

Expand All @@ -31,7 +31,7 @@ class ExtAuthzConfigFactory : public Server::Configuration::NamedNetworkFilterCo
std::string name() override { return NetworkFilterNames::get().EXT_AUTHORIZATION; }

private:
Server::Configuration::NetworkFilterFactoryCb
Network::NetworkFilterFactoryCb
createFilter(const envoy::config::filter::network::ext_authz::v2::ExtAuthz& proto_config,
Server::Configuration::FactoryContext& context);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ namespace HttpConnectionManager {
SINGLETON_MANAGER_REGISTRATION(date_provider);
SINGLETON_MANAGER_REGISTRATION(route_config_provider_manager);

Server::Configuration::NetworkFilterFactoryCb
HttpConnectionManagerFilterConfigFactory::createFilter(
Network::NetworkFilterFactoryCb HttpConnectionManagerFilterConfigFactory::createFilter(
const envoy::config::filter::network::http_connection_manager::v2::HttpConnectionManager&
proto_config,
Server::Configuration::FactoryContext& context) {
Expand Down Expand Up @@ -69,15 +68,14 @@ HttpConnectionManagerFilterConfigFactory::createFilter(
};
}

Server::Configuration::NetworkFilterFactoryCb
HttpConnectionManagerFilterConfigFactory::createFilterFactory(
Network::NetworkFilterFactoryCb HttpConnectionManagerFilterConfigFactory::createFilterFactory(
const Json::Object& json_config, Server::Configuration::FactoryContext& context) {
envoy::config::filter::network::http_connection_manager::v2::HttpConnectionManager proto_config;
Config::FilterJson::translateHttpConnectionManager(json_config, proto_config);
return createFilter(proto_config, context);
}

Server::Configuration::NetworkFilterFactoryCb
Network::NetworkFilterFactoryCb
HttpConnectionManagerFilterConfigFactory::createFilterFactoryFromProto(
const Protobuf::Message& proto_config, Server::Configuration::FactoryContext& context) {
return createFilter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ class HttpConnectionManagerFilterConfigFactory
public Server::Configuration::NamedNetworkFilterConfigFactory {
public:
// NamedNetworkFilterConfigFactory
Server::Configuration::NetworkFilterFactoryCb
Network::NetworkFilterFactoryCb
createFilterFactory(const Json::Object& json_config,
Server::Configuration::FactoryContext& context) override;
Server::Configuration::NetworkFilterFactoryCb
Network::NetworkFilterFactoryCb
createFilterFactoryFromProto(const Protobuf::Message& proto_config,
Server::Configuration::FactoryContext& context) override;

Expand All @@ -44,7 +44,7 @@ class HttpConnectionManagerFilterConfigFactory
std::string name() override { return NetworkFilterNames::get().HTTP_CONNECTION_MANAGER; }

private:
Server::Configuration::NetworkFilterFactoryCb createFilter(
Network::NetworkFilterFactoryCb createFilter(
const envoy::config::filter::network::http_connection_manager::v2::HttpConnectionManager&
proto_config,
Server::Configuration::FactoryContext& context);
Expand Down
7 changes: 3 additions & 4 deletions source/extensions/filters/network/mongo_proxy/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Extensions {
namespace NetworkFilters {
namespace MongoProxy {

Server::Configuration::NetworkFilterFactoryCb MongoProxyFilterConfigFactory::createFilter(
Network::NetworkFilterFactoryCb MongoProxyFilterConfigFactory::createFilter(
const envoy::config::filter::network::mongo_proxy::v2::MongoProxy& proto_config,
Server::Configuration::FactoryContext& context) {

Expand All @@ -41,16 +41,15 @@ Server::Configuration::NetworkFilterFactoryCb MongoProxyFilterConfigFactory::cre
};
}

Server::Configuration::NetworkFilterFactoryCb
Network::NetworkFilterFactoryCb
MongoProxyFilterConfigFactory::createFilterFactory(const Json::Object& json_config,
Server::Configuration::FactoryContext& context) {
envoy::config::filter::network::mongo_proxy::v2::MongoProxy proto_config;
Config::FilterJson::translateMongoProxy(json_config, proto_config);
return createFilter(proto_config, context);
}

Server::Configuration::NetworkFilterFactoryCb
MongoProxyFilterConfigFactory::createFilterFactoryFromProto(
Network::NetworkFilterFactoryCb MongoProxyFilterConfigFactory::createFilterFactoryFromProto(
const Protobuf::Message& proto_config, Server::Configuration::FactoryContext& context) {
return createFilter(
MessageUtil::downcastAndValidate<
Expand Down
6 changes: 3 additions & 3 deletions source/extensions/filters/network/mongo_proxy/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ class MongoProxyFilterConfigFactory
: public Server::Configuration::NamedNetworkFilterConfigFactory {
public:
// NamedNetworkFilterConfigFactory
Server::Configuration::NetworkFilterFactoryCb
Network::NetworkFilterFactoryCb
createFilterFactory(const Json::Object& proto_config,
Server::Configuration::FactoryContext& context) override;
Server::Configuration::NetworkFilterFactoryCb
Network::NetworkFilterFactoryCb
createFilterFactoryFromProto(const Protobuf::Message& proto_config,
Server::Configuration::FactoryContext& context) override;

Expand All @@ -34,7 +34,7 @@ class MongoProxyFilterConfigFactory
std::string name() override { return NetworkFilterNames::get().MONGO_PROXY; }

private:
Server::Configuration::NetworkFilterFactoryCb
Network::NetworkFilterFactoryCb
createFilter(const envoy::config::filter::network::mongo_proxy::v2::MongoProxy& proto_config,
Server::Configuration::FactoryContext& context);
};
Expand Down
Loading