Skip to content

Commit 2c99250

Browse files
yuval-ksoloio-bulldozer[bot]
authored andcommitted
Transform cleanup (#21)
* transformation cleanup * formatfix * more cleanup
1 parent 6af384e commit 2c99250

33 files changed

+332
-259
lines changed

WORKSPACE

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1-
workspace(name="envoy_gloo")
1+
workspace(name = "envoy_gloo")
22

33
load("//bazel:repositories.bzl", "envoy_gloo_dependencies")
44

55
envoy_gloo_dependencies()
66

77
load("@envoy//bazel:api_binding.bzl", "envoy_api_binding")
8+
89
envoy_api_binding()
910

1011
load("@envoy//bazel:api_repositories.bzl", "envoy_api_dependencies")
12+
1113
envoy_api_dependencies()
1214

1315
load("@envoy//bazel:repositories.bzl", "envoy_dependencies")
16+
1417
envoy_dependencies()
1518

1619
load("@envoy//bazel:dependency_imports.bzl", "envoy_dependency_imports")
20+
1721
envoy_dependency_imports()

api/envoy/config/filter/http/aws_lambda/v2/aws_lambda.proto

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ syntax = "proto3";
22

33
package envoy.config.filter.http.aws_lambda.v2;
44

5+
option java_package = "io.envoyproxy.envoy.config.filter.http.aws_lambda.v2";
6+
option java_outer_classname = "AwsLambdaProto";
7+
option java_multiple_files = true;
58
import "google/protobuf/wrappers.proto";
69
import "validate/validate.proto";
710

api/envoy/config/filter/http/nats/streaming/v2/nats_streaming.proto

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ syntax = "proto3";
22

33
package envoy.config.filter.http.nats.streaming.v2;
44

5+
option java_package = "io.envoyproxy.envoy.config.filter.http.nats.streaming.v2";
6+
option java_outer_classname = "NatsStreamingProto";
7+
option java_multiple_files = true;
58
import "google/protobuf/duration.proto";
69
import "validate/validate.proto";
710

api/envoy/config/filter/http/nats/streaming/v2/payload.proto

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
syntax = "proto3";
22
package pb;
33

4+
option java_package = "io.envoyproxy.pb";
5+
option java_outer_classname = "PayloadProto";
6+
option java_multiple_files = true;
47
message Payload {
58
map<string, string> headers = 1;
69
bytes body = 2;

api/envoy/config/filter/http/transformation/v2/transformation_filter.proto

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ syntax = "proto3";
22

33
package envoy.api.v2.filter.http;
44

5+
option java_package = "io.envoyproxy.envoy.api.v2.filter.http";
6+
option java_outer_classname = "TransformationFilterProto";
7+
option java_multiple_files = true;
58
option go_package = "transformation";
69

710
message RouteTransformations {

api/envoy/config/filter/network/consul_connect/v2/authorize.proto

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ syntax = "proto3";
22

33
package agent.connect.authorize.v1;
44

5+
option java_package = "io.envoyproxy.agent.connect.authorize.v1";
6+
option java_outer_classname = "AuthorizeProto";
7+
option java_multiple_files = true;
58
import "google/protobuf/duration.proto";
69

710
// [#protodoc-title: Authorize]

api/envoy/config/filter/network/consul_connect/v2/consul_connect.proto

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ syntax = "proto3";
22

33
package envoy.config.filter.network.consul_connect.v2;
44

5+
option java_package = "io.envoyproxy.envoy.config.filter.network.consul_connect.v2";
6+
option java_outer_classname = "ConsulConnectProto";
7+
option java_multiple_files = true;
58
import "google/protobuf/duration.proto";
69

710
import "validate/validate.proto";

bazel/envoy_test.bzl

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
21
# Copied from @envoy/bazel/envoy_test.bzl and uses public visibility for tests
32
# So we can target them to use our coverage.
43

54
load(
65
"@envoy//bazel:envoy_build_system.bzl",
76
"envoy_cc_test_library",
87
)
9-
108
load(
119
"@envoy//bazel:envoy_internal.bzl",
1210
"envoy_copts",
13-
"envoy_select_force_libcpp",
1411
"envoy_linkstatic",
12+
"envoy_select_force_libcpp",
1513
"tcmalloc_external_dep",
1614
)
1715

@@ -32,7 +30,7 @@ def _envoy_test_linkopts():
3230
# TODO(mattklein123): It's not great that we universally link against the following libs.
3331
# In particular, -latomic and -lrt are not needed on all platforms. Make this more granular.
3432
"//conditions:default": ["-pthread", "-lrt", "-ldl"],
35-
}) + envoy_select_force_libcpp(["-lc++fs"], ["-lstdc++fs", "-latomic"])
33+
}) + envoy_select_force_libcpp([], ["-lstdc++fs", "-latomic"])
3634

