Skip to main content

taskcluster/generated/
purgecache.rs

1#![allow(unused_imports)]
2#![cfg_attr(rustfmt, rustfmt_skip)]
3/* THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT */
4use crate::{Client, ClientBuilder, Credentials, Retry};
5use anyhow::Error;
6use serde_json::Value;
7use std::time::Duration;
8use crate::util::urlencode;
9
10/// Purge Cache Service
11///
12/// The purge-cache service is responsible for tracking cache-purge requests.
13///
14/// User create purge requests for specific caches on specific workers, and
15/// these requests are timestamped.  Workers consult the service before
16/// starting a new task, and purge any caches older than the timestamp.
17pub struct PurgeCache {
18    /// The underlying client used to make API calls for this service.
19    pub client: Client
20}
21
22#[allow(non_snake_case)]
23impl PurgeCache {
24    /// Create a new PurgeCache instance, based on the given client builder
25    pub fn new<CB: Into<ClientBuilder>>(client_builder: CB) -> Result<Self, Error> {
26        Ok(Self{
27            client: client_builder
28                .into()
29                .path_prefix("api/purge-cache/v1/")
30                .build()?,
31        })
32    }
33
34    /// Ping Server
35    ///
36    /// Respond without doing anything.
37    /// This endpoint is used to check that the service is up.
38    pub async fn ping(&self) -> Result<(), Error> {
39        let method = "GET";
40        let (path, query) = Self::ping_details();
41        let body = None;
42        let resp = self.client.request(method, path, query, body).await?;
43        resp.bytes().await?;
44        Ok(())
45    }
46
47    /// Generate an unsigned URL for the ping endpoint
48    pub fn ping_url(&self) -> Result<String, Error> {
49        let (path, query) = Self::ping_details();
50        self.client.make_url(path, query)
51    }
52
53    /// Generate a signed URL for the ping endpoint
54    pub fn ping_signed_url(&self, ttl: Duration) -> Result<String, Error> {
55        let (path, query) = Self::ping_details();
56        self.client.make_signed_url(path, query, ttl)
57    }
58
59    /// Determine the HTTP request details for ping
60    fn ping_details<'a>() -> (&'static str, Option<Vec<(&'static str, &'a str)>>) {
61        let path = "ping";
62        let query = None;
63
64        (path, query)
65    }
66
67    /// Load Balancer Heartbeat
68    ///
69    /// Respond without doing anything.
70    /// This endpoint is used to check that the service is up.
71    pub async fn lbheartbeat(&self) -> Result<(), Error> {
72        let method = "GET";
73        let (path, query) = Self::lbheartbeat_details();
74        let body = None;
75        let resp = self.client.request(method, path, query, body).await?;
76        resp.bytes().await?;
77        Ok(())
78    }
79
80    /// Generate an unsigned URL for the lbheartbeat endpoint
81    pub fn lbheartbeat_url(&self) -> Result<String, Error> {
82        let (path, query) = Self::lbheartbeat_details();
83        self.client.make_url(path, query)
84    }
85
86    /// Generate a signed URL for the lbheartbeat endpoint
87    pub fn lbheartbeat_signed_url(&self, ttl: Duration) -> Result<String, Error> {
88        let (path, query) = Self::lbheartbeat_details();
89        self.client.make_signed_url(path, query, ttl)
90    }
91
92    /// Determine the HTTP request details for lbheartbeat
93    fn lbheartbeat_details<'a>() -> (&'static str, Option<Vec<(&'static str, &'a str)>>) {
94        let path = "__lbheartbeat__";
95        let query = None;
96
97        (path, query)
98    }
99
100    /// Taskcluster Version
101    ///
102    /// Respond with the JSON version object.
103    /// https://github.com/mozilla-services/Dockerflow/blob/main/docs/version_object.md
104    pub async fn version(&self) -> Result<(), Error> {
105        let method = "GET";
106        let (path, query) = Self::version_details();
107        let body = None;
108        let resp = self.client.request(method, path, query, body).await?;
109        resp.bytes().await?;
110        Ok(())
111    }
112
113    /// Generate an unsigned URL for the version endpoint
114    pub fn version_url(&self) -> Result<String, Error> {
115        let (path, query) = Self::version_details();
116        self.client.make_url(path, query)
117    }
118
119    /// Generate a signed URL for the version endpoint
120    pub fn version_signed_url(&self, ttl: Duration) -> Result<String, Error> {
121        let (path, query) = Self::version_details();
122        self.client.make_signed_url(path, query, ttl)
123    }
124
125    /// Determine the HTTP request details for version
126    fn version_details<'a>() -> (&'static str, Option<Vec<(&'static str, &'a str)>>) {
127        let path = "__version__";
128        let query = None;
129
130        (path, query)
131    }
132
133    /// Purge Worker Cache
134    ///
135    /// Publish a request to purge caches named `cacheName` with
136    /// on `workerPoolId` workers.
137    ///
138    /// If such a request already exists, its `before` timestamp is updated to
139    /// the current time.
140    pub async fn purgeCache(&self, workerPoolId: &str, payload: &Value) -> Result<(), Error> {
141        let method = "POST";
142        let (path, query) = Self::purgeCache_details(workerPoolId);
143        let body = Some(payload);
144        let resp = self.client.request(method, &path, query, body).await?;
145        resp.bytes().await?;
146        Ok(())
147    }
148
149    /// Determine the HTTP request details for purgeCache
150    fn purgeCache_details<'a>(workerPoolId: &'a str) -> (String, Option<Vec<(&'static str, &'a str)>>) {
151        let path = format!("purge-cache/{}", urlencode(workerPoolId));
152        let query = None;
153
154        (path, query)
155    }
156
157    /// All Open Purge Requests
158    ///
159    /// View all active purge requests.
160    ///
161    /// This is useful mostly for administors to view
162    /// the set of open purge requests. It should not
163    /// be used by workers. They should use the purgeRequests
164    /// endpoint that is specific to their workerType and
165    /// provisionerId.
166    pub async fn allPurgeRequests(&self, continuationToken: Option<&str>, limit: Option<&str>) -> Result<Value, Error> {
167        let method = "GET";
168        let (path, query) = Self::allPurgeRequests_details(continuationToken, limit);
169        let body = None;
170        let resp = self.client.request(method, path, query, body).await?;
171        Ok(resp.json().await?)
172    }
173
174    /// Generate an unsigned URL for the allPurgeRequests endpoint
175    pub fn allPurgeRequests_url(&self, continuationToken: Option<&str>, limit: Option<&str>) -> Result<String, Error> {
176        let (path, query) = Self::allPurgeRequests_details(continuationToken, limit);
177        self.client.make_url(path, query)
178    }
179
180    /// Generate a signed URL for the allPurgeRequests endpoint
181    pub fn allPurgeRequests_signed_url(&self, continuationToken: Option<&str>, limit: Option<&str>, ttl: Duration) -> Result<String, Error> {
182        let (path, query) = Self::allPurgeRequests_details(continuationToken, limit);
183        self.client.make_signed_url(path, query, ttl)
184    }
185
186    /// Determine the HTTP request details for allPurgeRequests
187    fn allPurgeRequests_details<'a>(continuationToken: Option<&'a str>, limit: Option<&'a str>) -> (&'static str, Option<Vec<(&'static str, &'a str)>>) {
188        let path = "purge-cache/list";
189        let mut query = None;
190        if let Some(q) = continuationToken {
191            query.get_or_insert_with(Vec::new).push(("continuationToken", q));
192        }
193        if let Some(q) = limit {
194            query.get_or_insert_with(Vec::new).push(("limit", q));
195        }
196
197        (path, query)
198    }
199
200    /// Open Purge Requests for a worker pool
201    ///
202    /// List the caches for this `workerPoolId` that should to be
203    /// purged if they are from before the time given in the response.
204    ///
205    /// This is intended to be used by workers to determine which caches to purge.
206    pub async fn purgeRequests(&self, workerPoolId: &str, since: Option<&str>) -> Result<Value, Error> {
207        let method = "GET";
208        let (path, query) = Self::purgeRequests_details(workerPoolId, since);
209        let body = None;
210        let resp = self.client.request(method, &path, query, body).await?;
211        Ok(resp.json().await?)
212    }
213
214    /// Generate an unsigned URL for the purgeRequests endpoint
215    pub fn purgeRequests_url(&self, workerPoolId: &str, since: Option<&str>) -> Result<String, Error> {
216        let (path, query) = Self::purgeRequests_details(workerPoolId, since);
217        self.client.make_url(&path, query)
218    }
219
220    /// Generate a signed URL for the purgeRequests endpoint
221    pub fn purgeRequests_signed_url(&self, workerPoolId: &str, since: Option<&str>, ttl: Duration) -> Result<String, Error> {
222        let (path, query) = Self::purgeRequests_details(workerPoolId, since);
223        self.client.make_signed_url(&path, query, ttl)
224    }
225
226    /// Determine the HTTP request details for purgeRequests
227    fn purgeRequests_details<'a>(workerPoolId: &'a str, since: Option<&'a str>) -> (String, Option<Vec<(&'static str, &'a str)>>) {
228        let path = format!("purge-cache/{}", urlencode(workerPoolId));
229        let mut query = None;
230        if let Some(q) = since {
231            query.get_or_insert_with(Vec::new).push(("since", q));
232        }
233
234        (path, query)
235    }
236
237    /// Heartbeat
238    ///
239    /// Respond with a service heartbeat.
240    ///
241    /// This endpoint is used to check on backing services this service
242    /// depends on.
243    pub async fn heartbeat(&self) -> Result<(), Error> {
244        let method = "GET";
245        let (path, query) = Self::heartbeat_details();
246        let body = None;
247        let resp = self.client.request(method, path, query, body).await?;
248        resp.bytes().await?;
249        Ok(())
250    }
251
252    /// Generate an unsigned URL for the heartbeat endpoint
253    pub fn heartbeat_url(&self) -> Result<String, Error> {
254        let (path, query) = Self::heartbeat_details();
255        self.client.make_url(path, query)
256    }
257
258    /// Generate a signed URL for the heartbeat endpoint
259    pub fn heartbeat_signed_url(&self, ttl: Duration) -> Result<String, Error> {
260        let (path, query) = Self::heartbeat_details();
261        self.client.make_signed_url(path, query, ttl)
262    }
263
264    /// Determine the HTTP request details for heartbeat
265    fn heartbeat_details<'a>() -> (&'static str, Option<Vec<(&'static str, &'a str)>>) {
266        let path = "__heartbeat__";
267        let query = None;
268
269        (path, query)
270    }
271}