Skip to content

Commit 3f96633

Browse files
committed
feat: Adds tunnel configuration endpoints
1 parent 4309cfe commit 3f96633

File tree

5 files changed

+84
-3
lines changed

5 files changed

+84
-3
lines changed

cloudflare/src/endpoints/cfd_tunnel/create_tunnel.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ pub struct Params<'a> {
4141
pub name: &'a str,
4242
/// The byte array (with 32 or more bytes) representing a secret for the tunnel. This is
4343
/// encoded into JSON as a base64 String. This secret is necessary to run the tunnel.
44-
#[serde_as(as = "Base64<Standard, Padded>")]
45-
pub tunnel_secret: &'a Vec<u8>,
44+
#[serde_as(as = "Option<Base64<Standard, Padded>>")]
45+
#[serde(default)]
46+
pub tunnel_secret: Option<&'a [u8]>,
4647

4748
pub config_src: &'a ConfigurationSrc,
4849

cloudflare/src/endpoints/cfd_tunnel/data_structures.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
1+
use crate::framework::response::ApiResult;
12
use chrono::{offset::Utc, DateTime};
23
use serde::{Deserialize, Serialize};
34
use std::net::IpAddr;
45
use uuid::Uuid;
56

6-
use crate::framework::response::ApiResult;
7+
#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
8+
pub struct TunnelToken(String);
9+
10+
impl From<String> for TunnelToken {
11+
fn from(s: String) -> TunnelToken {
12+
TunnelToken(s)
13+
}
14+
}
15+
16+
impl From<TunnelToken> for String {
17+
fn from(s: TunnelToken) -> String {
18+
s.0
19+
}
20+
}
721

822
/// A Cfd Tunnel
923
/// 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 {
127141
impl ApiResult for TunnelConfiguration {}
128142
impl ApiResult for Tunnel {}
129143
impl ApiResult for Vec<Tunnel> {}
144+
impl ApiResult for TunnelToken {}
130145

131146
#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
132147
pub struct TunnelConfigurationResult {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use crate::endpoints::cfd_tunnel::{ConfigurationSrc, Tunnel};
2+
use serde::Serialize;
3+
use serde_with::{
4+
base64::{Base64, Standard},
5+
formats::Padded,
6+
serde_as,
7+
};
8+
9+
use crate::framework::endpoint::{EndpointSpec, Method};
10+
11+
/// Create a Cfd Tunnel
12+
/// This creates the Tunnel, which can then be routed and ran. Creating the Tunnel per se is only
13+
/// a metadata operation (i.e. no Tunnel is running at this point).
14+
/// <https://developers.cloudflare.com/api/operations/cloudflare-tunnel-create-a-cloudflare-tunnel>
15+
#[derive(Debug)]
16+
pub struct GetTunnel<'a> {
17+
pub account_identifier: &'a str,
18+
pub tunnel_id: &'a str,
19+
}
20+
21+
impl<'a> EndpointSpec<Tunnel> for GetTunnel<'a> {
22+
fn method(&self) -> Method {
23+
Method::GET
24+
}
25+
fn path(&self) -> String {
26+
format!(
27+
"accounts/{}/cfd_tunnel/{}",
28+
self.account_identifier, self.tunnel_id
29+
)
30+
}
31+
#[inline]
32+
fn body(&self) -> Option<String> {
33+
None
34+
}
35+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use crate::framework::endpoint::{serialize_query, EndpointSpec, Method};
2+
use serde::Serialize;
3+
4+
use super::TunnelToken as TunnelTokenResult;
5+
6+
/// Delete a tunnel
7+
/// <https://developers.cloudflare.com/api/operations/cloudflare-tunnel-delete-a-cloudflare-tunnel>
8+
#[derive(Debug)]
9+
pub struct TunnelToken<'a> {
10+
pub account_identifier: &'a str,
11+
pub tunnel_id: &'a str,
12+
}
13+
14+
impl<'a> EndpointSpec<TunnelTokenResult> for TunnelToken<'a> {
15+
fn method(&self) -> Method {
16+
Method::GET
17+
}
18+
fn path(&self) -> String {
19+
format!(
20+
"accounts/{}/cfd_tunnel/{}/token",
21+
self.account_identifier, self.tunnel_id
22+
)
23+
}
24+
#[inline]
25+
fn body(&self) -> Option<String> {
26+
None
27+
}
28+
}

cloudflare/src/endpoints/cfd_tunnel/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ pub mod create_tunnel;
22
mod data_structures;
33
pub mod delete_tunnel;
44
pub mod get_configuration;
5+
pub mod get_tunnel;
6+
pub mod get_tunnel_token;
57
pub mod list_tunnels;
68
pub mod route_dns;
79
pub mod update_configuration;

0 commit comments

Comments
 (0)