-
Notifications
You must be signed in to change notification settings - Fork 110
Add WARP Connector specs #295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lmpn
wants to merge
12
commits into
cloudflare:master
Choose a base branch
from
lmpn:lneto/warp-connector-specs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e051797
Add warp connector create
lmpn 43fd3f1
Add warp connector delete
lmpn 27996dd
Add warp connector update
lmpn d219aaa
Add warp connector get
lmpn a2c8b14
Add warp connector list
lmpn dfdfe6c
Make warp connector update params optional
lmpn 602c8fb
Add warp connector get token endpoint
lmpn 6bd0b55
Add warp connector list connections endpoint
lmpn 8a24298
Add warp connector get connector endpoint
lmpn 0d874bb
Add warp connector trigger failover endpoint
lmpn f574908
Add warp connector get HA configuration endpoint
lmpn 9943770
Add warp connector update HA configuration endpoint
lmpn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
cloudflare/src/endpoints/warp_connector_tunnel/create_tunnel.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| use serde::Serialize; | ||
| use serde_with::serde_as; | ||
|
|
||
| use crate::framework::response::ApiSuccess; | ||
| use crate::{ | ||
| endpoints::warp_connector_tunnel::data_structures::WarpConnectorTunnel, | ||
| framework::endpoint::{EndpointSpec, Method, RequestBody}, | ||
| }; | ||
|
|
||
| /// Create a Warp Connector tunnel | ||
| /// <https://developers.cloudflare.com/api/resources/zero_trust/subresources/tunnels/subresources/warp_connector/methods/create> | ||
| #[derive(Debug)] | ||
| pub struct CreateTunnel<'a> { | ||
| pub account_identifier: &'a str, | ||
| pub params: Params<'a>, | ||
| } | ||
|
|
||
| impl EndpointSpec for CreateTunnel<'_> { | ||
| type JsonResponse = WarpConnectorTunnel; | ||
| type ResponseType = ApiSuccess<Self::JsonResponse>; | ||
|
|
||
| fn method(&self) -> Method { | ||
| Method::POST | ||
| } | ||
| fn path(&self) -> String { | ||
| format!("accounts/{}/warp_connector", self.account_identifier) | ||
| } | ||
| #[inline] | ||
| fn body(&'_ self) -> Option<RequestBody<'_>> { | ||
| let body = serde_json::to_string(&self.params).unwrap(); | ||
| Some(RequestBody::Json(body)) | ||
| } | ||
| } | ||
|
|
||
| /// Params for creating a Warp Connector Tunnel | ||
| #[serde_as] | ||
| #[serde_with::skip_serializing_none] | ||
| #[derive(Serialize, Clone, Debug)] | ||
| pub struct Params<'a> { | ||
| /// The name for the Tunnel to be created. It must be unique within the account. | ||
| pub name: &'a str, | ||
| pub ha: bool, | ||
| } |
153 changes: 153 additions & 0 deletions
153
cloudflare/src/endpoints/warp_connector_tunnel/data_structures.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| use chrono::{offset::Utc, DateTime}; | ||
| use serde::{Deserialize, Serialize}; | ||
| use uuid::Uuid; | ||
|
|
||
| use crate::endpoints::cfd_tunnel::{ActiveConnection, TunnelStatusType}; | ||
| use crate::framework::response::ApiResult; | ||
|
|
||
| /// A Warp Connector Tunnel. | ||
| /// | ||
| /// Mirrors the JSON returned by the Cloudflare API when creating or fetching a | ||
| /// warp_connector tunnel, including its credentials file and connection token. | ||
| #[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)] | ||
| pub struct WarpConnectorTunnel { | ||
| pub id: Uuid, | ||
| pub account_tag: String, | ||
| pub created_at: DateTime<Utc>, | ||
| pub deleted_at: Option<DateTime<Utc>>, | ||
| pub name: String, | ||
| pub connections: Vec<ActiveConnection>, | ||
| pub conns_active_at: Option<DateTime<Utc>>, | ||
| pub conns_inactive_at: Option<DateTime<Utc>>, | ||
| pub tun_type: String, | ||
| pub metadata: serde_json::Value, | ||
| pub status: TunnelStatusType, | ||
| /// Present on create responses; absent on delete responses. | ||
| #[serde(flatten)] | ||
| pub credentials: Option<WarpConnectorCredentials>, | ||
| } | ||
|
|
||
| /// Credentials bundle returned only when a Warp Connector Tunnel is created. | ||
| /// | ||
| /// Flattened into [`WarpConnectorTunnel`] so it inlines `credentials_file` and | ||
| /// `token` at the top level of the JSON. | ||
| #[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)] | ||
| pub struct WarpConnectorCredentials { | ||
| pub credentials_file: WarpConnectorCredentialsFile, | ||
| pub token: String, | ||
| } | ||
|
|
||
| /// Credentials file contents for a Warp Connector Tunnel. | ||
| /// | ||
| /// Field names follow the API's PascalCase convention. | ||
| #[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)] | ||
| pub struct WarpConnectorCredentialsFile { | ||
| #[serde(rename = "AccountTag")] | ||
| pub account_tag: String, | ||
| #[serde(rename = "TunnelID")] | ||
| pub tunnel_id: Uuid, | ||
| #[serde(rename = "TunnelName")] | ||
| pub tunnel_name: String, | ||
| #[serde(rename = "TunnelSecret")] | ||
| pub tunnel_secret: String, | ||
| } | ||
|
|
||
| impl ApiResult for WarpConnectorTunnel {} | ||
| impl ApiResult for Vec<WarpConnectorTunnel> {} | ||
|
|
||
| /// A Warp Connector client maintaining a connection to a Cloudflare data center. | ||
| /// | ||
| /// Returned by both the connections list and the single-connector get endpoints. | ||
| #[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)] | ||
| pub struct WarpConnector { | ||
| pub id: Option<Uuid>, | ||
| pub arch: Option<String>, | ||
| pub conns: Option<Vec<WarpConnectorConn>>, | ||
| pub features: Option<Vec<String>>, | ||
| pub ha_status: Option<WarpConnectorHaStatus>, | ||
| pub run_at: Option<DateTime<Utc>>, | ||
| pub version: Option<String>, | ||
| } | ||
|
|
||
| /// A single Warp Connector connection between a client and Cloudflare's edge. | ||
| #[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)] | ||
| pub struct WarpConnectorConn { | ||
| pub id: Option<Uuid>, | ||
| pub client_id: Option<Uuid>, | ||
| pub client_version: Option<String>, | ||
| pub colo_name: Option<String>, | ||
| pub opened_at: Option<DateTime<Utc>>, | ||
| pub origin_ip: Option<String>, | ||
| } | ||
|
|
||
| /// HA status reported by a Warp Connector client. | ||
| #[derive(Deserialize, Serialize, Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
| #[serde(rename_all = "lowercase")] | ||
| pub enum WarpConnectorHaStatus { | ||
| Offline, | ||
| Passive, | ||
| Active, | ||
| } | ||
|
|
||
| impl ApiResult for WarpConnector {} | ||
| impl ApiResult for Vec<WarpConnector> {} | ||
|
|
||
| /// HA configuration for a Warp Connector Tunnel. | ||
| #[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)] | ||
| pub struct WarpConnectorHaConfiguration { | ||
| /// Monotonically increasing configuration version, incremented on each PUT. | ||
| pub configuration_version: u64, | ||
| pub created_at: DateTime<Utc>, | ||
| pub ha_mode: WarpConnectorHaMode, | ||
| pub tunnel_id: Uuid, | ||
| /// Provider-specific configuration; present for `aws` and `local` modes. | ||
| #[serde(default)] | ||
| pub config: Option<WarpConnectorProviderConfiguration>, | ||
| pub updated_at: Option<DateTime<Utc>>, | ||
| } | ||
|
|
||
| /// HA mode for a Warp Connector tunnel. | ||
| #[derive(Deserialize, Serialize, Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
| #[serde(rename_all = "lowercase")] | ||
| pub enum WarpConnectorHaMode { | ||
| /// HA enabled but no provider configured yet. | ||
| None, | ||
| /// HA explicitly turned off. | ||
| Disabled, | ||
| /// AWS ENI move-based failover. | ||
| Aws, | ||
| /// Local VIP-based failover. | ||
| Local, | ||
| } | ||
|
|
||
| /// Provider-specific HA configuration payload, discriminated by shape. | ||
| #[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)] | ||
| #[serde(untagged)] | ||
| pub enum WarpConnectorProviderConfiguration { | ||
| Aws(WarpConnectorAwsProviderConfiguration), | ||
| Local(WarpConnectorHaLocalProviderConfiguration), | ||
| } | ||
|
|
||
| #[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)] | ||
| pub struct WarpConnectorAwsProviderConfiguration { | ||
| /// Floating Network Resource ID — the secondary ENI moved between nodes | ||
| /// on failover. | ||
| pub fnr_id: String, | ||
| } | ||
|
|
||
| #[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)] | ||
| pub struct WarpConnectorHaLocalProviderConfiguration { | ||
| /// VIPs to assign on the CloudflareWARP interface. | ||
| pub vips: Vec<WarpConnectorVip>, | ||
| /// VIPs to clean up on demotion or version drift. | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| pub vips_previous: Option<Vec<WarpConnectorVip>>, | ||
| } | ||
|
|
||
| #[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)] | ||
| pub struct WarpConnectorVip { | ||
| /// Virtual IP address (IPv4 or IPv6). | ||
| pub address: String, | ||
| } | ||
|
|
||
| impl ApiResult for WarpConnectorHaConfiguration {} | ||
39 changes: 39 additions & 0 deletions
39
cloudflare/src/endpoints/warp_connector_tunnel/delete_tunnel.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| use crate::endpoints::warp_connector_tunnel::data_structures::WarpConnectorTunnel; | ||
| use crate::framework::endpoint::{serialize_query, EndpointSpec, Method}; | ||
| use crate::framework::response::ApiSuccess; | ||
| use serde::Serialize; | ||
|
|
||
| /// Delete a WARP Connector tunnel | ||
| /// <https://developers.cloudflare.com/api/resources/zero_trust/subresources/tunnels/subresources/warp_connector/methods/delete> | ||
| #[derive(Debug)] | ||
| pub struct DeleteTunnel<'a> { | ||
| pub account_identifier: &'a str, | ||
| pub tunnel_id: &'a str, | ||
| pub params: Params, | ||
| } | ||
|
|
||
| impl EndpointSpec for DeleteTunnel<'_> { | ||
| type JsonResponse = WarpConnectorTunnel; | ||
| type ResponseType = ApiSuccess<Self::JsonResponse>; | ||
|
|
||
| fn method(&self) -> Method { | ||
| Method::DELETE | ||
| } | ||
| fn path(&self) -> String { | ||
| format!( | ||
| "accounts/{}/warp_connector/{}", | ||
| self.account_identifier, self.tunnel_id | ||
| ) | ||
| } | ||
| #[inline] | ||
| fn query(&self) -> Option<String> { | ||
| serialize_query(&self.params) | ||
| } | ||
| } | ||
|
|
||
| #[serde_with::skip_serializing_none] | ||
| #[derive(Serialize, Clone, Debug, Default)] | ||
| pub struct Params { | ||
| // should delete tunnel connections if any exists | ||
| pub cascade: bool, | ||
| } |
28 changes: 28 additions & 0 deletions
28
cloudflare/src/endpoints/warp_connector_tunnel/get_connector.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| use crate::endpoints::warp_connector_tunnel::data_structures::WarpConnector; | ||
| use crate::framework::endpoint::{EndpointSpec, Method}; | ||
| use crate::framework::response::ApiSuccess; | ||
|
|
||
| /// Fetch connector + connection details for a single Warp Connector client. | ||
| /// <https://developers.cloudflare.com/api/resources/zero_trust/subresources/tunnels/subresources/warp_connector/subresources/connectors/methods/get> | ||
| #[derive(Debug)] | ||
| pub struct GetConnector<'a> { | ||
| pub account_identifier: &'a str, | ||
| pub tunnel_id: &'a str, | ||
| pub connector_id: &'a str, | ||
| } | ||
|
|
||
| impl EndpointSpec for GetConnector<'_> { | ||
| type JsonResponse = WarpConnector; | ||
| type ResponseType = ApiSuccess<Self::JsonResponse>; | ||
|
|
||
| fn method(&self) -> Method { | ||
| Method::GET | ||
| } | ||
|
|
||
| fn path(&self) -> String { | ||
| format!( | ||
| "accounts/{}/warp_connector/{}/connectors/{}", | ||
| self.account_identifier, self.tunnel_id, self.connector_id | ||
| ) | ||
| } | ||
| } |
27 changes: 27 additions & 0 deletions
27
cloudflare/src/endpoints/warp_connector_tunnel/get_ha_configuration.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| use crate::endpoints::warp_connector_tunnel::data_structures::WarpConnectorHaConfiguration; | ||
| use crate::framework::endpoint::{EndpointSpec, Method}; | ||
| use crate::framework::response::ApiSuccess; | ||
|
|
||
| /// Get the HA configuration for a Warp Connector Tunnel. | ||
| /// <https://developers.cloudflare.com/api/resources/zero_trust/subresources/tunnels/subresources/warp_connector/subresources/configurations/methods/get> | ||
| #[derive(Debug)] | ||
| pub struct GetHaConfiguration<'a> { | ||
| pub account_identifier: &'a str, | ||
| pub tunnel_id: &'a str, | ||
| } | ||
|
|
||
| impl EndpointSpec for GetHaConfiguration<'_> { | ||
| type JsonResponse = WarpConnectorHaConfiguration; | ||
| type ResponseType = ApiSuccess<Self::JsonResponse>; | ||
|
|
||
| fn method(&self) -> Method { | ||
| Method::GET | ||
| } | ||
|
|
||
| fn path(&self) -> String { | ||
| format!( | ||
| "accounts/{}/warp_connector/{}/configurations", | ||
| self.account_identifier, self.tunnel_id | ||
| ) | ||
| } | ||
| } |
37 changes: 37 additions & 0 deletions
37
cloudflare/src/endpoints/warp_connector_tunnel/get_token.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| use crate::framework::endpoint::{EndpointSpec, Method}; | ||
| use crate::framework::response::{ApiResult, ApiSuccess}; | ||
|
|
||
| /// Fetch the token used to authenticate a Warp Connector Tunnel. | ||
| /// <https://developers.cloudflare.com/api/resources/zero_trust/subresources/tunnels/subresources/warp_connector/methods/token_get> | ||
| #[derive(Debug)] | ||
| pub struct GetToken<'a> { | ||
| pub account_identifier: &'a str, | ||
| pub tunnel_id: &'a str, | ||
| } | ||
|
|
||
| impl EndpointSpec for GetToken<'_> { | ||
| type JsonResponse = WarpConnectorToken; | ||
| type ResponseType = ApiSuccess<Self::JsonResponse>; | ||
|
|
||
| fn method(&self) -> Method { | ||
| Method::GET | ||
| } | ||
|
|
||
| fn path(&self) -> String { | ||
| format!( | ||
| "accounts/{}/warp_connector/{}/token", | ||
| self.account_identifier, self.tunnel_id | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| /// Tunnel token returned by the API. The raw JSON value is a plain string | ||
| /// (e.g. `"eyJhIjoi…"`) but it is wrapped here so the crate's `ApiResult` | ||
| /// trait can be implemented without violating Rust's orphan rules. | ||
| #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] | ||
| #[serde(transparent)] | ||
| pub struct WarpConnectorToken(pub String); | ||
|
|
||
| impl ApiResult for WarpConnectorToken {} |
27 changes: 27 additions & 0 deletions
27
cloudflare/src/endpoints/warp_connector_tunnel/get_tunnel.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| use crate::endpoints::warp_connector_tunnel::data_structures::WarpConnectorTunnel; | ||
| use crate::framework::endpoint::{EndpointSpec, Method}; | ||
| use crate::framework::response::ApiSuccess; | ||
|
|
||
| /// Fetch a single Warp Connector Tunnel. | ||
| /// <https://developers.cloudflare.com/api/resources/zero_trust/subresources/tunnels/subresources/warp_connector/methods/get> | ||
| #[derive(Debug)] | ||
| pub struct GetTunnel<'a> { | ||
| pub account_identifier: &'a str, | ||
| pub tunnel_id: &'a str, | ||
| } | ||
|
|
||
| impl EndpointSpec for GetTunnel<'_> { | ||
| type JsonResponse = WarpConnectorTunnel; | ||
| type ResponseType = ApiSuccess<Self::JsonResponse>; | ||
|
|
||
| fn method(&self) -> Method { | ||
| Method::GET | ||
| } | ||
|
|
||
| fn path(&self) -> String { | ||
| format!( | ||
| "accounts/{}/warp_connector/{}", | ||
| self.account_identifier, self.tunnel_id | ||
| ) | ||
| } | ||
| } |
27 changes: 27 additions & 0 deletions
27
cloudflare/src/endpoints/warp_connector_tunnel/list_connections.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| use crate::endpoints::warp_connector_tunnel::data_structures::WarpConnector; | ||
| use crate::framework::endpoint::{EndpointSpec, Method}; | ||
| use crate::framework::response::ApiSuccess; | ||
|
|
||
| /// List active connections for a Warp Connector Tunnel. | ||
| /// <https://developers.cloudflare.com/api/resources/zero_trust/subresources/tunnels/subresources/warp_connector/subresources/connections/methods/list> | ||
| #[derive(Debug)] | ||
| pub struct ListConnections<'a> { | ||
| pub account_identifier: &'a str, | ||
| pub tunnel_id: &'a str, | ||
| } | ||
|
|
||
| impl EndpointSpec for ListConnections<'_> { | ||
| type JsonResponse = Vec<WarpConnector>; | ||
| type ResponseType = ApiSuccess<Self::JsonResponse>; | ||
|
|
||
| fn method(&self) -> Method { | ||
| Method::GET | ||
| } | ||
|
|
||
| fn path(&self) -> String { | ||
| format!( | ||
| "accounts/{}/warp_connector/{}/connections", | ||
| self.account_identifier, self.tunnel_id | ||
| ) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this really comes in the reply 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes it comes