jira_api_v2/apis/
project_key_and_name_validation_api.rs

1/*
2 * The Jira Cloud platform REST API
3 *
4 * Jira Cloud platform REST API documentation
5 *
6 * The version of the OpenAPI document: 1001.0.0-SNAPSHOT
7 * Contact: ecosystem@atlassian.com
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 [`get_valid_project_key`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetValidProjectKeyError {
22    Status401(),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method [`get_valid_project_name`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum GetValidProjectNameError {
30    Status400(),
31    Status401(),
32    Status404(),
33    UnknownValue(serde_json::Value),
34}
35
36/// struct for typed errors of method [`validate_project_key`]
37#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(untagged)]
39pub enum ValidateProjectKeyError {
40    Status401(),
41    UnknownValue(serde_json::Value),
42}
43
44
45/// Validates a project key and, if the key is invalid or in use, generates a valid random string for the project key.  **[Permissions](#permissions) required:** None.
46pub async fn get_valid_project_key(configuration: &configuration::Configuration, key: Option<&str>) -> Result<String, Error<GetValidProjectKeyError>> {
47    // add a prefix to parameters to efficiently prevent name collisions
48    let p_key = key;
49
50    let uri_str = format!("{}/rest/api/2/projectvalidate/validProjectKey", configuration.base_path);
51    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
52
53    if let Some(ref param_value) = p_key {
54        req_builder = req_builder.query(&[("key", &param_value.to_string())]);
55    }
56    if let Some(ref user_agent) = configuration.user_agent {
57        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
58    }
59    if let Some(ref auth_conf) = configuration.basic_auth {
60        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
61    };
62
63    let req = req_builder.build()?;
64    let resp = configuration.client.execute(req).await?;
65
66    let status = resp.status();
67
68    if !status.is_client_error() && !status.is_server_error() {
69        let content = resp.text().await?;
70        serde_json::from_str(&content).map_err(Error::from)
71    } else {
72        let content = resp.text().await?;
73        let entity: Option<GetValidProjectKeyError> = serde_json::from_str(&content).ok();
74        Err(Error::ResponseError(ResponseContent { status, content, entity }))
75    }
76}
77
78/// Checks that a project name isn't in use. If the name isn't in use, the passed string is returned. If the name is in use, this operation attempts to generate a valid project name based on the one supplied, usually by adding a sequence number. If a valid project name cannot be generated, a 404 response is returned.  **[Permissions](#permissions) required:** None.
79pub async fn get_valid_project_name(configuration: &configuration::Configuration, name: &str) -> Result<String, Error<GetValidProjectNameError>> {
80    // add a prefix to parameters to efficiently prevent name collisions
81    let p_name = name;
82
83    let uri_str = format!("{}/rest/api/2/projectvalidate/validProjectName", configuration.base_path);
84    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
85
86    req_builder = req_builder.query(&[("name", &p_name.to_string())]);
87    if let Some(ref user_agent) = configuration.user_agent {
88        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
89    }
90    if let Some(ref auth_conf) = configuration.basic_auth {
91        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
92    };
93
94    let req = req_builder.build()?;
95    let resp = configuration.client.execute(req).await?;
96
97    let status = resp.status();
98
99    if !status.is_client_error() && !status.is_server_error() {
100        let content = resp.text().await?;
101        serde_json::from_str(&content).map_err(Error::from)
102    } else {
103        let content = resp.text().await?;
104        let entity: Option<GetValidProjectNameError> = serde_json::from_str(&content).ok();
105        Err(Error::ResponseError(ResponseContent { status, content, entity }))
106    }
107}
108
109/// Validates a project key by confirming the key is a valid string and not in use.  **[Permissions](#permissions) required:** None.
110pub async fn validate_project_key(configuration: &configuration::Configuration, key: Option<&str>) -> Result<models::ErrorCollection, Error<ValidateProjectKeyError>> {
111    // add a prefix to parameters to efficiently prevent name collisions
112    let p_key = key;
113
114    let uri_str = format!("{}/rest/api/2/projectvalidate/key", configuration.base_path);
115    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
116
117    if let Some(ref param_value) = p_key {
118        req_builder = req_builder.query(&[("key", &param_value.to_string())]);
119    }
120    if let Some(ref user_agent) = configuration.user_agent {
121        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
122    }
123    if let Some(ref token) = configuration.oauth_access_token {
124        req_builder = req_builder.bearer_auth(token.to_owned());
125    };
126    if let Some(ref auth_conf) = configuration.basic_auth {
127        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
128    };
129
130    let req = req_builder.build()?;
131    let resp = configuration.client.execute(req).await?;
132
133    let status = resp.status();
134
135    if !status.is_client_error() && !status.is_server_error() {
136        let content = resp.text().await?;
137        serde_json::from_str(&content).map_err(Error::from)
138    } else {
139        let content = resp.text().await?;
140        let entity: Option<ValidateProjectKeyError> = serde_json::from_str(&content).ok();
141        Err(Error::ResponseError(ResponseContent { status, content, entity }))
142    }
143}
144