diff --git a/ngrok/src/config/http.rs b/ngrok/src/config/http.rs index 4f54c6a..c73c68d 100644 --- a/ngrok/src/config/http.rs +++ b/ngrok/src/config/http.rs @@ -121,6 +121,7 @@ struct HttpOptions { pub(crate) webhook_verification: Option, // Flitering placed on the origin of incoming connections to the edge. pub(crate) user_agent_filter: UaFilter, + pub(crate) bindings: Vec, } impl HttpOptions { @@ -151,6 +152,7 @@ impl TunnelConfig for HttpOptions { token: Default::default(), ip_policy_ref: Default::default(), metadata: self.common_opts.metadata.clone().unwrap_or_default(), + bindings: self.bindings.clone(), } } fn proto(&self) -> String { @@ -251,6 +253,11 @@ impl HttpTunnelBuilder { self.options.common_opts.metadata = Some(metadata.into()); self } + /// Sets the ingress configuration for this endpoint + pub fn binding(&mut self, binding: impl Into) -> &mut Self { + self.options.bindings.push(binding.into()); + self + } /// Sets the ForwardsTo string for this tunnel. This can be viewed via the /// API or dashboard. /// @@ -455,7 +462,7 @@ impl HttpTunnelBuilder { mod test { use super::*; use crate::config::policies::test::POLICY_JSON; - + const BINDING: &str = "public"; const METADATA: &str = "testmeta"; const TEST_FORWARD: &str = "testforward"; const TEST_FORWARD_PROTO: &str = "http2"; @@ -482,6 +489,7 @@ mod test { .deny_cidr(DENY_CIDR) .proxy_proto(ProxyProto::V2) .metadata(METADATA) + .binding(BINDING) .scheme(Scheme::from_str("hTtPs").unwrap()) .domain(DOMAIN) .mutual_tlsca(CA_CERT.into()) @@ -526,6 +534,7 @@ mod test { let extra = tunnel_cfg.extra(); assert_eq!(String::default(), *extra.token); assert_eq!(METADATA, extra.metadata); + assert_eq!(Vec::from([BINDING]), extra.bindings); assert_eq!(String::default(), extra.ip_policy_ref); assert_eq!("https", tunnel_cfg.proto()); diff --git a/ngrok/src/config/labeled.rs b/ngrok/src/config/labeled.rs index 5e6ee14..7109d52 100644 --- a/ngrok/src/config/labeled.rs +++ b/ngrok/src/config/labeled.rs @@ -50,6 +50,7 @@ impl TunnelConfig for LabeledOptions { token: Default::default(), ip_policy_ref: Default::default(), metadata: self.common_opts.metadata.clone().unwrap_or_default(), + bindings: Vec::new(), } } fn proto(&self) -> String { diff --git a/ngrok/src/config/tcp.rs b/ngrok/src/config/tcp.rs index 33f23ac..a89957d 100644 --- a/ngrok/src/config/tcp.rs +++ b/ngrok/src/config/tcp.rs @@ -32,6 +32,7 @@ use crate::{ struct TcpOptions { pub(crate) common_opts: CommonOpts, pub(crate) remote_addr: Option, + pub(crate) bindings: Vec, } impl TunnelConfig for TcpOptions { @@ -46,6 +47,7 @@ impl TunnelConfig for TcpOptions { token: Default::default(), ip_policy_ref: Default::default(), metadata: self.common_opts.metadata.clone().unwrap_or_default(), + bindings: self.bindings.clone(), } } fn proto(&self) -> String { @@ -116,6 +118,11 @@ impl TcpTunnelBuilder { self.options.common_opts.metadata = Some(metadata.into()); self } + /// Sets the ingress configuration for this endpoint + pub fn binding(&mut self, binding: impl Into) -> &mut Self { + self.options.bindings.push(binding.into()); + self + } /// Sets the ForwardsTo string for this tunnel. This can be viewed via the /// API or dashboard. /// @@ -164,7 +171,7 @@ impl TcpTunnelBuilder { mod test { use super::*; use crate::config::policies::test::POLICY_JSON; - + const BINDING: &str = "public"; const METADATA: &str = "testmeta"; const TEST_FORWARD: &str = "testforward"; const REMOTE_ADDR: &str = "4.tcp.ngrok.io:1337"; @@ -184,6 +191,7 @@ mod test { .deny_cidr(DENY_CIDR) .proxy_proto(ProxyProto::V2) .metadata(METADATA) + .binding(BINDING) .remote_addr(REMOTE_ADDR) .forwards_to(TEST_FORWARD) .policy(POLICY_JSON) @@ -201,6 +209,7 @@ mod test { let extra = tunnel_cfg.extra(); assert_eq!(String::default(), *extra.token); assert_eq!(METADATA, extra.metadata); + assert_eq!(Vec::from([BINDING]), extra.bindings); assert_eq!(String::default(), extra.ip_policy_ref); assert_eq!("tcp", tunnel_cfg.proto()); diff --git a/ngrok/src/config/tls.rs b/ngrok/src/config/tls.rs index 69fd037..3d34806 100644 --- a/ngrok/src/config/tls.rs +++ b/ngrok/src/config/tls.rs @@ -37,6 +37,7 @@ struct TlsOptions { pub(crate) mutual_tlsca: Vec, pub(crate) key_pem: Option, pub(crate) cert_pem: Option, + pub(crate) bindings: Vec, } impl TunnelConfig for TlsOptions { @@ -61,6 +62,7 @@ impl TunnelConfig for TlsOptions { token: Default::default(), ip_policy_ref: Default::default(), metadata: self.common_opts.metadata.clone().unwrap_or_default(), + bindings: self.bindings.clone(), } } fn proto(&self) -> String { @@ -135,6 +137,11 @@ impl TlsTunnelBuilder { self.options.common_opts.metadata = Some(metadata.into()); self } + /// Sets the ingress configuration for this endpoint + pub fn binding(&mut self, binding: impl Into) -> &mut Self { + self.options.bindings.push(binding.into()); + self + } /// Sets the ForwardsTo string for this tunnel. This can be viewed via the /// API or dashboard. /// @@ -205,6 +212,7 @@ mod test { use super::*; use crate::config::policies::test::POLICY_JSON; + const BINDING: &str = "public"; const METADATA: &str = "testmeta"; const TEST_FORWARD: &str = "testforward"; const ALLOW_CIDR: &str = "0.0.0.0/0"; @@ -228,6 +236,7 @@ mod test { .deny_cidr(DENY_CIDR) .proxy_proto(ProxyProto::V2) .metadata(METADATA) + .binding(BINDING) .domain(DOMAIN) .mutual_tlsca(CA_CERT.into()) .mutual_tlsca(CA_CERT2.into()) @@ -248,6 +257,7 @@ mod test { let extra = tunnel_cfg.extra(); assert_eq!(String::default(), *extra.token); assert_eq!(METADATA, extra.metadata); + assert_eq!(Vec::from([BINDING]), extra.bindings); assert_eq!(String::default(), extra.ip_policy_ref); assert_eq!("tls", tunnel_cfg.proto()); diff --git a/ngrok/src/internals/proto.rs b/ngrok/src/internals/proto.rs index 7dfa9ba..2055ca1 100644 --- a/ngrok/src/internals/proto.rs +++ b/ngrok/src/internals/proto.rs @@ -322,6 +322,7 @@ pub struct BindExtra { #[serde(rename = "IPPolicyRef")] pub ip_policy_ref: String, pub metadata: String, + pub bindings: Vec, } #[derive(Serialize, Deserialize, Debug, Clone)] diff --git a/ngrok/src/online_tests.rs b/ngrok/src/online_tests.rs index 3c0dd76..63dcb96 100644 --- a/ngrok/src/online_tests.rs +++ b/ngrok/src/online_tests.rs @@ -98,6 +98,7 @@ async fn tunnel() -> Result<(), Error> { let tun = setup_session() .await? .http_endpoint() + .binding("public") .metadata("Hello, world!") .forwards_to("some application") .listen()