Skip to main content

hanzo_client/apis/
sync_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 [`delete_sync_by_id`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum DeleteSyncByIdError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`get_sync`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetSyncError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`get_sync_by_id`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetSyncByIdError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`patch_sync_by_id`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum PatchSyncByIdError {
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`post_sync`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum PostSyncError {
50    UnknownValue(serde_json::Value),
51}
52
53/// struct for typed errors of method [`post_sync_by_id_run`]
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum PostSyncByIdRunError {
57    UnknownValue(serde_json::Value),
58}
59
60
61/// Delete removes one sync and tears down the outbound mirror it derived, answering 204. The teardown is the point: without it an unsynced repository would keep force-pushing to the upstream it is no longer linked to. Org-scoped, so another tenant's id is the same 404 an unknown id gives.
62pub async fn delete_sync_by_id(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<DeleteSyncByIdError>> {
63    // add a prefix to parameters to efficiently prevent name collisions
64    let p_id = id;
65
66    let uri_str = format!("{}/v1/sync/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
67    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
68
69    if let Some(ref user_agent) = configuration.user_agent {
70        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
71    }
72    if let Some(ref token) = configuration.bearer_access_token {
73        req_builder = req_builder.bearer_auth(token.to_owned());
74    };
75
76    let req = req_builder.build()?;
77    let resp = configuration.client.execute(req).await?;
78
79    let status = resp.status();
80
81    if !status.is_client_error() && !status.is_server_error() {
82        Ok(())
83    } else {
84        let content = resp.text().await?;
85        let entity: Option<DeleteSyncByIdError> = serde_json::from_str(&content).ok();
86        Err(Error::ResponseError(ResponseContent { status, content, entity }))
87    }
88}
89
90/// List returns every sync link the caller's org has, each with its two endpoints, its direction and trigger policy, and the time it last reconciled. Scoped to the caller's own org — another tenant's links are structurally unreachable.
91pub async fn get_sync(configuration: &configuration::Configuration, ) -> Result<models::SyncList, Error<GetSyncError>> {
92
93    let uri_str = format!("{}/v1/sync", configuration.base_path);
94    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
95
96    if let Some(ref user_agent) = configuration.user_agent {
97        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
98    }
99    if let Some(ref token) = configuration.bearer_access_token {
100        req_builder = req_builder.bearer_auth(token.to_owned());
101    };
102
103    let req = req_builder.build()?;
104    let resp = configuration.client.execute(req).await?;
105
106    let status = resp.status();
107    let content_type = resp
108        .headers()
109        .get("content-type")
110        .and_then(|v| v.to_str().ok())
111        .unwrap_or("application/octet-stream");
112    let content_type = super::ContentType::from(content_type);
113
114    if !status.is_client_error() && !status.is_server_error() {
115        let content = resp.text().await?;
116        match content_type {
117            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
118            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SyncList`"))),
119            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::SyncList`")))),
120        }
121    } else {
122        let content = resp.text().await?;
123        let entity: Option<GetSyncError> = serde_json::from_str(&content).ok();
124        Err(Error::ResponseError(ResponseContent { status, content, entity }))
125    }
126}
127
128/// Get returns one sync by id. It is org-scoped: an id belonging to another tenant is the same 404 an unknown id gives, so a probe learns nothing about what exists.
129pub async fn get_sync_by_id(configuration: &configuration::Configuration, id: &str) -> Result<models::SyncView, Error<GetSyncByIdError>> {
130    // add a prefix to parameters to efficiently prevent name collisions
131    let p_id = id;
132
133    let uri_str = format!("{}/v1/sync/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
134    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
135
136    if let Some(ref user_agent) = configuration.user_agent {
137        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
138    }
139    if let Some(ref token) = configuration.bearer_access_token {
140        req_builder = req_builder.bearer_auth(token.to_owned());
141    };
142
143    let req = req_builder.build()?;
144    let resp = configuration.client.execute(req).await?;
145
146    let status = resp.status();
147    let content_type = resp
148        .headers()
149        .get("content-type")
150        .and_then(|v| v.to_str().ok())
151        .unwrap_or("application/octet-stream");
152    let content_type = super::ContentType::from(content_type);
153
154    if !status.is_client_error() && !status.is_server_error() {
155        let content = resp.text().await?;
156        match content_type {
157            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
158            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SyncView`"))),
159            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::SyncView`")))),
160        }
161    } else {
162        let content = resp.text().await?;
163        let entity: Option<GetSyncByIdError> = serde_json::from_str(&content).ok();
164        Err(Error::ResponseError(ResponseContent { status, content, entity }))
165    }
166}
167
168/// Patch updates one sync's mutable policy — direction, trigger and actor — in place. The endpoints and the kind are immutable: re-pointing a sync is a delete and a create, so a link can never silently start syncing somewhere else. A field the request omits is left as it was. Changing the direction immediately reconciles the derived outbound mirror, so turning push off stops the upstream being written to rather than merely recording the intent.
169pub async fn patch_sync_by_id(configuration: &configuration::Configuration, id: &str, patch_sync_in: models::PatchSyncIn) -> Result<models::SyncView, Error<PatchSyncByIdError>> {
170    // add a prefix to parameters to efficiently prevent name collisions
171    let p_id = id;
172    let p_patch_sync_in = patch_sync_in;
173
174    let uri_str = format!("{}/v1/sync/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
175    let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
176
177    if let Some(ref user_agent) = configuration.user_agent {
178        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
179    }
180    if let Some(ref token) = configuration.bearer_access_token {
181        req_builder = req_builder.bearer_auth(token.to_owned());
182    };
183    req_builder = req_builder.json(&p_patch_sync_in);
184
185    let req = req_builder.build()?;
186    let resp = configuration.client.execute(req).await?;
187
188    let status = resp.status();
189    let content_type = resp
190        .headers()
191        .get("content-type")
192        .and_then(|v| v.to_str().ok())
193        .unwrap_or("application/octet-stream");
194    let content_type = super::ContentType::from(content_type);
195
196    if !status.is_client_error() && !status.is_server_error() {
197        let content = resp.text().await?;
198        match content_type {
199            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
200            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SyncView`"))),
201            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::SyncView`")))),
202        }
203    } else {
204        let content = resp.text().await?;
205        let entity: Option<PatchSyncByIdError> = serde_json::from_str(&content).ok();
206        Err(Error::ResponseError(ResponseContent { status, content, entity }))
207    }
208}
209
210/// Create declares a sync between two endpoints and returns it. It is an UPSERT: re-declaring the same source and target updates that link rather than piling up duplicates, so a console that re-submits is safe. The org comes from the validated principal, never from the request, so a sync can only ever bind endpoints inside the caller's own org. A git source must be an https clone URL on the provider's own host with no embedded credentials; a target left empty is derived as a native repository named after the source. With run=true the first reconcile is queued in the background, so a large initial import never blocks this response.
211pub async fn post_sync(configuration: &configuration::Configuration, sync_req: models::SyncReq) -> Result<models::SyncView, Error<PostSyncError>> {
212    // add a prefix to parameters to efficiently prevent name collisions
213    let p_sync_req = sync_req;
214
215    let uri_str = format!("{}/v1/sync", configuration.base_path);
216    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
217
218    if let Some(ref user_agent) = configuration.user_agent {
219        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
220    }
221    if let Some(ref token) = configuration.bearer_access_token {
222        req_builder = req_builder.bearer_auth(token.to_owned());
223    };
224    req_builder = req_builder.json(&p_sync_req);
225
226    let req = req_builder.build()?;
227    let resp = configuration.client.execute(req).await?;
228
229    let status = resp.status();
230    let content_type = resp
231        .headers()
232        .get("content-type")
233        .and_then(|v| v.to_str().ok())
234        .unwrap_or("application/octet-stream");
235    let content_type = super::ContentType::from(content_type);
236
237    if !status.is_client_error() && !status.is_server_error() {
238        let content = resp.text().await?;
239        match content_type {
240            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
241            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SyncView`"))),
242            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::SyncView`")))),
243        }
244    } else {
245        let content = resp.text().await?;
246        let entity: Option<PostSyncError> = serde_json::from_str(&content).ok();
247        Err(Error::ResponseError(ResponseContent { status, content, entity }))
248    }
249}
250
251/// Run reconciles one sync now — the manual re-sync, and the initial import for a link created without run=true. The work is handed to a bounded background worker and the call answers 202 immediately, so a large mirror-in never holds the request open; queued=true means accepted, not finished.
252pub async fn post_sync_by_id_run(configuration: &configuration::Configuration, id: &str) -> Result<models::SyncQueued, Error<PostSyncByIdRunError>> {
253    // add a prefix to parameters to efficiently prevent name collisions
254    let p_id = id;
255
256    let uri_str = format!("{}/v1/sync/{id}/run", configuration.base_path, id=crate::apis::urlencode(p_id));
257    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
258
259    if let Some(ref user_agent) = configuration.user_agent {
260        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
261    }
262    if let Some(ref token) = configuration.bearer_access_token {
263        req_builder = req_builder.bearer_auth(token.to_owned());
264    };
265
266    let req = req_builder.build()?;
267    let resp = configuration.client.execute(req).await?;
268
269    let status = resp.status();
270    let content_type = resp
271        .headers()
272        .get("content-type")
273        .and_then(|v| v.to_str().ok())
274        .unwrap_or("application/octet-stream");
275    let content_type = super::ContentType::from(content_type);
276
277    if !status.is_client_error() && !status.is_server_error() {
278        let content = resp.text().await?;
279        match content_type {
280            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
281            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SyncQueued`"))),
282            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::SyncQueued`")))),
283        }
284    } else {
285        let content = resp.text().await?;
286        let entity: Option<PostSyncByIdRunError> = serde_json::from_str(&content).ok();
287        Err(Error::ResponseError(ResponseContent { status, content, entity }))
288    }
289}
290