From 4309cfe9079b14e9f2b8c57f36646ecd13a00062 Mon Sep 17 00:00:00 2001 From: Arturo Guerra Date: Mon, 9 Dec 2024 16:14:50 -0600 Subject: [PATCH 1/3] Adds support for cfd_tunnel configuration endpoints --- .../endpoints/cfd_tunnel/data_structures.rs | 68 +++++++++++++++++++ .../endpoints/cfd_tunnel/get_configuration.rs | 27 ++++++++ cloudflare/src/endpoints/cfd_tunnel/mod.rs | 2 + .../cfd_tunnel/update_configuration.rs | 37 ++++++++++ 4 files changed, 134 insertions(+) create mode 100644 cloudflare/src/endpoints/cfd_tunnel/get_configuration.rs create mode 100644 cloudflare/src/endpoints/cfd_tunnel/update_configuration.rs diff --git a/cloudflare/src/endpoints/cfd_tunnel/data_structures.rs b/cloudflare/src/endpoints/cfd_tunnel/data_structures.rs index 997e04a1..386b22bc 100644 --- a/cloudflare/src/endpoints/cfd_tunnel/data_structures.rs +++ b/cloudflare/src/endpoints/cfd_tunnel/data_structures.rs @@ -68,9 +68,76 @@ pub struct ActiveConnection { pub client_version: String, } +#[derive(Serialize, Deserialize, Eq, PartialEq, Debug, Clone, Hash)] +#[serde(rename_all = "camelCase")] +pub struct TunnelConfiguration { + pub ingress: Option>, + #[serde(skip_serializing_if = "Option::is_none")] + #[serde(default)] + pub origin_request: Option, + #[serde(rename = "warp-routing")] + #[serde(skip_serializing_if = "Option::is_none")] + #[serde(default)] + pub warp_routing: Option, +} + +#[derive(Serialize, Deserialize, Eq, PartialEq, Debug, Clone, Hash)] +pub struct WarpRouting { + pub enabled: bool, +} + +#[derive(Serialize, Deserialize, Eq, PartialEq, Debug, Clone, Hash)] +#[serde(rename_all = "camelCase")] +pub struct Ingress { + pub hostname: Option, + #[serde(skip_serializing_if = "Option::is_none")] + #[serde(rename = "warp-routing")] + pub origin_request: Option, + pub path: Option, + pub service: String, +} + +#[derive(Serialize, Deserialize, Eq, PartialEq, Debug, Clone, Hash)] +#[serde(rename_all = "camelCase")] +pub struct OriginRequestAccress { + pub aud_tag: Vec, + pub required: bool, + pub team_name: String, +} + +#[derive(Serialize, Deserialize, Eq, PartialEq, Debug, Clone, Hash)] +#[serde(rename_all = "camelCase")] +pub struct OriginRequest { + pub access: Option, + pub ca_pool: Option, + pub connection_timeout: i32, + pub disable_chunked_encoding: bool, + pub http2origin: bool, + pub http_host_header: Option, + pub keep_alive_connections: i32, + pub keep_alive_timeout: i32, + pub no_happy_eyeballs: bool, + pub no_tls_verify: bool, + pub origin_server_name: Option, + pub proxy_type: Option, + pub tcp_keep_alive: i32, + pub tls_timeout: i32, +} + +impl ApiResult for TunnelConfiguration {} impl ApiResult for Tunnel {} impl ApiResult for Vec {} +#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)] +pub struct TunnelConfigurationResult { + pub account_id: Option, + pub created_at: DateTime, + pub config: Option, + pub source: String, + pub tunnel_id: Uuid, + pub version: i32, +} + /// The result of a route request for a Cfd Tunnel #[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)] #[serde(untagged)] @@ -100,4 +167,5 @@ pub enum Change { Updated, } +impl ApiResult for TunnelConfigurationResult {} impl ApiResult for RouteResult {} diff --git a/cloudflare/src/endpoints/cfd_tunnel/get_configuration.rs b/cloudflare/src/endpoints/cfd_tunnel/get_configuration.rs new file mode 100644 index 00000000..08111f65 --- /dev/null +++ b/cloudflare/src/endpoints/cfd_tunnel/get_configuration.rs @@ -0,0 +1,27 @@ +use crate::endpoints::cfd_tunnel::TunnelConfigurationResult; +use crate::framework::endpoint::{EndpointSpec, Method}; +use uuid::Uuid; + +#[derive(Debug)] +pub struct GetTunnelConfiguration<'a> { + pub account_identifier: &'a str, + pub tunnel_id: Uuid, +} + +impl<'a> EndpointSpec for GetTunnelConfiguration<'a> { + fn method(&self) -> Method { + Method::GET + } + + fn path(&self) -> String { + format!( + "accounts/{}/cfd_tunnel/{}/configurations", + self.account_identifier, self.tunnel_id + ) + } + + #[inline] + fn body(&self) -> Option { + None + } +} diff --git a/cloudflare/src/endpoints/cfd_tunnel/mod.rs b/cloudflare/src/endpoints/cfd_tunnel/mod.rs index 1841ae5e..8c1c541f 100644 --- a/cloudflare/src/endpoints/cfd_tunnel/mod.rs +++ b/cloudflare/src/endpoints/cfd_tunnel/mod.rs @@ -1,8 +1,10 @@ pub mod create_tunnel; mod data_structures; pub mod delete_tunnel; +pub mod get_configuration; pub mod list_tunnels; pub mod route_dns; +pub mod update_configuration; pub mod update_tunnel; pub use data_structures::*; diff --git a/cloudflare/src/endpoints/cfd_tunnel/update_configuration.rs b/cloudflare/src/endpoints/cfd_tunnel/update_configuration.rs new file mode 100644 index 00000000..49501afd --- /dev/null +++ b/cloudflare/src/endpoints/cfd_tunnel/update_configuration.rs @@ -0,0 +1,37 @@ +use crate::endpoints::cfd_tunnel::{TunnelConfiguration, TunnelConfigurationResult}; +use crate::framework::endpoint::{EndpointSpec, Method}; +use serde::Serialize; +use serde_with::serde_as; +use uuid::Uuid; + +#[derive(Debug)] +pub struct UpdateTunnelConfiguration<'a> { + pub account_identifier: &'a str, + pub tunnel_id: Uuid, + pub params: Params, +} + +impl<'a> EndpointSpec for UpdateTunnelConfiguration<'a> { + fn method(&self) -> Method { + Method::PUT + } + + fn path(&self) -> String { + format!( + "accounts/{}/cfd_tunnel/{}/configurations", + self.account_identifier, self.tunnel_id + ) + } + + #[inline] + fn body(&self) -> Option { + Some(serde_json::to_string(&self.params).unwrap()) + } +} + +#[serde_as] +#[serde_with::skip_serializing_none] +#[derive(Serialize, Clone, Debug)] +pub struct Params { + pub config: TunnelConfiguration, +} From 3f966332f6f65fc9917cde0c61c969c585783e9c Mon Sep 17 00:00:00 2001 From: Arturo Guerra Date: Tue, 17 Dec 2024 18:11:18 -0600 Subject: [PATCH 2/3] feat: Adds tunnel configuration endpoints --- .../src/endpoints/cfd_tunnel/create_tunnel.rs | 5 +-- .../endpoints/cfd_tunnel/data_structures.rs | 17 ++++++++- .../src/endpoints/cfd_tunnel/get_tunnel.rs | 35 +++++++++++++++++++ .../endpoints/cfd_tunnel/get_tunnel_token.rs | 28 +++++++++++++++ cloudflare/src/endpoints/cfd_tunnel/mod.rs | 2 ++ 5 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 cloudflare/src/endpoints/cfd_tunnel/get_tunnel.rs create mode 100644 cloudflare/src/endpoints/cfd_tunnel/get_tunnel_token.rs diff --git a/cloudflare/src/endpoints/cfd_tunnel/create_tunnel.rs b/cloudflare/src/endpoints/cfd_tunnel/create_tunnel.rs index 7172218e..5bc579b8 100644 --- a/cloudflare/src/endpoints/cfd_tunnel/create_tunnel.rs +++ b/cloudflare/src/endpoints/cfd_tunnel/create_tunnel.rs @@ -41,8 +41,9 @@ pub struct Params<'a> { pub name: &'a str, /// The byte array (with 32 or more bytes) representing a secret for the tunnel. This is /// encoded into JSON as a base64 String. This secret is necessary to run the tunnel. - #[serde_as(as = "Base64")] - pub tunnel_secret: &'a Vec, + #[serde_as(as = "Option>")] + #[serde(default)] + pub tunnel_secret: Option<&'a [u8]>, pub config_src: &'a ConfigurationSrc, diff --git a/cloudflare/src/endpoints/cfd_tunnel/data_structures.rs b/cloudflare/src/endpoints/cfd_tunnel/data_structures.rs index 386b22bc..03e87649 100644 --- a/cloudflare/src/endpoints/cfd_tunnel/data_structures.rs +++ b/cloudflare/src/endpoints/cfd_tunnel/data_structures.rs @@ -1,9 +1,23 @@ +use crate::framework::response::ApiResult; use chrono::{offset::Utc, DateTime}; use serde::{Deserialize, Serialize}; use std::net::IpAddr; use uuid::Uuid; -use crate::framework::response::ApiResult; +#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)] +pub struct TunnelToken(String); + +impl From for TunnelToken { + fn from(s: String) -> TunnelToken { + TunnelToken(s) + } +} + +impl From for String { + fn from(s: TunnelToken) -> String { + s.0 + } +} /// A Cfd Tunnel /// This is an Cfd Tunnel that has been created. It can be used for routing and subsequent running. @@ -127,6 +141,7 @@ pub struct OriginRequest { impl ApiResult for TunnelConfiguration {} impl ApiResult for Tunnel {} impl ApiResult for Vec {} +impl ApiResult for TunnelToken {} #[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)] pub struct TunnelConfigurationResult { diff --git a/cloudflare/src/endpoints/cfd_tunnel/get_tunnel.rs b/cloudflare/src/endpoints/cfd_tunnel/get_tunnel.rs new file mode 100644 index 00000000..92bbc73f --- /dev/null +++ b/cloudflare/src/endpoints/cfd_tunnel/get_tunnel.rs @@ -0,0 +1,35 @@ +use crate::endpoints::cfd_tunnel::{ConfigurationSrc, Tunnel}; +use serde::Serialize; +use serde_with::{ + base64::{Base64, Standard}, + formats::Padded, + serde_as, +}; + +use crate::framework::endpoint::{EndpointSpec, Method}; + +/// Create a Cfd Tunnel +/// This creates the Tunnel, which can then be routed and ran. Creating the Tunnel per se is only +/// a metadata operation (i.e. no Tunnel is running at this point). +/// +#[derive(Debug)] +pub struct GetTunnel<'a> { + pub account_identifier: &'a str, + pub tunnel_id: &'a str, +} + +impl<'a> EndpointSpec for GetTunnel<'a> { + fn method(&self) -> Method { + Method::GET + } + fn path(&self) -> String { + format!( + "accounts/{}/cfd_tunnel/{}", + self.account_identifier, self.tunnel_id + ) + } + #[inline] + fn body(&self) -> Option { + None + } +} diff --git a/cloudflare/src/endpoints/cfd_tunnel/get_tunnel_token.rs b/cloudflare/src/endpoints/cfd_tunnel/get_tunnel_token.rs new file mode 100644 index 00000000..51559fe4 --- /dev/null +++ b/cloudflare/src/endpoints/cfd_tunnel/get_tunnel_token.rs @@ -0,0 +1,28 @@ +use crate::framework::endpoint::{serialize_query, EndpointSpec, Method}; +use serde::Serialize; + +use super::TunnelToken as TunnelTokenResult; + +/// Delete a tunnel +/// +#[derive(Debug)] +pub struct TunnelToken<'a> { + pub account_identifier: &'a str, + pub tunnel_id: &'a str, +} + +impl<'a> EndpointSpec for TunnelToken<'a> { + fn method(&self) -> Method { + Method::GET + } + fn path(&self) -> String { + format!( + "accounts/{}/cfd_tunnel/{}/token", + self.account_identifier, self.tunnel_id + ) + } + #[inline] + fn body(&self) -> Option { + None + } +} diff --git a/cloudflare/src/endpoints/cfd_tunnel/mod.rs b/cloudflare/src/endpoints/cfd_tunnel/mod.rs index 8c1c541f..f5d569a1 100644 --- a/cloudflare/src/endpoints/cfd_tunnel/mod.rs +++ b/cloudflare/src/endpoints/cfd_tunnel/mod.rs @@ -2,6 +2,8 @@ pub mod create_tunnel; mod data_structures; pub mod delete_tunnel; pub mod get_configuration; +pub mod get_tunnel; +pub mod get_tunnel_token; pub mod list_tunnels; pub mod route_dns; pub mod update_configuration; From 313d83ec9b783632ae4de8cbd2031713aa6ba9af Mon Sep 17 00:00:00 2001 From: Arturo Guerra Date: Sat, 21 Dec 2024 13:16:53 -0600 Subject: [PATCH 3/3] feat: Adds the get_tunnel and get_tunnel_token endpoints --- cloudflare/src/endpoints/cfd_tunnel/get_tunnel.rs | 9 +-------- cloudflare/src/endpoints/cfd_tunnel/get_tunnel_token.rs | 4 +--- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/cloudflare/src/endpoints/cfd_tunnel/get_tunnel.rs b/cloudflare/src/endpoints/cfd_tunnel/get_tunnel.rs index 92bbc73f..15199477 100644 --- a/cloudflare/src/endpoints/cfd_tunnel/get_tunnel.rs +++ b/cloudflare/src/endpoints/cfd_tunnel/get_tunnel.rs @@ -1,11 +1,4 @@ -use crate::endpoints::cfd_tunnel::{ConfigurationSrc, Tunnel}; -use serde::Serialize; -use serde_with::{ - base64::{Base64, Standard}, - formats::Padded, - serde_as, -}; - +use crate::endpoints::cfd_tunnel::Tunnel; use crate::framework::endpoint::{EndpointSpec, Method}; /// Create a Cfd Tunnel diff --git a/cloudflare/src/endpoints/cfd_tunnel/get_tunnel_token.rs b/cloudflare/src/endpoints/cfd_tunnel/get_tunnel_token.rs index 51559fe4..b96686c0 100644 --- a/cloudflare/src/endpoints/cfd_tunnel/get_tunnel_token.rs +++ b/cloudflare/src/endpoints/cfd_tunnel/get_tunnel_token.rs @@ -1,7 +1,5 @@ -use crate::framework::endpoint::{serialize_query, EndpointSpec, Method}; -use serde::Serialize; - use super::TunnelToken as TunnelTokenResult; +use crate::framework::endpoint::{EndpointSpec, Method}; /// Delete a tunnel ///