From 6f7da91c2b69519017fb8cd81880f44b7e6f3afe Mon Sep 17 00:00:00 2001 From: Victoria Date: Mon, 27 Jan 2020 10:50:58 -0600 Subject: [PATCH] Apply suggestions, add delete --- .../src/endpoints/workers/create_secret.rs | 4 ++- .../src/endpoints/workers/delete_secret.rs | 26 +++++++++++++++ cloudflare/src/endpoints/workers/mod.rs | 33 +++++++++++-------- 3 files changed, 48 insertions(+), 15 deletions(-) create mode 100644 cloudflare/src/endpoints/workers/delete_secret.rs diff --git a/cloudflare/src/endpoints/workers/create_secret.rs b/cloudflare/src/endpoints/workers/create_secret.rs index 13116292..1923c462 100644 --- a/cloudflare/src/endpoints/workers/create_secret.rs +++ b/cloudflare/src/endpoints/workers/create_secret.rs @@ -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, } diff --git a/cloudflare/src/endpoints/workers/delete_secret.rs b/cloudflare/src/endpoints/workers/delete_secret.rs new file mode 100644 index 00000000..4e353318 --- /dev/null +++ b/cloudflare/src/endpoints/workers/delete_secret.rs @@ -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 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 + ) + } +} diff --git a/cloudflare/src/endpoints/workers/mod.rs b/cloudflare/src/endpoints/workers/mod.rs index 47e66537..f618e5d7 100644 --- a/cloudflare/src/endpoints/workers/mod.rs +++ b/cloudflare/src/endpoints/workers/mod.rs @@ -1,15 +1,19 @@ 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 @@ -17,13 +21,13 @@ pub use list_routes::ListRoutes; /// 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, + /// 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, } impl ApiResult for WorkersRoute {} @@ -34,8 +38,8 @@ impl ApiResult for Vec {} /// 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 {} @@ -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, + pub created_on: DateTime, } impl ApiResult for WorkersSecret {}