From 9ce8e61862c1776e1096b2d014e22256fe3e0ac1 Mon Sep 17 00:00:00 2001 From: Brian Pane Date: Fri, 5 Jan 2018 01:59:08 +0000 Subject: [PATCH 1/5] Add DirectResponseAction, a new route action type that returns a hard-coded HTTP response. https://github.com/envoyproxy/envoy/issues/2315 Signed-off-by: Brian Pane --- api/rds.proto | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/api/rds.proto b/api/rds.proto index 531ace44c..e76bebdc7 100644 --- a/api/rds.proto +++ b/api/rds.proto @@ -178,6 +178,9 @@ message Route { // Return a redirect. RedirectAction redirect = 3; + + // [#not-implemented-hide:] Return an arbitrary HTTP response directly, without proxying. + DirectResponseAction response = 7; } // The Metadata field can be used to provide additional information @@ -585,6 +588,22 @@ message RedirectAction { RedirectResponseCode response_code = 3 [(validate.rules).enum.defined_only = true]; } +message DirectResponseAction { + // Specifies the HTTP response status to be returned. + google.protobuf.UInt32Value status = 1 [(validate.rules).message.required = true]; + + // Specifies the human-readable status to be returned if + // the response is encoded as HTTP/1.x. + string reason = 2; + + // Specifies the response content-type. This setting defaults to text/plain. + string content_type = 3; + + // Specifies the content of the response body. If this setting is omitted, + // no body is included in the generated response. + string body = 4; +} + message Decorator { // The operation name associated with the request matched to this route. If tracing is // enabled, this information will be used as the span name reported for this request. From d7ccda31834d1503ff072c6b645a2c68031f768f Mon Sep 17 00:00:00 2001 From: Brian Pane Date: Fri, 5 Jan 2018 19:33:55 +0000 Subject: [PATCH 2/5] Generalize DirectResponseAction to support arbitrary headers, plus a DataSource for body Signed-off-by: Brian Pane --- api/base.proto | 16 ++++++++++++++++ api/rds.proto | 12 ++++-------- api/sds.proto | 12 ------------ 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/api/base.proto b/api/base.proto index f4b7946e6..ae077d5c7 100644 --- a/api/base.proto +++ b/api/base.proto @@ -157,6 +157,22 @@ message HeaderValueOption { google.protobuf.BoolValue append = 2; } +// Data source consisting of either a file or an inline value. +message DataSource { + oneof specifier { + option (validate.required) = true; + + // Local filesystem data source. + string filename = 1 [(validate.rules).string.min_bytes = 1]; + + // Bytes inlined in the configuration. + bytes inline = 2 [(validate.rules).bytes.min_len = 1]; + + // String inlined in the configuration. + string inline_string = 3 [(validate.rules).string.min_bytes = 1]; + } +} + // API configuration source. This identifies the API type and cluster that Envoy // will use to fetch an xDS API. message ApiConfigSource { diff --git a/api/rds.proto b/api/rds.proto index e76bebdc7..e1003d464 100644 --- a/api/rds.proto +++ b/api/rds.proto @@ -180,7 +180,7 @@ message Route { RedirectAction redirect = 3; // [#not-implemented-hide:] Return an arbitrary HTTP response directly, without proxying. - DirectResponseAction response = 7; + DirectResponseAction direct_response = 7; } // The Metadata field can be used to provide additional information @@ -592,16 +592,12 @@ message DirectResponseAction { // Specifies the HTTP response status to be returned. google.protobuf.UInt32Value status = 1 [(validate.rules).message.required = true]; - // Specifies the human-readable status to be returned if - // the response is encoded as HTTP/1.x. - string reason = 2; - - // Specifies the response content-type. This setting defaults to text/plain. - string content_type = 3; + // Specifies headers to include in the HTTP response. + repeated HeaderValue response_headers = 2; // Specifies the content of the response body. If this setting is omitted, // no body is included in the generated response. - string body = 4; + DataSource body = 4; } message Decorator { diff --git a/api/sds.proto b/api/sds.proto index e4b1bae4f..0310f0098 100644 --- a/api/sds.proto +++ b/api/sds.proto @@ -24,18 +24,6 @@ service SecretDiscoveryService { } } -message DataSource { - oneof specifier { - option (validate.required) = true; - - // Local filesystem data source. - string filename = 1 [(validate.rules).string.min_bytes = 1]; - - // Bytes inlined in the configuration. - bytes inline = 2 [(validate.rules).bytes.min_len = 1]; - } -} - message TlsParameters { enum TlsProtocol { // Envoy will choose the optimal TLS version. From 4c86843624da85ae182d6865e07b78adf96b85d2 Mon Sep 17 00:00:00 2001 From: Brian Pane Date: Fri, 5 Jan 2018 19:42:19 +0000 Subject: [PATCH 3/5] Update DataSource field names for consistency Signed-off-by: Brian Pane --- api/base.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/base.proto b/api/base.proto index ae077d5c7..7f6e67953 100644 --- a/api/base.proto +++ b/api/base.proto @@ -166,7 +166,7 @@ message DataSource { string filename = 1 [(validate.rules).string.min_bytes = 1]; // Bytes inlined in the configuration. - bytes inline = 2 [(validate.rules).bytes.min_len = 1]; + bytes inline_bytes = 2 [(validate.rules).bytes.min_len = 1]; // String inlined in the configuration. string inline_string = 3 [(validate.rules).string.min_bytes = 1]; From ebdbd8f1a115802906c6d8fdb6b5495484c97d95 Mon Sep 17 00:00:00 2001 From: Brian Pane Date: Fri, 5 Jan 2018 20:23:41 +0000 Subject: [PATCH 4/5] Use a simple integer type for the status, and add a [100,599) range validator Signed-off-by: Brian Pane --- api/rds.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/rds.proto b/api/rds.proto index e1003d464..7fb884a8b 100644 --- a/api/rds.proto +++ b/api/rds.proto @@ -590,7 +590,7 @@ message RedirectAction { message DirectResponseAction { // Specifies the HTTP response status to be returned. - google.protobuf.UInt32Value status = 1 [(validate.rules).message.required = true]; + uint32 status = 1 [(validate.rules).uint32 = {gte: 100, lt: 600}]; // Specifies headers to include in the HTTP response. repeated HeaderValue response_headers = 2; From 89118356992af61b6a9d70e980b5e70322fa4ccf Mon Sep 17 00:00:00 2001 From: Brian Pane Date: Fri, 5 Jan 2018 23:09:19 +0000 Subject: [PATCH 5/5] Remove the headers field and link to the one in RouteConfiguration Signed-off-by: Brian Pane --- api/rds.proto | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/api/rds.proto b/api/rds.proto index 7fb884a8b..a45dcd301 100644 --- a/api/rds.proto +++ b/api/rds.proto @@ -592,12 +592,14 @@ message DirectResponseAction { // Specifies the HTTP response status to be returned. uint32 status = 1 [(validate.rules).uint32 = {gte: 100, lt: 600}]; - // Specifies headers to include in the HTTP response. - repeated HeaderValue response_headers = 2; - // Specifies the content of the response body. If this setting is omitted, // no body is included in the generated response. - DataSource body = 4; + // + // .. note:: + // + // Headers can be specified using *response_headers_to_add* in + // :ref:`envoy_api_msg_RouteConfiguration`. + DataSource body = 2; } message Decorator {