diff --git a/cloudflare/src/endpoints/cfd_tunnel/create_tunnel.rs b/cloudflare/src/endpoints/cfd_tunnel/create_tunnel.rs index ffd74e5..8fd9c84 100644 --- a/cloudflare/src/endpoints/cfd_tunnel/create_tunnel.rs +++ b/cloudflare/src/endpoints/cfd_tunnel/create_tunnel.rs @@ -45,8 +45,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 bb84390..79592c4 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 a Cfd Tunnel that has been created. It can be used for routing and subsequent running. @@ -68,8 +82,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 {} +impl ApiResult for TunnelToken {} + +#[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)] @@ -100,4 +182,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 0000000..08111f6 --- /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/get_tunnel.rs b/cloudflare/src/endpoints/cfd_tunnel/get_tunnel.rs new file mode 100644 index 0000000..1519947 --- /dev/null +++ b/cloudflare/src/endpoints/cfd_tunnel/get_tunnel.rs @@ -0,0 +1,28 @@ +use crate::endpoints::cfd_tunnel::Tunnel; +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 0000000..b96686c --- /dev/null +++ b/cloudflare/src/endpoints/cfd_tunnel/get_tunnel_token.rs @@ -0,0 +1,26 @@ +use super::TunnelToken as TunnelTokenResult; +use crate::framework::endpoint::{EndpointSpec, Method}; + +/// 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 1841ae5..f5d569a 100644 --- a/cloudflare/src/endpoints/cfd_tunnel/mod.rs +++ b/cloudflare/src/endpoints/cfd_tunnel/mod.rs @@ -1,8 +1,12 @@ 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; 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 0000000..49501af --- /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, +}