Skip to main content

tapis_workflows/apis/
cicd_api.rs

1/*
2 * Tapis Workflows API
3 *
4 * Create and manage pipelines
5 *
6 * The version of the OpenAPI document: 1.6.0
7 * Contact: cicsupport@tacc.utexas.edu
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16/// struct for typed errors of method [`create_ci_pipeline`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum CreateCiPipelineError {
20    Status400(models::RespError),
21    Status401(models::RespError),
22    Status403(models::RespError),
23    Status405(models::RespError),
24    Status409(models::RespError),
25    Status415(models::RespError),
26    Status422(models::RespError),
27    Status500(models::RespError),
28    UnknownValue(serde_json::Value),
29}
30
31/// Create a CI/CD pipeline using a request body. Pipeline id must be unique within a group and can be composed of alphanumeric characters and the following special characters [-_.].  Note: When creating pipelines for the CI/CD use case(primarily building images), use this endpoint. It offers a simplified interface for those who want to avoid the complexities of creating a standard workflow. This pipeline's tasks may be modified later.
32pub async fn create_ci_pipeline(
33    configuration: &configuration::Configuration,
34    group_id: &str,
35    req_ci_pipeline: models::ReqCiPipeline,
36) -> Result<models::RespResourceUrl, Error<CreateCiPipelineError>> {
37    // add a prefix to parameters to efficiently prevent name collisions
38    let p_path_group_id = group_id;
39    let p_body_req_ci_pipeline = req_ci_pipeline;
40
41    let uri_str = format!(
42        "{}/v3/workflows/groups/{group_id}/ci",
43        configuration.base_path,
44        group_id = crate::apis::urlencode(p_path_group_id)
45    );
46    let mut req_builder = configuration
47        .client
48        .request(reqwest::Method::POST, &uri_str);
49
50    if let Some(ref user_agent) = configuration.user_agent {
51        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
52    }
53    if let Some(ref apikey) = configuration.api_key {
54        let key = apikey.key.clone();
55        let value = match apikey.prefix {
56            Some(ref prefix) => format!("{} {}", prefix, key),
57            None => key,
58        };
59        req_builder = req_builder.header("X-TAPIS-TOKEN", value);
60    };
61    req_builder = req_builder.json(&p_body_req_ci_pipeline);
62
63    let req = req_builder.build()?;
64    let resp = configuration.client.execute(req).await?;
65
66    let status = resp.status();
67    let content_type = resp
68        .headers()
69        .get("content-type")
70        .and_then(|v| v.to_str().ok())
71        .unwrap_or("application/octet-stream");
72    let content_type = super::ContentType::from(content_type);
73
74    if !status.is_client_error() && !status.is_server_error() {
75        let content = resp.text().await?;
76        match content_type {
77            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
78            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespResourceUrl`"))),
79            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespResourceUrl`")))),
80        }
81    } else {
82        let content = resp.text().await?;
83        let entity: Option<CreateCiPipelineError> = serde_json::from_str(&content).ok();
84        Err(Error::ResponseError(ResponseContent {
85            status,
86            content,
87            entity,
88        }))
89    }
90}