Skip to main content

hanzo_client/apis/
registry_api.rs

1/*
2 * Hanzo Cloud API
3 *
4 * The Hanzo Cloud API as a customer calls it: every operation under /v1/ except the operator's admin product, relay routes, legacy spellings and capabilities still reached by flag. Tagged by product: the first path segment after /v1/.
5 *
6 * The version of the OpenAPI document: v1
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`get_registry_images`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetRegistryImagesError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`get_registry_packages`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetRegistryPackagesError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`get_registry_projects`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetRegistryProjectsError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`get_registry_status`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum GetRegistryStatusError {
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`get_registry_tags`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum GetRegistryTagsError {
50    UnknownValue(serde_json::Value),
51}
52
53/// struct for typed errors of method [`post_registry_token`]
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum PostRegistryTokenError {
57    UnknownValue(serde_json::Value),
58}
59
60
61/// Images lists the org's container repositories, read live from the OCI catalog and filtered server-side to the org's namespace — the page can only ever hold the caller's own images.
62pub async fn get_registry_images(configuration: &configuration::Configuration, ) -> Result<models::RegistryImageList, Error<GetRegistryImagesError>> {
63
64    let uri_str = format!("{}/v1/registry/images", configuration.base_path);
65    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
66
67    if let Some(ref user_agent) = configuration.user_agent {
68        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
69    }
70    if let Some(ref token) = configuration.bearer_access_token {
71        req_builder = req_builder.bearer_auth(token.to_owned());
72    };
73
74    let req = req_builder.build()?;
75    let resp = configuration.client.execute(req).await?;
76
77    let status = resp.status();
78    let content_type = resp
79        .headers()
80        .get("content-type")
81        .and_then(|v| v.to_str().ok())
82        .unwrap_or("application/octet-stream");
83    let content_type = super::ContentType::from(content_type);
84
85    if !status.is_client_error() && !status.is_server_error() {
86        let content = resp.text().await?;
87        match content_type {
88            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
89            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RegistryImageList`"))),
90            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RegistryImageList`")))),
91        }
92    } else {
93        let content = resp.text().await?;
94        let entity: Option<GetRegistryImagesError> = serde_json::from_str(&content).ok();
95        Err(Error::ResponseError(ResponseContent { status, content, entity }))
96    }
97}
98
99/// Packages lists the org's npm packages — `<org>` and `@<org>/…` — from the npm registry's search index, optionally narrowed by a query within that scope. The org boundary is applied server-side after the search, so a query can never widen it.
100pub async fn get_registry_packages(configuration: &configuration::Configuration, query: Option<&str>) -> Result<models::RegistryPackageList, Error<GetRegistryPackagesError>> {
101    // add a prefix to parameters to efficiently prevent name collisions
102    let p_query = query;
103
104    let uri_str = format!("{}/v1/registry/packages", configuration.base_path);
105    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
106
107    if let Some(ref param_value) = p_query {
108        req_builder = req_builder.query(&[("query", &param_value.to_string())]);
109    }
110    if let Some(ref user_agent) = configuration.user_agent {
111        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
112    }
113    if let Some(ref token) = configuration.bearer_access_token {
114        req_builder = req_builder.bearer_auth(token.to_owned());
115    };
116
117    let req = req_builder.build()?;
118    let resp = configuration.client.execute(req).await?;
119
120    let status = resp.status();
121    let content_type = resp
122        .headers()
123        .get("content-type")
124        .and_then(|v| v.to_str().ok())
125        .unwrap_or("application/octet-stream");
126    let content_type = super::ContentType::from(content_type);
127
128    if !status.is_client_error() && !status.is_server_error() {
129        let content = resp.text().await?;
130        match content_type {
131            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
132            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RegistryPackageList`"))),
133            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RegistryPackageList`")))),
134        }
135    } else {
136        let content = resp.text().await?;
137        let entity: Option<GetRegistryPackagesError> = serde_json::from_str(&content).ok();
138        Err(Error::ResponseError(ResponseContent { status, content, entity }))
139    }
140}
141
142/// Projects lists the namespaces the caller can see with what each holds: the org's slug, its repository count on the OCI catalog, and its package count on the npm registry. Today that is exactly one row — the caller's org.
143pub async fn get_registry_projects(configuration: &configuration::Configuration, ) -> Result<models::RegistryProjectList, Error<GetRegistryProjectsError>> {
144
145    let uri_str = format!("{}/v1/registry/projects", configuration.base_path);
146    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
147
148    if let Some(ref user_agent) = configuration.user_agent {
149        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
150    }
151    if let Some(ref token) = configuration.bearer_access_token {
152        req_builder = req_builder.bearer_auth(token.to_owned());
153    };
154
155    let req = req_builder.build()?;
156    let resp = configuration.client.execute(req).await?;
157
158    let status = resp.status();
159    let content_type = resp
160        .headers()
161        .get("content-type")
162        .and_then(|v| v.to_str().ok())
163        .unwrap_or("application/octet-stream");
164    let content_type = super::ContentType::from(content_type);
165
166    if !status.is_client_error() && !status.is_server_error() {
167        let content = resp.text().await?;
168        match content_type {
169            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
170            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RegistryProjectList`"))),
171            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RegistryProjectList`")))),
172        }
173    } else {
174        let content = resp.text().await?;
175        let entity: Option<GetRegistryProjectsError> = serde_json::from_str(&content).ok();
176        Err(Error::ResponseError(ResponseContent { status, content, entity }))
177    }
178}
179
180/// Status reports whether the OCI and npm registries are reachable and, when the OCI half is auth-gated, which token realm its challenge advertises — an honest lens for \"is the registry plane up\", never a fabricated ok.
181pub async fn get_registry_status(configuration: &configuration::Configuration, ) -> Result<models::RegistryStatus, Error<GetRegistryStatusError>> {
182
183    let uri_str = format!("{}/v1/registry/status", configuration.base_path);
184    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
185
186    if let Some(ref user_agent) = configuration.user_agent {
187        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
188    }
189    if let Some(ref token) = configuration.bearer_access_token {
190        req_builder = req_builder.bearer_auth(token.to_owned());
191    };
192
193    let req = req_builder.build()?;
194    let resp = configuration.client.execute(req).await?;
195
196    let status = resp.status();
197    let content_type = resp
198        .headers()
199        .get("content-type")
200        .and_then(|v| v.to_str().ok())
201        .unwrap_or("application/octet-stream");
202    let content_type = super::ContentType::from(content_type);
203
204    if !status.is_client_error() && !status.is_server_error() {
205        let content = resp.text().await?;
206        match content_type {
207            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
208            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RegistryStatus`"))),
209            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RegistryStatus`")))),
210        }
211    } else {
212        let content = resp.text().await?;
213        let entity: Option<GetRegistryStatusError> = serde_json::from_str(&content).ok();
214        Err(Error::ResponseError(ResponseContent { status, content, entity }))
215    }
216}
217
218/// Tags lists one org-owned repository's tags, read live from the OCI registry. The repository is addressed inside the org's namespace — a name outside it cannot be expressed, and an unknown one answers 404.
219pub async fn get_registry_tags(configuration: &configuration::Configuration, image: Option<&str>) -> Result<models::RegistryTagList, Error<GetRegistryTagsError>> {
220    // add a prefix to parameters to efficiently prevent name collisions
221    let p_image = image;
222
223    let uri_str = format!("{}/v1/registry/tags", configuration.base_path);
224    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
225
226    if let Some(ref param_value) = p_image {
227        req_builder = req_builder.query(&[("image", &param_value.to_string())]);
228    }
229    if let Some(ref user_agent) = configuration.user_agent {
230        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
231    }
232    if let Some(ref token) = configuration.bearer_access_token {
233        req_builder = req_builder.bearer_auth(token.to_owned());
234    };
235
236    let req = req_builder.build()?;
237    let resp = configuration.client.execute(req).await?;
238
239    let status = resp.status();
240    let content_type = resp
241        .headers()
242        .get("content-type")
243        .and_then(|v| v.to_str().ok())
244        .unwrap_or("application/octet-stream");
245    let content_type = super::ContentType::from(content_type);
246
247    if !status.is_client_error() && !status.is_server_error() {
248        let content = resp.text().await?;
249        match content_type {
250            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
251            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RegistryTagList`"))),
252            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RegistryTagList`")))),
253        }
254    } else {
255        let content = resp.text().await?;
256        let entity: Option<GetRegistryTagsError> = serde_json::from_str(&content).ok();
257        Err(Error::ResponseError(ResponseContent { status, content, entity }))
258    }
259}
260
261/// Token mints a short-lived, pull-only registry token for exactly one of the org's images, through the same IAM realm the docker CLI authenticates against. The scope is pinned server-side to `<org>/<image>` with the `pull` action — no field exists to name another org's image or ask for push. Use it as `Authorization: Bearer …` on the OCI wire; it expires in minutes.
262pub async fn post_registry_token(configuration: &configuration::Configuration, registry_mint: models::RegistryMint) -> Result<models::RegistryToken, Error<PostRegistryTokenError>> {
263    // add a prefix to parameters to efficiently prevent name collisions
264    let p_registry_mint = registry_mint;
265
266    let uri_str = format!("{}/v1/registry/token", configuration.base_path);
267    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
268
269    if let Some(ref user_agent) = configuration.user_agent {
270        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
271    }
272    if let Some(ref token) = configuration.bearer_access_token {
273        req_builder = req_builder.bearer_auth(token.to_owned());
274    };
275    req_builder = req_builder.json(&p_registry_mint);
276
277    let req = req_builder.build()?;
278    let resp = configuration.client.execute(req).await?;
279
280    let status = resp.status();
281    let content_type = resp
282        .headers()
283        .get("content-type")
284        .and_then(|v| v.to_str().ok())
285        .unwrap_or("application/octet-stream");
286    let content_type = super::ContentType::from(content_type);
287
288    if !status.is_client_error() && !status.is_server_error() {
289        let content = resp.text().await?;
290        match content_type {
291            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
292            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RegistryToken`"))),
293            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RegistryToken`")))),
294        }
295    } else {
296        let content = resp.text().await?;
297        let entity: Option<PostRegistryTokenError> = serde_json::from_str(&content).ok();
298        Err(Error::ResponseError(ResponseContent { status, content, entity }))
299    }
300}
301