3735
# Envoy C++ test targets should be specified with this function.
3836
def envoy_gloo_cc_test(

bazel/external/BUILD

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
licenses(["notice"]) # Apache 2

bazel/external/inja.BUILD

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
licenses(["notice"]) # Apache 2
2+
13
cc_library(
24
name = "inja-lib",
35
hdrs = ["single_include/inja/inja.hpp"],
4-
visibility = ["//visibility:public"],
56
strip_include_prefix = "single_include/",
7+
visibility = ["//visibility:public"],
68
)

bazel/external/json.BUILD

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
licenses(["notice"]) # Apache 2
2+
13
cc_library(
24
name = "json-lib",
35
hdrs = ["single_include/nlohmann/json.hpp"],
4-
visibility = ["//visibility:public"],
56
strip_include_prefix = "single_include/",
7+
visibility = ["//visibility:public"],
68
)

source/extensions/filters/http/aws_lambda/aws_authenticator.cc

+2-3
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ std::string AwsAuthenticator::getBodyHexSha() {
120120
void AwsAuthenticator::fetchUrl() {
121121
const Http::HeaderString &canonical_url = request_headers_->Path()->value();
122122
url_base_ = canonical_url.getStringView();
123-
query_string_ =
124-
Http::Utility::findQueryStringStart(canonical_url);
123+
query_string_ = Http::Utility::findQueryStringStart(canonical_url);
125124
if (query_string_.length() != 0) {
126125
url_base_.remove_suffix(query_string_.length());
127126
// remove the question mark
@@ -267,7 +266,7 @@ void AwsAuthenticator::Sha256::update(const std::string &data) {
267266
update(data.c_str(), data.size());
268267
}
269268

270-
void AwsAuthenticator::Sha256::update(const absl::string_view& data) {
269+
void AwsAuthenticator::Sha256::update(const absl::string_view &data) {
271270
update(data.data(), data.size());
272271
}
273272

source/extensions/filters/http/aws_lambda/aws_authenticator.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class AwsAuthenticator {
7777
Sha256();
7878
void update(const Buffer::Instance &data);
7979
void update(const std::string &data);
80-
void update(const absl::string_view& data);
80+
void update(const absl::string_view &data);
8181

8282
void update(char c);
8383
void update(const uint8_t *bytes, size_t size);

source/extensions/filters/http/aws_lambda/aws_lambda_filter.cc

+5-6
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ namespace HttpFilters {
2424
namespace AwsLambda {
2525

2626
struct RcDetailsValues {
27-
// The jwt_authn filter rejected the request
28-
const std::string FunctionNotFound = "aws_lambda_function_not_fou8nd";
27+
const std::string FunctionNotFound = "aws_lambda_function_not_found";
2928
};
3029
typedef ConstSingleton<RcDetailsValues> RcDetails;
3130

@@ -78,13 +77,13 @@ AWSLambdaFilter::decodeHeaders(Http::HeaderMap &headers, bool end_stream) {
7877
route_ = decoder_callbacks_->route();
7978
// great! this is an aws cluster. get the function information:
8079
function_on_route_ =
81-
Http::SoloFilterUtility::resolvePerFilterConfig<AWSLambdaRouteConfig>(
80+
Http::Utility::resolveMostSpecificPerFilterConfig<AWSLambdaRouteConfig>(
8281
SoloHttpFilterNames::get().AwsLambda, route_);
8382

8483
if (!function_on_route_) {
85-
decoder_callbacks_->sendLocalReply(Http::Code::NotFound,
86-
"no function present for AWS upstream",
87-
nullptr, absl::nullopt, RcDetails::get().FunctionNotFound);
84+
decoder_callbacks_->sendLocalReply(
85+
Http::Code::NotFound, "no function present for AWS upstream", nullptr,
86+
absl::nullopt, RcDetails::get().FunctionNotFound);
8887
return Http::FilterHeadersStatus::StopIteration;
8988
}
9089

source/extensions/filters/http/nats/streaming/nats_streaming_filter.cc

+9-10
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "common/common/macros.h"
1212
#include "common/common/utility.h"
1313
#include "common/grpc/common.h"
14+
#include "common/http/utility.h"
1415
#include "common/http/solo_filter_utility.h"
1516

1617
#include "extensions/filters/http/solo_well_known_names.h"
@@ -59,11 +60,8 @@ NatsStreamingFilter::decodeHeaders(Envoy::Http::HeaderMap &headers,
5960
auto mutable_headers = payload_.mutable_headers();
6061
headers.iterate(
6162
[](const Envoy::Http::HeaderEntry &e, void *ctx) {
62-
Envoy::Protobuf::Map<std::string,
63-
std::string> *mutable_headers =
64-
static_cast<Envoy::Protobuf::Map<std::string,
65-
std::string> *>(
66-
ctx);
63+
Envoy::Protobuf::Map<std::string, std::string> *mutable_headers =
64+
static_cast<Envoy::Protobuf::Map<std::string, std::string> *>(ctx);
6765
(*mutable_headers)[std::string(e.key().getStringView())] =
6866
std::string(e.value().getStringView());
6967
return Envoy::Http::HeaderMap::Iterate::Continue;
@@ -89,9 +87,9 @@ NatsStreamingFilter::decodeData(Envoy::Buffer::Instance &data,
8987
if ((decoder_buffer_limit_.has_value()) &&
9088
((body_.length() + data.length()) > decoder_buffer_limit_.value())) {
9189

92-
decoder_callbacks_->sendLocalReply(Http::Code::PayloadTooLarge,
93-
"nats streaming paylaod too large",
94-
nullptr, absl::nullopt, RcDetails::get().PayloadTooLarge);
90+
decoder_callbacks_->sendLocalReply(
91+
Http::Code::PayloadTooLarge, "nats streaming paylaod too large",
92+
nullptr, absl::nullopt, RcDetails::get().PayloadTooLarge);
9593
return Http::FilterDataStatus::StopIterationNoBuffer;
9694
}
9795

@@ -138,7 +136,7 @@ void NatsStreamingFilter::retrieveRouteSpecificFilterConfig() {
138136
// remains valid for the current request.
139137
route_ = decoder_callbacks_->route();
140138

141-
const auto *route_local = Http::SoloFilterUtility::resolvePerFilterConfig<
139+
const auto *route_local = Http::Utility::resolveMostSpecificPerFilterConfig<
142140
const NatsStreamingRouteSpecificFilterConfig>(name, route_);
143141

144142
if (route_local != nullptr) {
@@ -178,7 +176,8 @@ void NatsStreamingFilter::onCompletion(Http::Code response_code,
178176
in_flight_request_ = nullptr;
179177

180178
decoder_callbacks_->sendLocalReply(response_code, body_text, nullptr,
181-
absl::nullopt, RcDetails::get().Completion);
179+
absl::nullopt,
180+
RcDetails::get().Completion);
182181
}
183182

184183
void NatsStreamingFilter::onCompletion(Http::Code response_code,

source/extensions/filters/http/transformation/BUILD

+23-4
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,17 @@ load("@envoy_api//bazel:api_build_system.bzl", "api_proto_library")
1414

1515
envoy_cc_library(
1616
name = "transformation_filter_config",
17+
srcs = [
18+
"transformation_filter_config.cc",
19+
],
1720
hdrs = [
1821
"transformation_filter_config.h",
1922
],
2023
repository = "@envoy",
2124
deps = [
25+
":body_header_transformer_lib",
26+
":inja_transformer_lib",
27+
":transformer_lib",
2228
"//api/envoy/config/filter/http/transformation/v2:transformation_filter_proto_cc",
2329
"@envoy//include/envoy/router:router_interface",
2430
],
@@ -34,7 +40,6 @@ envoy_cc_library(
3440
],
3541
repository = "@envoy",
3642
deps = [
37-
":body_header_transformer_lib",
3843
":transformation_filter_config",
3944
":transformer_lib",
4045
"//source/common/http:solo_filter_utility_lib",
@@ -55,22 +60,24 @@ envoy_cc_library(
5560
],
5661
repository = "@envoy",
5762
deps = [
63+
":transformer_lib",
5864
"@envoy//include/envoy/buffer:buffer_interface",
5965
"@envoy//source/common/http:header_map_lib",
6066
"@json//:json-lib",
6167
],
6268
)
6369

6470
envoy_cc_library(
65-
name = "transformer_lib",
71+
name = "inja_transformer_lib",
6672
srcs = [
67-
"transformer.cc",
73+
"inja_transformer.cc",
6874
],
6975
hdrs = [
70-
"transformer.h",
76+
"inja_transformer.h",
7177
],
7278
repository = "@envoy",
7379
deps = [
80+
":transformer_lib",
7481
"//api/envoy/config/filter/http/transformation/v2:transformation_filter_proto_cc",
7582
"@envoy//include/envoy/buffer:buffer_interface",
7683
"@envoy//include/envoy/http:header_map_interface",
@@ -81,6 +88,18 @@ envoy_cc_library(
8188
],
8289
)
8390

91+
envoy_cc_library(
92+
name = "transformer_lib",
93+
hdrs = [
94+
"transformer.h",
95+
],
96+
repository = "@envoy",
97+
deps = [
98+
"@envoy//include/envoy/buffer:buffer_interface",
99+
"@envoy//include/envoy/http:header_map_interface",
100+
],
101+
)
102+
84103
envoy_cc_library(
85104
name = "transformation_filter_config_lib",
86105
srcs = ["transformation_filter_config_factory.cc"],

source/extensions/filters/http/transformation/body_header_transformer.cc

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include "common/http/headers.h"
44

5+
#include "nlohmann/json.hpp"
6+
57
// For convenience
68
using json = nlohmann::json;
79

@@ -11,7 +13,7 @@ namespace HttpFilters {
1113
namespace Transformation {
1214

1315
void BodyHeaderTransformer::transform(Http::HeaderMap &header_map,
14-
Buffer::Instance &body) {
16+
Buffer::Instance &body) const {
1517
json json_body;
1618
if (body.length() > 0) {
1719
json_body["body"] = body.toString();
@@ -23,7 +25,8 @@ void BodyHeaderTransformer::transform(Http::HeaderMap &header_map,
2325
void *context) -> Http::HeaderMap::Iterate {
2426
json *headers_ptr = static_cast<json *>(context);
2527
json &headers = *headers_ptr;
26-
headers[std::string(header.key().getStringView())] = std::string(header.value().getStringView());
28+
headers[std::string(header.key().getStringView())] =
29+
std::string(header.value().getStringView());
2730
return Http::HeaderMap::Iterate::Continue;
2831
},
2932
&headers);

source/extensions/filters/http/transformation/body_header_transformer.h

+3-6
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,16 @@
22

33
#include <map>
44

5-
#include "envoy/buffer/buffer.h"
6-
#include "envoy/http/header_map.h"
7-
8-
#include "nlohmann/json.hpp"
5+
#include "extensions/filters/http/transformation/transformer.h"
96

107
namespace Envoy {
118
namespace Extensions {
129
namespace HttpFilters {
1310
namespace Transformation {
1411

15-
class BodyHeaderTransformer {
12+
class BodyHeaderTransformer : public Transformer {
1613
public:
17-
void transform(Http::HeaderMap &map, Buffer::Instance &body);
14+
void transform(Http::HeaderMap &map, Buffer::Instance &body) const override;
1815
};
1916

2017
} // namespace Transformation

0 commit comments

Comments
 (0)