cloudflare/endpoints/workers/
mod.rs

1use crate::framework::ApiResultTraits;
2
3use chrono::{DateTime, Utc};
4use serde::Deserialize;
5
6mod create_route;
7mod create_secret;
8mod create_tail;
9mod delete_route;
10mod delete_secret;
11mod delete_tail;
12mod list_routes;
13mod list_secrets;
14mod list_tails;
15mod send_tail_heartbeat;
16
17pub use create_route::{CreateRoute, CreateRouteParams};
18pub use create_secret::{CreateSecret, CreateSecretParams};
19pub use create_tail::{CreateTail, CreateTailParams};
20pub use delete_route::DeleteRoute;
21pub use delete_secret::DeleteSecret;
22pub use delete_tail::DeleteTail;
23pub use list_routes::ListRoutes;
24pub use list_secrets::ListSecrets;
25pub use list_tails::ListTails;
26pub use send_tail_heartbeat::SendTailHeartbeat;
27
28/// Workers KV Route
29/// Routes are basic patterns used to enable or disable workers that match requests.
30/// https://api.cloudflare.com/#worker-routes-properties
31#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
32pub struct WorkersRoute {
33    /// Namespace identifier tag.
34    pub id: String,
35    /// The basic pattern that should map to the script
36    pub pattern: String,
37    /// Name of the script to apply when the route is matched.
38    /// The route is skipped when this is blank/missing.
39    pub script: Option<String>,
40}
41
42impl ApiResultTraits for WorkersRoute {}
43impl ApiResultTraits for Vec<WorkersRoute> {}
44
45/// A variant of WorkersRoute returned by the CreateRoute endpoint
46/// We could make `pattern` and `script` into `Option<String>` types
47/// but it feels wrong.
48#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
49pub struct WorkersRouteIdOnly {
50    /// Namespace identifier tag.
51    pub id: String,
52}
53
54impl ApiResultTraits for WorkersRouteIdOnly {}
55
56/// Secrets attach to a single script to be readable in only the script
57/// https://api.cloudflare.com/#worker-secrets-properties
58#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
59pub struct WorkersSecret {
60    pub name: String,
61    #[serde(rename = "type")]
62    pub secret_type: String,
63}
64
65impl ApiResultTraits for WorkersSecret {}
66impl ApiResultTraits for Vec<WorkersSecret> {} // to parse arrays too
67
68/// A Tail is attached to a single Worker and is impermanent
69/// https://api.cloudflare.com/#worker-tail-properties
70#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
71pub struct WorkersTail {
72    pub id: String,
73    pub url: Option<String>,
74    pub expires_at: DateTime<Utc>,
75}
76
77impl ApiResultTraits for WorkersTail {}
78impl ApiResultTraits for Vec<WorkersTail> {}