gitbundle_sdk/apis/
runners_api.rs1use reqwest;
12use serde::{de::Error as _, Deserialize, Serialize};
13
14use super::{configuration, ContentType, Error};
15use crate::{apis::ResponseContent, models};
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum PollStageError {
21 Status400(models::JsonErrorResponseNull),
22 Status401(models::JsonErrorResponseNull),
23 Status403(models::JsonErrorResponseNull),
24 Status404(models::JsonErrorResponseNull),
25 Status409(models::JsonErrorResponseNull),
26 Status429(models::JsonErrorResponseNull),
27 Status500(models::JsonErrorResponseNull),
28 UnknownValue(serde_json::Value),
29}
30
31#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(untagged)]
34pub enum PostRunnersRegisterError {
35 Status400(models::JsonErrorResponseNull),
36 Status401(models::JsonErrorResponseNull),
37 Status403(models::JsonErrorResponseNull),
38 Status404(models::JsonErrorResponseNull),
39 Status409(models::JsonErrorResponseNull),
40 Status429(models::JsonErrorResponseNull),
41 Status500(models::JsonErrorResponseNull),
42 UnknownValue(serde_json::Value),
43}
44
45pub async fn poll_stage(
46 configuration: &configuration::Configuration,
47 runner_context: models::RunnerContext,
48) -> Result<models::StageMetadata, Error<PollStageError>> {
49 let p_body_runner_context = runner_context;
51
52 let uri_str = format!("{}/runners/poll_stage", configuration.base_path);
53 let mut req_builder = configuration
54 .client
55 .request(reqwest::Method::POST, &uri_str);
56
57 if let Some(ref apikey) = configuration.api_key {
58 let key = apikey.key.clone();
59 let value = match apikey.prefix {
60 Some(ref prefix) => format!("{} {}", prefix, key),
61 None => key,
62 };
63 req_builder = req_builder.query(&[("access_token", value)]);
64 }
65 if let Some(ref user_agent) = configuration.user_agent {
66 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
67 }
68 if let Some(ref auth_conf) = configuration.basic_auth {
69 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
70 };
71 if let Some(ref token) = configuration.bearer_access_token {
72 req_builder = req_builder.bearer_auth(token.to_owned());
73 };
74 req_builder = req_builder.json(&p_body_runner_context);
75
76 let req = req_builder.build()?;
77 let resp = configuration.client.execute(req).await?;
78
79 let status = resp.status();
80 let content_type = resp
81 .headers()
82 .get("content-type")
83 .and_then(|v| v.to_str().ok())
84 .unwrap_or("application/octet-stream");
85 let content_type = super::ContentType::from(content_type);
86
87 if !status.is_client_error() && !status.is_server_error() {
88 let content = resp.text().await?;
89 match content_type {
90 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
91 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::StageMetadata`"))),
92 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::StageMetadata`")))),
93 }
94 } else {
95 let content = resp.text().await?;
96 let entity: Option<PollStageError> = serde_json::from_str(&content).ok();
97 Err(Error::ResponseError(ResponseContent {
98 status,
99 content,
100 entity,
101 }))
102 }
103}
104
105pub async fn post_runners_register(
106 configuration: &configuration::Configuration,
107 runner_post_input: models::RunnerPostInput,
108) -> Result<models::TokenCreateOutput, Error<PostRunnersRegisterError>> {
109 let p_body_runner_post_input = runner_post_input;
111
112 let uri_str = format!("{}/runners/register", configuration.base_path);
113 let mut req_builder = configuration
114 .client
115 .request(reqwest::Method::POST, &uri_str);
116
117 if let Some(ref user_agent) = configuration.user_agent {
118 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
119 }
120 req_builder = req_builder.json(&p_body_runner_post_input);
121
122 let req = req_builder.build()?;
123 let resp = configuration.client.execute(req).await?;
124
125 let status = resp.status();
126 let content_type = resp
127 .headers()
128 .get("content-type")
129 .and_then(|v| v.to_str().ok())
130 .unwrap_or("application/octet-stream");
131 let content_type = super::ContentType::from(content_type);
132
133 if !status.is_client_error() && !status.is_server_error() {
134 let content = resp.text().await?;
135 match content_type {
136 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
137 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TokenCreateOutput`"))),
138 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::TokenCreateOutput`")))),
139 }
140 } else {
141 let content = resp.text().await?;
142 let entity: Option<PostRunnersRegisterError> = serde_json::from_str(&content).ok();
143 Err(Error::ResponseError(ResponseContent {
144 status,
145 content,
146 entity,
147 }))
148 }
149}