cloudflare/endpoints/workers/
create_secret.rs

1use surf::http::Method;
2
3use super::WorkersSecret;
4use crate::framework::endpoint::Endpoint;
5
6/// Create Secret
7/// https://api.cloudflare.com/#worker-create-secret
8#[derive(Debug)]
9pub struct CreateSecret<'a> {
10    /// Account ID of script owner
11    pub account_identifier: &'a str,
12    /// The name of the script to attach the secret to
13    pub script_name: &'a str,
14    /// The contents of the secret
15    pub params: CreateSecretParams,
16}
17
18impl<'a> Endpoint<WorkersSecret, (), CreateSecretParams> for CreateSecret<'a> {
19    fn method(&self) -> Method {
20        Method::Put
21    }
22    fn path(&self) -> String {
23        format!(
24            "accounts/{}/workers/scripts/{}/secrets",
25            self.account_identifier, self.script_name
26        )
27    }
28    fn body(&self) -> Option<CreateSecretParams> {
29        Some(self.params.clone())
30    }
31}
32
33#[derive(Serialize, Clone, Debug)]
34pub struct CreateSecretParams {
35    /// the variable name of the secret that will be bound to the script
36    pub name: String,
37    /// the string value of the secret
38    pub text: String,
39    // type of binding (e.g.secret_text)
40    #[serde(rename = "type")]
41    pub secret_type: String,
42}