Skip to main content

windmill_api/apis/
git_sync_api.rs

1/*
2 * Windmill API
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: 1.660.1
7 * Contact: contact@windmill.dev
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`delete_from_workspace`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum DeleteFromWorkspaceError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`export_installation`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum ExportInstallationError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`get_ghes_config`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetGhesConfigError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`get_global_connected_repositories`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum GetGlobalConnectedRepositoriesError {
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`ghes_installation_callback`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum GhesInstallationCallbackError {
50    UnknownValue(serde_json::Value),
51}
52
53/// struct for typed errors of method [`import_installation`]
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum ImportInstallationError {
57    UnknownValue(serde_json::Value),
58}
59
60/// struct for typed errors of method [`install_from_workspace`]
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum InstallFromWorkspaceError {
64    UnknownValue(serde_json::Value),
65}
66
67
68/// Removes a GitHub installation from the specified workspace. Requires admin privileges.
69pub async fn delete_from_workspace(configuration: &configuration::Configuration, workspace: &str, installation_id: i64) -> Result<(), Error<DeleteFromWorkspaceError>> {
70    let local_var_configuration = configuration;
71
72    let local_var_client = &local_var_configuration.client;
73
74    let local_var_uri_str = format!("{}/w/{workspace}/github_app/installation/{installation_id}", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace), installation_id=installation_id);
75    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
76
77    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
78        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
79    }
80    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
81        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
82    };
83
84    let local_var_req = local_var_req_builder.build()?;
85    let local_var_resp = local_var_client.execute(local_var_req).await?;
86
87    let local_var_status = local_var_resp.status();
88    let local_var_content = local_var_resp.text().await?;
89
90    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
91        Ok(())
92    } else {
93        let local_var_entity: Option<DeleteFromWorkspaceError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
94        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
95        Err(Error::ResponseError(local_var_error))
96    }
97}
98
99/// Exports the JWT token for a specific GitHub installation in the workspace
100pub async fn export_installation(configuration: &configuration::Configuration, workspace: &str, installation_id: i32) -> Result<models::ExportInstallation200Response, Error<ExportInstallationError>> {
101    let local_var_configuration = configuration;
102
103    let local_var_client = &local_var_configuration.client;
104
105    let local_var_uri_str = format!("{}/w/{workspace}/github_app/export/{installationId}", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace), installationId=installation_id);
106    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
107
108    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
109        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
110    }
111    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
112        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
113    };
114
115    let local_var_req = local_var_req_builder.build()?;
116    let local_var_resp = local_var_client.execute(local_var_req).await?;
117
118    let local_var_status = local_var_resp.status();
119    let local_var_content = local_var_resp.text().await?;
120
121    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
122        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
123    } else {
124        let local_var_entity: Option<ExportInstallationError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
125        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
126        Err(Error::ResponseError(local_var_error))
127    }
128}
129
130/// Returns the GitHub Enterprise Server app configuration (without private key) for constructing the installation URL
131pub async fn get_ghes_config(configuration: &configuration::Configuration, ) -> Result<models::GetGhesConfig200Response, Error<GetGhesConfigError>> {
132    let local_var_configuration = configuration;
133
134    let local_var_client = &local_var_configuration.client;
135
136    let local_var_uri_str = format!("{}/github_app/ghes_config", local_var_configuration.base_path);
137    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
138
139    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
140        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
141    }
142    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
143        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
144    };
145
146    let local_var_req = local_var_req_builder.build()?;
147    let local_var_resp = local_var_client.execute(local_var_req).await?;
148
149    let local_var_status = local_var_resp.status();
150    let local_var_content = local_var_resp.text().await?;
151
152    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
153        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
154    } else {
155        let local_var_entity: Option<GetGhesConfigError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
156        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
157        Err(Error::ResponseError(local_var_error))
158    }
159}
160
161pub async fn get_global_connected_repositories(configuration: &configuration::Configuration, page: Option<i32>) -> Result<Vec<models::GithubInstallationsInner>, Error<GetGlobalConnectedRepositoriesError>> {
162    let local_var_configuration = configuration;
163
164    let local_var_client = &local_var_configuration.client;
165
166    let local_var_uri_str = format!("{}/github_app/connected_repositories", local_var_configuration.base_path);
167    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
168
169    if let Some(ref local_var_str) = page {
170        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
171    }
172    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
173        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
174    }
175    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
176        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
177    };
178
179    let local_var_req = local_var_req_builder.build()?;
180    let local_var_resp = local_var_client.execute(local_var_req).await?;
181
182    let local_var_status = local_var_resp.status();
183    let local_var_content = local_var_resp.text().await?;
184
185    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
186        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
187    } else {
188        let local_var_entity: Option<GetGlobalConnectedRepositoriesError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
189        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
190        Err(Error::ResponseError(local_var_error))
191    }
192}
193
194/// Register a self-managed GitHub App installation from GitHub Enterprise Server
195pub async fn ghes_installation_callback(configuration: &configuration::Configuration, workspace: &str, ghes_installation_callback_request: models::GhesInstallationCallbackRequest) -> Result<(), Error<GhesInstallationCallbackError>> {
196    let local_var_configuration = configuration;
197
198    let local_var_client = &local_var_configuration.client;
199
200    let local_var_uri_str = format!("{}/w/{workspace}/github_app/ghes_installation_callback", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
201    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
202
203    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
204        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
205    }
206    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
207        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
208    };
209    local_var_req_builder = local_var_req_builder.json(&ghes_installation_callback_request);
210
211    let local_var_req = local_var_req_builder.build()?;
212    let local_var_resp = local_var_client.execute(local_var_req).await?;
213
214    let local_var_status = local_var_resp.status();
215    let local_var_content = local_var_resp.text().await?;
216
217    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
218        Ok(())
219    } else {
220        let local_var_entity: Option<GhesInstallationCallbackError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
221        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
222        Err(Error::ResponseError(local_var_error))
223    }
224}
225
226/// Imports a GitHub installation from a JWT token exported from another instance
227pub async fn import_installation(configuration: &configuration::Configuration, workspace: &str, import_installation_request: models::ImportInstallationRequest) -> Result<(), Error<ImportInstallationError>> {
228    let local_var_configuration = configuration;
229
230    let local_var_client = &local_var_configuration.client;
231
232    let local_var_uri_str = format!("{}/w/{workspace}/github_app/import", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
233    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
234
235    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
236        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
237    }
238    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
239        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
240    };
241    local_var_req_builder = local_var_req_builder.json(&import_installation_request);
242
243    let local_var_req = local_var_req_builder.build()?;
244    let local_var_resp = local_var_client.execute(local_var_req).await?;
245
246    let local_var_status = local_var_resp.status();
247    let local_var_content = local_var_resp.text().await?;
248
249    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
250        Ok(())
251    } else {
252        let local_var_entity: Option<ImportInstallationError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
253        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
254        Err(Error::ResponseError(local_var_error))
255    }
256}
257
258pub async fn install_from_workspace(configuration: &configuration::Configuration, workspace: &str, install_from_workspace_request: models::InstallFromWorkspaceRequest) -> Result<(), Error<InstallFromWorkspaceError>> {
259    let local_var_configuration = configuration;
260
261    let local_var_client = &local_var_configuration.client;
262
263    let local_var_uri_str = format!("{}/w/{workspace}/github_app/install_from_workspace", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
264    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
265
266    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
267        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
268    }
269    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
270        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
271    };
272    local_var_req_builder = local_var_req_builder.json(&install_from_workspace_request);
273
274    let local_var_req = local_var_req_builder.build()?;
275    let local_var_resp = local_var_client.execute(local_var_req).await?;
276
277    let local_var_status = local_var_resp.status();
278    let local_var_content = local_var_resp.text().await?;
279
280    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
281        Ok(())
282    } else {
283        let local_var_entity: Option<InstallFromWorkspaceError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
284        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
285        Err(Error::ResponseError(local_var_error))
286    }
287}
288