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

direct_response: use data source #10342

Merged
merged 2 commits into from
Mar 16, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion api/envoy/config/filter/network/direct_response/v2/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")
licenses(["notice"]) # Apache 2

api_proto_package(
deps = ["@com_github_cncf_udpa//udpa/annotations:pkg"],
deps = [
"//envoy/api/v2/core:pkg",
"@com_github_cncf_udpa//udpa/annotations:pkg",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ syntax = "proto3";

package envoy.config.filter.network.direct_response.v2;

import "envoy/api/v2/core/base.proto";

import "udpa/annotations/migrate.proto";

option java_package = "io.envoyproxy.envoy.config.filter.network.direct_response.v2";
Expand All @@ -15,6 +17,6 @@ option (udpa.annotations.file_migrate).move_to_package =
// [#extension: envoy.filters.network.direct_response]

message Config {
// Response data as bytes.
bytes response = 1;
// Response data as a data source.
api.v2.core.DataSource response = 1;
Copy link
Member

Choose a reason for hiding this comment

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

This is a breaking API change. You will need to add a new field for data source.

Copy link
Member

Choose a reason for hiding this comment

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

This was added in the last few days. No one is using it yet so IMO it's fine to change.

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ licenses(["notice"]) # Apache 2

api_proto_package(
deps = [
"//envoy/config/core/v3:pkg",
"//envoy/config/filter/network/direct_response/v2:pkg",
"@com_github_cncf_udpa//udpa/annotations:pkg",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ syntax = "proto3";

package envoy.extensions.filters.network.direct_response.v3;

import "envoy/config/core/v3/base.proto";

import "udpa/annotations/versioning.proto";

option java_package = "io.envoyproxy.envoy.extensions.filters.network.direct_response.v3";
Expand All @@ -16,6 +18,6 @@ message Config {
option (udpa.annotations.versioning).previous_message_type =
"envoy.config.filter.network.direct_response.v2.Config";

// Response data as bytes.
bytes response = 1;
// Response data as a data source.
config.core.v3.DataSource response = 1;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions source/extensions/filters/network/direct_response/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ envoy_cc_extension(
":filter",
"//include/envoy/registry",
"//include/envoy/server:filter_config_interface",
"//source/common/config:datasource_lib",
"//source/extensions/filters/network:well_known_names",
"//source/extensions/filters/network/common:factory_base_lib",
"@envoy_api//envoy/extensions/filters/network/direct_response/v3:pkg_cc_proto",
Expand Down
9 changes: 6 additions & 3 deletions source/extensions/filters/network/direct_response/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "envoy/registry/registry.h"
#include "envoy/server/filter_config.h"

#include "common/config/datasource.h"

#include "extensions/filters/network/common/factory_base.h"
#include "extensions/filters/network/direct_response/filter.h"
#include "extensions/filters/network/well_known_names.h"
Expand All @@ -23,9 +25,10 @@ class DirectResponseConfigFactory
private:
Network::FilterFactoryCb createFilterFactoryFromProtoTyped(
const envoy::extensions::filters::network::direct_response::v3::Config& config,
Server::Configuration::FactoryContext&) override {
return [config](Network::FilterManager& filter_manager) -> void {
filter_manager.addReadFilter(std::make_shared<DirectResponseFilter>(config.response()));
Server::Configuration::FactoryContext& context) override {
return [config, &context](Network::FilterManager& filter_manager) -> void {
auto content = Config::DataSource::read(config.response(), true, context.api());
filter_manager.addReadFilter(std::make_shared<DirectResponseFilter>(content));
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class DirectResponseIntegrationTest : public testing::TestWithParam<Network::Add
- name: direct_response
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.direct_response.v3.Config
response: aGVsbG8sIHdvcmxkIQo=
response:
inline_string: "hello, world!\n"
)EOF";
}

Expand Down