From ec7bae8ce6857bf4e287a867f49dff7cb50ee1b9 Mon Sep 17 00:00:00 2001 From: Ryan Grant Date: Tue, 9 Jul 2024 11:28:26 -0700 Subject: [PATCH] update example to use traffic policy vs policy --- ngrok/examples/axum.rs | 49 +++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/ngrok/examples/axum.rs b/ngrok/examples/axum.rs index dbb9ed9..053ea4c 100644 --- a/ngrok/examples/axum.rs +++ b/ngrok/examples/axum.rs @@ -62,7 +62,7 @@ async fn start_tunnel() -> anyhow::Result { // .allow_domain("") // .scope(""), // ) - // .policy(create_policy())? + // .traffic_policy(POLICY_JSON) // .proxy_proto(ProxyProto::None) // .remove_request_header("X-Req-Nope") // .remove_response_header("X-Res-Nope") @@ -80,27 +80,26 @@ async fn start_tunnel() -> anyhow::Result { Ok(tun) } -#[allow(dead_code)] -fn create_policy() -> Result { - Ok(Policy::new() - .add_inbound( - Rule::new("deny_put") - .add_expression("req.Method == 'PUT'") - .add_action(Action::new("deny", None)?), - ) - .add_outbound( - Rule::new("200_response") - .add_expression("res.StatusCode == '200'") - .add_action(Action::new( - "custom-response", - Some( - r###"{ - "status_code": 200, - "content_type": "text/html", - "content": "Custom 200 response." - }"###, - ), - )?), - ) - .to_owned()) -} +const POLICY_JSON: &str = r###"{ + "Inbound":[ + { + "Name":"deny_put", + "Expressions":["req.Method == 'PUT'"], + "Actions":[{"Type":"deny"}] + }], + "Outbound":[ + { + "Name":"test_out", + "Expressions":["res.StatusCode == '200'"], + "Actions":[{ + "Type":"custom-response", + "Config":{ + "status_code":201, + "content": "Custom 200 response.", + "headers": { + "content_type": "text/html" + } + } + }] + }] +}"###;