cloudflare_but_works/endpoints/workers/
create_secret.rs

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