Skip to content

Commit

Permalink
Apply suggestions, add delete
Browse files Browse the repository at this point in the history
  • Loading branch information
exvuma committed Jan 27, 2020
1 parent ca0c02c commit 6f7da91
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 15 deletions.
4 changes: 3 additions & 1 deletion cloudflare/src/endpoints/workers/create_secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@ pub struct CreateSecretParams {
/// the variable name of the secret that will be bound to the script
pub name: String,
/// the string value of the secret
pub value: String,
pub text: String,
// type of binding (e.g.secret_text)
pub r#type: String,
}
26 changes: 26 additions & 0 deletions cloudflare/src/endpoints/workers/delete_secret.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use super::WorkersSecret;

use crate::framework::endpoint::{Endpoint, Method};

/// Delete Secret
/// https://api.cloudflare.com/#worker-delete-secret
pub struct DeleteSecret<'a> {
/// account id of owner of the script
pub account_identifier: &'a str,
/// the name of the script to remove the secret from
pub script_name: &'a str,
/// the variable name of the secret
pub secret_name: &'a str,
}

impl<'a> Endpoint<WorkersSecret> for DeleteSecret<'a> {
fn method(&self) -> Method {
Method::Delete
}
fn path(&self) -> String {
format!(
"accounts/{}/workers/scripts/{}/secrets/{}",
self.account_identifier, self.script_name, self.secret_name
)
}
}
33 changes: 19 additions & 14 deletions cloudflare/src/endpoints/workers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
use crate::framework::response::ApiResult;

use chrono::offset::Utc;
use chrono::DateTime;
use serde::Deserialize;

mod create_route;
pub mod create_secret;
mod create_secret;
mod delete_route;
pub mod delete_secret;
mod delete_secret;
mod list_routes;

pub use create_route::{CreateRoute, CreateRouteParams};
pub use create_secret::{CreateSecret, CreateSecretParams};
pub use delete_route::DeleteRoute;
pub use delete_secret::DeleteSecret;
pub use list_routes::ListRoutes;

/// Workers KV Route
/// Routes are basic patterns used to enable or disable workers that match requests.
/// https://api.cloudflare.com/#worker-routes-properties
#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
pub struct WorkersRoute {
/// Namespace identifier tag.
pub id: String,
/// The basic pattern that should map to the script
pub pattern: String,
/// Name of the script to apply when the route is matched.
/// The route is skipped when this is blank/missing.
pub script: Option<String>,
/// Namespace identifier tag.
pub id: String,
/// The basic pattern that should map to the script
pub pattern: String,
/// Name of the script to apply when the route is matched.
/// The route is skipped when this is blank/missing.
pub script: Option<String>,
}

impl ApiResult for WorkersRoute {}
Expand All @@ -34,8 +38,8 @@ impl ApiResult for Vec<WorkersRoute> {}
/// but it feels wrong.
#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
pub struct WorkersRouteIdOnly {
/// Namespace identifier tag.
pub id: String,
/// Namespace identifier tag.
pub id: String,
}

impl ApiResult for WorkersRouteIdOnly {}
Expand All @@ -44,10 +48,11 @@ impl ApiResult for WorkersRouteIdOnly {}
/// https://api.cloudflare.com/#worker-secrets-properties
#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
pub struct WorkersSecret {
/// TODO these fields depend on the API and may be wrong
/// TODO: these fields depend on the API and may be wrong since unable to test
pub name: String,
pub modified_on: String,
pub script_id: String,
pub r#type: String,
pub modified_on: DateTime<Utc>,
pub created_on: DateTime<Utc>,
}

impl ApiResult for WorkersSecret {}
Expand Down

0 comments on commit 6f7da91

Please sign in to comment.