diff --git a/cloudflare/src/endpoints/argo_tunnel/data_structures.rs b/cloudflare/src/endpoints/argo_tunnel/data_structures.rs index 9fd104fe..067b522f 100644 --- a/cloudflare/src/endpoints/argo_tunnel/data_structures.rs +++ b/cloudflare/src/endpoints/argo_tunnel/data_structures.rs @@ -25,3 +25,32 @@ pub struct ActiveConnection { } impl ApiResult for Tunnel {} + +/// The result of a route request for a Named Argo Tunnel +#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)] +#[serde(untagged)] +pub enum RouteResult { + Dns(DnsRouteResult), + Lb(LoadBalancerRouteResult), +} + +#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)] +pub struct DnsRouteResult { + pub cname: Change, +} + +#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)] +pub struct LoadBalancerRouteResult { + pub load_balancer: Change, + pub pool: Change, +} + +#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)] +#[serde(rename_all = "lowercase")] +pub enum Change { + Unchanged, + New, + Updated, +} + +impl ApiResult for RouteResult {} diff --git a/cloudflare/src/endpoints/argo_tunnel/mod.rs b/cloudflare/src/endpoints/argo_tunnel/mod.rs index c90556d3..1e2353b9 100644 --- a/cloudflare/src/endpoints/argo_tunnel/mod.rs +++ b/cloudflare/src/endpoints/argo_tunnel/mod.rs @@ -1,5 +1,6 @@ pub mod create_tunnel; mod data_structures; +pub mod route_dns; pub use data_structures::*; diff --git a/cloudflare/src/endpoints/argo_tunnel/route_dns.rs b/cloudflare/src/endpoints/argo_tunnel/route_dns.rs new file mode 100644 index 00000000..105e302f --- /dev/null +++ b/cloudflare/src/endpoints/argo_tunnel/route_dns.rs @@ -0,0 +1,35 @@ +use crate::framework::endpoint::{Endpoint, Method}; + +use super::RouteResult; +use uuid::Uuid; + +/// Route for a Named Argo Tunnel +/// This creates a new route for the identified Tunnel. More than 1 route may co-exist for the same +/// Tunnel. +/// Note that this modifies only metadata on Cloudflare side to route traffic to the Tunnel, but +/// it is still up to the user to run the Tunnel to receive that traffic. +pub struct RouteTunnel<'a> { + pub zone_tag: &'a str, + pub tunnel_id: Uuid, + pub params: Params<'a>, +} + +impl<'a> Endpoint> for RouteTunnel<'a> { + fn method(&self) -> Method { + Method::Put + } + fn path(&self) -> String { + format!("zones/{}/tunnels/{}/routes", self.zone_tag, self.tunnel_id) + } + fn body(&self) -> Option> { + Some(self.params.clone()) + } +} + +/// Params for routing a Named Argo Tunnel +#[derive(Serialize, Clone, Debug)] +#[serde(tag = "type", rename_all = "lowercase")] +pub enum Params<'a> { + Dns { user_hostname: &'a str }, + Lb { lb_name: &'a str, lb_pool: &'a str }, +}