Skip to content
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

Added bulk routes endpoints #168

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions cloudflare/src/endpoints/workers/add_routes_script.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use super::{BulkRoute, CreatedBulkRoute};
use crate::framework::endpoint::{Endpoint, Method};

/// Adds provided routes on provided script
///
/// TODO link to api.cloudflare.com
#[derive(Debug)]
pub struct AddRoutesScript<'a> {
pub account_id: &'a str,
pub script_name: &'a str,
pub params: Vec<BulkRoute>,
}

impl<'a> Endpoint<Vec<CreatedBulkRoute>, (), Vec<BulkRoute>> for AddRoutesScript<'a> {
fn method(&self) -> Method {
Method::Patch
}
fn path(&self) -> String {
format!(
"accounts/{}/workers/scripts/{}/routes",
self.account_id, self.script_name
)
}
fn body(&self) -> Option<Vec<BulkRoute>> {
Some(self.params.clone())
}
}
27 changes: 27 additions & 0 deletions cloudflare/src/endpoints/workers/create_routes_script.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use super::{BulkRoute, CreatedBulkRoute};
use crate::framework::endpoint::{Endpoint, Method};

/// Deletes all current routes for given script and creates new provided routes
///
/// TODO link to api.cloudflare.com
#[derive(Debug)]
pub struct CreateRoutesScript<'a> {
pub account_id: &'a str,
pub script_name: &'a str,
pub params: Vec<BulkRoute>,
}

impl<'a> Endpoint<Vec<CreatedBulkRoute>, (), Vec<BulkRoute>> for CreateRoutesScript<'a> {
fn method(&self) -> Method {
Method::Put
}
fn path(&self) -> String {
format!(
"accounts/{}/workers/scripts/{}/routes",
self.account_id, self.script_name
)
}
fn body(&self) -> Option<Vec<BulkRoute>> {
Some(self.params.clone())
}
}
23 changes: 23 additions & 0 deletions cloudflare/src/endpoints/workers/delete_route_script.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use crate::framework::endpoint::{Endpoint, Method};

/// Deletes provided route on provided script
///
/// TODO link to api.cloudflare.com
#[derive(Debug)]
pub struct DeleteRouteScript<'a> {
pub account_id: &'a str,
pub script_name: &'a str,
pub route_id: &'a str,
}

impl<'a> Endpoint<(), (), ()> for DeleteRouteScript<'a> {
fn method(&self) -> Method {
Method::Delete
}
fn path(&self) -> String {
format!(
"accounts/{}/workers/scripts/{}/routes/{}",
self.account_id, self.script_name, self.route_id
)
}
}
23 changes: 23 additions & 0 deletions cloudflare/src/endpoints/workers/list_routes_script.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use super::CreatedBulkRoute;
use crate::framework::endpoint::{Endpoint, Method};

/// List all routes for provided script
///
/// TODO link to api.cloudflare.com
#[derive(Debug)]
pub struct ListRoutesScript<'a> {
pub account_id: &'a str,
pub script_name: &'a str,
}

impl<'a> Endpoint<Vec<CreatedBulkRoute>, (), ()> for ListRoutesScript<'a> {
fn method(&self) -> Method {
Method::Get
}
fn path(&self) -> String {
format!(
"accounts/{}/workers/scripts/{}/routes",
self.account_id, self.script_name
)
}
}
35 changes: 34 additions & 1 deletion cloudflare/src/endpoints/workers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,38 @@ use crate::framework::response::ApiResult;
use chrono::{DateTime, Utc};
use serde::Deserialize;

mod add_routes_script;
mod create_route;
mod create_routes_script;
mod create_secret;
mod create_tail;
mod delete_do;
mod delete_route;
mod delete_route_script;
mod delete_script;
mod delete_secret;
mod delete_tail;
mod list_bindings;
mod list_routes;
mod list_routes_script;
mod list_secrets;
mod list_tails;
mod send_tail_heartbeat;

pub use add_routes_script::AddRoutesScript;
pub use create_route::{CreateRoute, CreateRouteParams};
pub use create_routes_script::CreateRoutesScript;
pub use create_secret::{CreateSecret, CreateSecretParams};
pub use create_tail::{CreateTail, CreateTailParams};
pub use delete_do::DeleteDurableObject;
pub use delete_route::DeleteRoute;
pub use delete_route_script::DeleteRouteScript;
pub use delete_script::DeleteScript;
pub use delete_secret::DeleteSecret;
pub use delete_tail::DeleteTail;
pub use list_bindings::ListBindings;
pub use list_routes::ListRoutes;
pub use list_routes_script::ListRoutesScript;
pub use list_secrets::ListSecrets;
pub use list_tails::ListTails;
pub use send_tail_heartbeat::SendTailHeartbeat;
Expand Down Expand Up @@ -93,5 +101,30 @@ pub struct WorkersBinding {
}

impl ApiResult for WorkersBinding {}
impl ApiResult for Vec<WorkersBinding>{}
impl ApiResult for Vec<WorkersBinding> {}

/// Route to be created with `CreateRoutesScript` or `AddRoutesScript`
///
/// * `pattern`: the zone name along with glob-style wildcards e.g. "example.net/*"
///
/// * `fail_open`: if set to true a request will continue to the origin without
/// hitting the worker in case of worker request limits
///
/// * `disabled`: if set to true the worker will not be hit on this route
#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct BulkRoute {
pub pattern: String,
pub fail_open: Option<bool>,
pub disabled: Option<bool>,
}

/// Created route
#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct CreatedBulkRoute {
pub id: String,
pub pattern: String,
pub fail_open: Option<bool>,
pub disabled: Option<bool>,
}

impl ApiResult for Vec<CreatedBulkRoute> {}