-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add create/delete/list for Load Balancers (#139)
Co-authored-by: Nuno Diegues <[email protected]>
- Loading branch information
1 parent
e7a886e
commit dbd4f26
Showing
5 changed files
with
218 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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,63 @@ | ||
use crate::endpoints::load_balancing::{LbPoolId, SteeringPolicy, SessionAffinityAttributes, LbPoolMapping, SessionAffinity, LoadBalancer}; | ||
use crate::framework::endpoint::{Endpoint, Method}; | ||
|
||
/// Create Load Balancer | ||
/// https://api.cloudflare.com/#load-balancers-create-load-balancer | ||
#[derive(Debug)] | ||
pub struct CreateLoadBalancer<'a> { | ||
/// The Zone to which this Load Balancer shall belong. | ||
pub zone_identifier: &'a str, | ||
/// Optional parameters for the API call | ||
pub params: Params<'a>, | ||
} | ||
|
||
/// Mandatory parameters for creating a Load Balancer. | ||
#[serde_with::skip_serializing_none] | ||
#[derive(Serialize, Clone, Debug)] | ||
pub struct Params<'a> { | ||
/// A short name (tag) for the load balancer. | ||
/// Only alphanumeric characters, hyphens and underscores are allowed. | ||
/// E.g. "lb-user-facing" | ||
pub name: &'a str, | ||
/// The list of LB Pools (by their IDs) ordered by their failover priority. | ||
pub default_pools: &'a [LbPoolId], | ||
/// The LB Pool ID to use when all other pools are detected as unhealthy. | ||
pub fallback_pool: &'a LbPoolId, | ||
#[serde(flatten)] | ||
pub optional_params: Option<OptionalParams<'a>>, | ||
} | ||
|
||
/// Optional parameters for creating a Load Balancer. | ||
#[serde_with::skip_serializing_none] | ||
#[derive(Serialize, Clone, Debug, Default)] | ||
pub struct OptionalParams<'a> { | ||
pub description: Option<&'a str>, | ||
/// Time to live (TTL) of the DNS entry for the IP address returned by this load balancer. This | ||
/// only applies to gray-clouded (unproxied) load balancers. | ||
pub ttl: Option<u32>, | ||
/// A mapping of Cloudflare PoP identifiers to a list of pool IDs (ordered by their failover | ||
/// priority) for the PoP (datacenter). Any PoPs not explicitly defined will fall back to using | ||
/// default_pools. | ||
pub pop_pools: Option<LbPoolMapping>, | ||
/// A mapping of region/country codes to a list of pool IDs (ordered by their failover priority) | ||
/// for the given region. Any regions not explicitly defined will fall back to using | ||
/// default_pools. | ||
pub region_pools: Option<LbPoolMapping>, | ||
pub proxied: Option<bool>, | ||
pub steering_policy: Option<SteeringPolicy>, | ||
pub session_affinity: Option<SessionAffinity>, | ||
pub session_affinity_attributes: Option<SessionAffinityAttributes>, | ||
pub session_affinity_ttl: Option<u32>, | ||
} | ||
|
||
impl<'a> Endpoint<LoadBalancer, (), Params<'a>> for CreateLoadBalancer<'a> { | ||
fn method(&self) -> Method { | ||
Method::Post | ||
} | ||
fn path(&self) -> String { | ||
format!("zones/{}/load_balancers", self.zone_identifier) | ||
} | ||
fn body(&self) -> Option<Params<'a>> { | ||
Some(self.params.clone()) | ||
} | ||
} |
This file contains 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,30 @@ | ||
use crate::framework::endpoint::{Endpoint, Method}; | ||
use crate::framework::response::ApiResult; | ||
|
||
/// Delete Load Balancer | ||
/// https://api.cloudflare.com/#load-balancers-delete-load-balancer | ||
#[derive(Debug)] | ||
pub struct DeleteLoadBalancer<'a> { | ||
/// The Zone to which this Load Balancer belongs. | ||
pub zone_identifier: &'a str, | ||
/// Which load balancer to delete. | ||
pub identifier: &'a str, | ||
} | ||
|
||
impl<'a> Endpoint<Response, (), ()> for DeleteLoadBalancer<'a> { | ||
fn method(&self) -> Method { | ||
Method::Delete | ||
} | ||
fn path(&self) -> String { | ||
format!( | ||
"zones/{}/load_balancers/{}", | ||
self.zone_identifier, self.identifier | ||
) | ||
} | ||
} | ||
|
||
#[derive(Deserialize, Clone, Debug)] | ||
pub struct Response { | ||
id: String, | ||
} | ||
impl ApiResult for Response {} |
This file contains 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,22 @@ | ||
use crate::endpoints::load_balancing::LoadBalancer; | ||
use crate::framework::endpoint::{Endpoint, Method}; | ||
use crate::framework::response::ApiResult; | ||
|
||
/// List Load Balancers | ||
/// https://api.cloudflare.com/#load-balancers-list-load-balancers | ||
#[derive(Debug)] | ||
pub struct ListLoadBalancers<'a> { | ||
/// The Zone to list Load Balancers from. | ||
pub zone_identifier: &'a str, | ||
} | ||
|
||
impl<'a> Endpoint<Vec<LoadBalancer>, ()> for ListLoadBalancers<'a> { | ||
fn method(&self) -> Method { | ||
Method::Get | ||
} | ||
fn path(&self) -> String { | ||
format!("zones/{}/load_balancers", self.zone_identifier) | ||
} | ||
} | ||
|
||
impl ApiResult for Vec<LoadBalancer> {} |
This file contains 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