From cd75a08b7345f571c21bde62886f95e0b32a88be Mon Sep 17 00:00:00 2001 From: "data-plane-api(Azure Pipelines)" Date: Wed, 14 Sep 2022 16:16:57 +0000 Subject: [PATCH] Full Set Of Changes For Pattern Match and Rewrite (#22207) This PR will implement issue detailed here and described below: #7763 Match Patterns and Templates Wildcard support based on match patterns and templates. A match pattern matches an incoming URL path. Match patterns support glob operators to match URL text and variable definitions to bind matched text to names. Template patterns are used to re-write URLs. Template patterns build new URLs and may reference variables bound by a match pattern. Match Examples /**.m3u8 would match /foo.m3u8 and /foo/bar.m3u8. /{dir_name}/*.ts would match /example/file.ts and bind dir_name="example" for a later template match to use. /{dir_name}/**.ts would match /example/path/file.ts and bind dir_name="example" for a later template match to use. This would also match /example/.ts, which may or may not be a desired behavior. /{path=v1/*}/{file=*.ts} would match /v1/example/movie.ts (binding path="v1/example" and file="movie"), but would not match /v0/example/movie.ts. See post for full details and example: #7763 (comment) Risk Level: Testing: Unit tests. Both both internal matching/rewrite library and config/data plane changes. Signed-off-by: silverstar195 Mirrored from https://github.com/envoyproxy/envoy @ 8cfc61f916cf52ce8bce6710686e9d4fca2c06bd --- BUILD | 4 ++-- envoy/config/route/v3/route_components.proto | 18 ++++++++---------- .../v3/BUILD | 0 .../v3/uri_template_match.proto} | 14 +++++++------- .../v3/BUILD | 0 .../v3/uri_template_rewrite.proto} | 14 +++++++------- versioning/BUILD | 4 ++-- 7 files changed, 26 insertions(+), 28 deletions(-) rename envoy/extensions/path/match/{pattern_template => uri_template}/v3/BUILD (100%) rename envoy/extensions/path/match/{pattern_template/v3/pattern_template_match.proto => uri_template/v3/uri_template_match.proto} (80%) rename envoy/extensions/path/rewrite/{pattern_template => uri_template}/v3/BUILD (100%) rename envoy/extensions/path/rewrite/{pattern_template/v3/pattern_template_rewrite.proto => uri_template/v3/uri_template_rewrite.proto} (87%) diff --git a/BUILD b/BUILD index 52c4178f..1d438047 100644 --- a/BUILD +++ b/BUILD @@ -243,8 +243,8 @@ proto_library( "//envoy/extensions/network/dns_resolver/cares/v3:pkg", "//envoy/extensions/network/dns_resolver/getaddrinfo/v3:pkg", "//envoy/extensions/network/socket_interface/v3:pkg", - "//envoy/extensions/path/match/pattern_template/v3:pkg", - "//envoy/extensions/path/rewrite/pattern_template/v3:pkg", + "//envoy/extensions/path/match/uri_template/v3:pkg", + "//envoy/extensions/path/rewrite/uri_template/v3:pkg", "//envoy/extensions/quic/crypto_stream/v3:pkg", "//envoy/extensions/quic/proof_source/v3:pkg", "//envoy/extensions/rate_limit_descriptors/expr/v3:pkg", diff --git a/envoy/config/route/v3/route_components.proto b/envoy/config/route/v3/route_components.proto index e2c46a97..86a14434 100644 --- a/envoy/config/route/v3/route_components.proto +++ b/envoy/config/route/v3/route_components.proto @@ -572,8 +572,7 @@ message RouteMatch { // Expect the value to not contain ``?`` or ``#`` and not to end in ``/`` string path_separated_prefix = 14 [(validate.rules).string = {pattern: "^[^?#]+[^?#/]$"}]; - // [#not-implemented-hide:] - // [#comment: TODO(silverstar195): Hook into extension once added] + // [#extension-category: envoy.path.match] core.v3.TypedExtensionConfig path_match_policy = 15; } @@ -1030,9 +1029,9 @@ message RouteAction { // place the original path before rewrite into the :ref:`x-envoy-original-path // ` header. // - // Only one of :ref:`regex_rewrite ` or - // [#comment:TODO(silverstar194) add the following once implemented: :ref:`path_rewrite_policy `] - // :ref:`prefix_rewrite ` may be specified. + // Only one of :ref:`regex_rewrite ` + // :ref:`path_rewrite_policy `, + // or :ref:`prefix_rewrite ` may be specified. // // .. attention:: // @@ -1067,9 +1066,9 @@ message RouteAction { // before the rewrite into the :ref:`x-envoy-original-path // ` header. // - // Only one of :ref:`regex_rewrite ` - // or :ref:`prefix_rewrite ` - // [#comment:TODO(silverstar194) add the following once implemented: :ref:`path_rewrite_policy `] + // Only one of :ref:`regex_rewrite `, + // :ref:`prefix_rewrite `, or + // :ref:`path_rewrite_policy `] // may be specified. // // Examples using Google's `RE2 `_ engine: @@ -1090,8 +1089,7 @@ message RouteAction { // ``/aaa/yyy/bbb``. type.matcher.v3.RegexMatchAndSubstitute regex_rewrite = 32; - // [#not-implemented-hide:] - // [#comment: TODO(silverstar195): Hook into extension once added] + // [#extension-category: envoy.path.rewrite] core.v3.TypedExtensionConfig path_rewrite_policy = 41; oneof host_rewrite_specifier { diff --git a/envoy/extensions/path/match/pattern_template/v3/BUILD b/envoy/extensions/path/match/uri_template/v3/BUILD similarity index 100% rename from envoy/extensions/path/match/pattern_template/v3/BUILD rename to envoy/extensions/path/match/uri_template/v3/BUILD diff --git a/envoy/extensions/path/match/pattern_template/v3/pattern_template_match.proto b/envoy/extensions/path/match/uri_template/v3/uri_template_match.proto similarity index 80% rename from envoy/extensions/path/match/pattern_template/v3/pattern_template_match.proto rename to envoy/extensions/path/match/uri_template/v3/uri_template_match.proto index 24e6d96c..27579f5b 100644 --- a/envoy/extensions/path/match/pattern_template/v3/pattern_template_match.proto +++ b/envoy/extensions/path/match/uri_template/v3/uri_template_match.proto @@ -1,17 +1,18 @@ syntax = "proto3"; -package envoy.extensions.path.match.pattern_template.v3; +package envoy.extensions.path.match.uri_template.v3; import "udpa/annotations/status.proto"; import "validate/validate.proto"; -option java_package = "io.envoyproxy.envoy.extensions.path.match.pattern_template.v3"; -option java_outer_classname = "PatternTemplateMatchProto"; +option java_package = "io.envoyproxy.envoy.extensions.path.match.uri_template.v3"; +option java_outer_classname = "UriTemplateMatchProto"; option java_multiple_files = true; -option go_package = "github.com/envoyproxy/go-control-plane/envoy/extensions/path/match/pattern_template/v3;pattern_templatev3"; +option go_package = "github.com/envoyproxy/go-control-plane/envoy/extensions/path/match/uri_template/v3;uri_templatev3"; option (udpa.annotations.file_status).package_version_status = ACTIVE; -// [#protodoc-title: Pattern Template Match Config] +// [#protodoc-title: Uri Template Match Config] +// [#extension: envoy.path.match.uri_template.uri_template_matcher] // If specified, the route is a template match rule meaning that the // ``:path`` header (without the query string) must match the given @@ -38,7 +39,6 @@ option (udpa.annotations.file_status).package_version_status = ACTIVE; // * ``/videos/{file}`` would match ``/videos/1080p5000_00001.m4s`` // // * ``/**.mpd`` would match ``/content/123/india/dash/55/manifest.mpd`` -// [#not-implemented-hide:] -message PatternTemplateMatchConfig { +message UriTemplateMatchConfig { string path_template = 1 [(validate.rules).string = {min_len: 1 max_len: 256}]; } diff --git a/envoy/extensions/path/rewrite/pattern_template/v3/BUILD b/envoy/extensions/path/rewrite/uri_template/v3/BUILD similarity index 100% rename from envoy/extensions/path/rewrite/pattern_template/v3/BUILD rename to envoy/extensions/path/rewrite/uri_template/v3/BUILD diff --git a/envoy/extensions/path/rewrite/pattern_template/v3/pattern_template_rewrite.proto b/envoy/extensions/path/rewrite/uri_template/v3/uri_template_rewrite.proto similarity index 87% rename from envoy/extensions/path/rewrite/pattern_template/v3/pattern_template_rewrite.proto rename to envoy/extensions/path/rewrite/uri_template/v3/uri_template_rewrite.proto index 2d5cebe8..0d35ca52 100644 --- a/envoy/extensions/path/rewrite/pattern_template/v3/pattern_template_rewrite.proto +++ b/envoy/extensions/path/rewrite/uri_template/v3/uri_template_rewrite.proto @@ -1,17 +1,18 @@ syntax = "proto3"; -package envoy.extensions.path.rewrite.pattern_template.v3; +package envoy.extensions.path.rewrite.uri_template.v3; import "udpa/annotations/status.proto"; import "validate/validate.proto"; -option java_package = "io.envoyproxy.envoy.extensions.path.rewrite.pattern_template.v3"; -option java_outer_classname = "PatternTemplateRewriteProto"; +option java_package = "io.envoyproxy.envoy.extensions.path.rewrite.uri_template.v3"; +option java_outer_classname = "UriTemplateRewriteProto"; option java_multiple_files = true; -option go_package = "github.com/envoyproxy/go-control-plane/envoy/extensions/path/rewrite/pattern_template/v3;pattern_templatev3"; +option go_package = "github.com/envoyproxy/go-control-plane/envoy/extensions/path/rewrite/uri_template/v3;uri_templatev3"; option (udpa.annotations.file_status).package_version_status = ACTIVE; -// [#protodoc-title: Pattern Template Rewrite Config] +// [#protodoc-title: Uri Template Rewrite Config] +// [#extension: envoy.path.rewrite.uri_template.uri_template_rewriter] // Indicates that during forwarding, portions of the path that match the // pattern should be rewritten, even allowing the substitution of variables @@ -52,7 +53,6 @@ option (udpa.annotations.file_status).package_version_status = ACTIVE; // * The path pattern ``/content/{format}/{lang}/{id}/{file}.vtt`` paired with a substitution // string of ``/{lang}/{format}/{file}.vtt`` would transform ``/content/hls/en-us/12345/en_193913.vtt`` // into ``/en-us/hls/en_193913.vtt``. -// [#not-implemented-hide:] -message PatternTemplateRewriteConfig { +message UriTemplateRewriteConfig { string path_template_rewrite = 1 [(validate.rules).string = {min_len: 1 max_len: 256}]; } diff --git a/versioning/BUILD b/versioning/BUILD index 69f18bb8..e8817753 100644 --- a/versioning/BUILD +++ b/versioning/BUILD @@ -186,8 +186,8 @@ proto_library( "//envoy/extensions/network/dns_resolver/cares/v3:pkg", "//envoy/extensions/network/dns_resolver/getaddrinfo/v3:pkg", "//envoy/extensions/network/socket_interface/v3:pkg", - "//envoy/extensions/path/match/pattern_template/v3:pkg", - "//envoy/extensions/path/rewrite/pattern_template/v3:pkg", + "//envoy/extensions/path/match/uri_template/v3:pkg", + "//envoy/extensions/path/rewrite/uri_template/v3:pkg", "//envoy/extensions/quic/crypto_stream/v3:pkg", "//envoy/extensions/quic/proof_source/v3:pkg", "//envoy/extensions/rate_limit_descriptors/expr/v3:pkg",