From aa48962c8c5c3085efff8a8b0d8355a735547e8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charles-Edouard=20Br=C3=A9t=C3=A9ch=C3=A9?= Date: Thu, 7 Nov 2024 16:31:15 +0100 Subject: [PATCH] docs: add envoy lib examples (#201) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Charles-Edouard Brétéché --- website/docs/cel-extensions/envoy.md | 103 ++++++++++++++++++++++----- 1 file changed, 86 insertions(+), 17 deletions(-) diff --git a/website/docs/cel-extensions/envoy.md b/website/docs/cel-extensions/envoy.md index 59bba39..7d34120 100644 --- a/website/docs/cel-extensions/envoy.md +++ b/website/docs/cel-extensions/envoy.md @@ -28,7 +28,9 @@ envoy.Allowed() -> #### Example -TODO +``` +envoy.Allowed() +``` ### envoy.Denied @@ -42,7 +44,9 @@ envoy.Denied( code) -> #### Example -TODO +``` +envoy.Denied(401) +``` ### envoy.Response @@ -62,7 +66,19 @@ envoy.Response( denied) -> #### Example -TODO +``` +// ok +envoy.Response(0) + +// permission denied +envoy.Response(7) +``` +``` +envoy.Response(envoy.Allowed()) +``` +``` +envoy.Response(envoy.Denied(401)) +``` ### envoy.Null @@ -76,7 +92,9 @@ envoy.Null() -> #### Example -TODO +``` +envoy.Null() +``` ### envoy.Header @@ -90,7 +108,9 @@ envoy.Header( key, value) -> #### Example -TODO +``` +envoy.Header("foo", "bar") +``` ### WithBody @@ -104,12 +124,16 @@ This function sets the body of a `` object. #### Example -TODO +``` +envoy.Denied(401).WithBody("Unauthorized Request") +``` ### WithHeader -This function adds a `` when the request is sent upstream by Envoy, in the case of an `OkHttpResponse`. -This function adds a `` when the response is sent downstream by Envoy, in the case of a `DeniedHttpResponse`. +This function adds a ``: + +- When the request is sent upstream by Envoy, in the case of an ``. +- When the response is sent downstream by Envoy, in the case of a ``. #### Signature and overloads @@ -128,7 +152,18 @@ This function adds a `` when the response is sent downstream #### Example -TODO +``` +envoy.Allowed().WithHeader(envoy.Header("foo", "bar")) +``` +``` +envoy.Allowed().WithHeader("foo", "bar") +``` +``` +envoy.Denied(401).WithHeader(envoy.Header("foo", "bar")) +``` +``` +envoy.Denied(401).WithHeader("foo", "bar") +``` ### WithoutHeader @@ -142,7 +177,9 @@ This function marks a header to be removed when the request is sent upstream by #### Example -TODO +``` +envoy.Allowed().WithoutHeader("foo") +``` ### WithResponseHeader @@ -159,7 +196,12 @@ This function adds a `` when the response is sent downstream #### Example -TODO +``` +envoy.Allowed().WithResponseHeader(envoy.Header("foo", "bar")) +``` +``` +envoy.Allowed().WithResponseHeader("foo", "bar") +``` ### WithQueryParam @@ -173,7 +215,12 @@ This function adds a `` to be added when the request is sent ups #### Example -TODO +``` +envoy.Allowed().WithQueryParam(envoy.config.core.v3.QueryParameter{ + key: "foo", + bar: "bar" +}) +``` ### WithoutQueryParam @@ -187,7 +234,9 @@ This function marks a query parameter to be removed when the request is sent ups #### Example -TODO +``` +envoy.Allowed().WithoutQueryParam("foo") +``` ### KeepEmptyValue @@ -204,7 +253,12 @@ This function sets the `keep_empty_value` field of an `` obje #### Example -TODO +``` +envoy.Header("foo", "bar").KeepEmptyValue() +``` +``` +envoy.Header("foo", "bar").KeepEmptyValue(true) +``` ### Response @@ -221,7 +275,12 @@ This function creates a `` object from an `` or ` #### Example -TODO +``` +envoy.Allowed().Response() +``` +``` +envoy.Denied(401).Response() +``` ### WithMessage @@ -235,7 +294,12 @@ This function sets the `status.message` field of a `` object. #### Example -TODO +``` +envoy.Allowed().Response().WithMessage("hello world!") +``` +``` +envoy.Denied(401).Response().WithMessage("hello world!") +``` ### WithMetadata @@ -249,4 +313,9 @@ This function sets the `dynamic_metadata` field of a `` object. #### Example -TODO +``` +envoy.Allowed().Response().WithMetadata({ "foo": "bar" }) +``` +``` +envoy.Denied(401).Response().WithMetadata({ "foo": "bar" }) +```