jira_api_v2/apis/
issue_attachments_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 [`add_attachment`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AddAttachmentError {
22    Status403(),
23    Status404(),
24    Status413(),
25    UnknownValue(serde_json::Value),
26}
27
28/// struct for typed errors of method [`expand_attachment_for_humans`]
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum ExpandAttachmentForHumansError {
32    Status401(),
33    Status403(),
34    Status404(),
35    Status409(),
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`expand_attachment_for_machines`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum ExpandAttachmentForMachinesError {
43    Status401(),
44    Status403(),
45    Status404(),
46    Status409(),
47    UnknownValue(serde_json::Value),
48}
49
50/// struct for typed errors of method [`get_attachment`]
51#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum GetAttachmentError {
54    Status401(),
55    Status403(),
56    Status404(),
57    UnknownValue(serde_json::Value),
58}
59
60/// struct for typed errors of method [`get_attachment_meta`]
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum GetAttachmentMetaError {
64    Status401(),
65    UnknownValue(serde_json::Value),
66}
67
68/// struct for typed errors of method [`remove_attachment`]
69#[derive(Debug, Clone, Serialize, Deserialize)]
70#[serde(untagged)]
71pub enum RemoveAttachmentError {
72    Status403(),
73    Status404(),
74    UnknownValue(serde_json::Value),
75}
76
77
78/// Adds one or more attachments to an issue. Attachments are posted as multipart/form-data ([RFC 1867](https://www.ietf.org/rfc/rfc1867.txt)).  Note that:   *  The request must have a `X-Atlassian-Token: no-check` header, if not it is blocked. See [Special headers](#special-request-headers) for more information.  *  The name of the multipart/form-data parameter that contains the attachments must be `file`.  The following example uploads a file called *myfile.txt* to the issue *TEST-123*:  `curl -D- -u admin:admin -X POST -H \"X-Atlassian-Token: no-check\" -F \"file=@myfile.txt\" https://your-domain.atlassian.net/rest/api/2/issue/TEST-123/attachments`  Tip: Use a client library. Many client libraries have classes for handling multipart POST operations. For example, in Java, the Apache HTTP Components library provides a [MultiPartEntity](http://hc.apache.org/httpcomponents-client-ga/httpmime/apidocs/org/apache/http/entity/mime/MultipartEntity.html) class for multipart POST operations.  This operation can be accessed anonymously.  **[Permissions](#permissions) required:**    *  *Browse Projects* and *Create attachments* [ project permission](https://confluence.atlassian.com/x/yodKLg) for the project that the issue is in.  *  If [issue-level security](https://confluence.atlassian.com/x/J4lKLg) is configured, issue-level security permission to view the issue.
79pub async fn add_attachment(configuration: &configuration::Configuration, issue_id_or_key: &str) -> Result<Vec<models::Attachment>, Error<AddAttachmentError>> {
80    // add a prefix to parameters to efficiently prevent name collisions
81    let p_issue_id_or_key = issue_id_or_key;
82
83    let uri_str = format!("{}/rest/api/2/issue/{issueIdOrKey}/attachments", configuration.base_path, issueIdOrKey=crate::apis::urlencode(p_issue_id_or_key));
84    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
85
86    if let Some(ref user_agent) = configuration.user_agent {
87        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
88    }
89    if let Some(ref token) = configuration.oauth_access_token {
90        req_builder = req_builder.bearer_auth(token.to_owned());
91    };
92    if let Some(ref auth_conf) = configuration.basic_auth {
93        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
94    };
95
96    let req = req_builder.build()?;
97    let resp = configuration.client.execute(req).await?;
98
99    let status = resp.status();
100
101    if !status.is_client_error() && !status.is_server_error() {
102        let content = resp.text().await?;
103        serde_json::from_str(&content).map_err(Error::from)
104    } else {
105        let content = resp.text().await?;
106        let entity: Option<AddAttachmentError> = serde_json::from_str(&content).ok();
107        Err(Error::ResponseError(ResponseContent { status, content, entity }))
108    }
109}
110
111/// Returns the metadata for the contents of an attachment, if it is an archive, and metadata for the attachment itself. For example, if the attachment is a ZIP archive, then information about the files in the archive is returned and metadata for the ZIP archive. Currently, only the ZIP archive format is supported.  Use this operation to retrieve data that is presented to the user, as this operation returns the metadata for the attachment itself, such as the attachment's ID and name. Otherwise, use [ Get contents metadata for an expanded attachment](#api-rest-api-2-attachment-id-expand-raw-get), which only returns the metadata for the attachment's contents.  This operation can be accessed anonymously.  **[Permissions](#permissions) required:** For the issue containing the attachment:   *  *Browse projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project that the issue is in.  *  If [issue-level security](https://confluence.atlassian.com/x/J4lKLg) is configured, issue-level security permission to view the issue.
112pub async fn expand_attachment_for_humans(configuration: &configuration::Configuration, id: &str) -> Result<models::AttachmentArchiveMetadataReadable, Error<ExpandAttachmentForHumansError>> {
113    // add a prefix to parameters to efficiently prevent name collisions
114    let p_id = id;
115
116    let uri_str = format!("{}/rest/api/2/attachment/{id}/expand/human", configuration.base_path, id=crate::apis::urlencode(p_id));
117    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
118
119    if let Some(ref user_agent) = configuration.user_agent {
120        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
121    }
122    if let Some(ref token) = configuration.oauth_access_token {
123        req_builder = req_builder.bearer_auth(token.to_owned());
124    };
125    if let Some(ref auth_conf) = configuration.basic_auth {
126        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
127    };
128
129    let req = req_builder.build()?;
130    let resp = configuration.client.execute(req).await?;
131
132    let status = resp.status();
133
134    if !status.is_client_error() && !status.is_server_error() {
135        let content = resp.text().await?;
136        serde_json::from_str(&content).map_err(Error::from)
137    } else {
138        let content = resp.text().await?;
139        let entity: Option<ExpandAttachmentForHumansError> = serde_json::from_str(&content).ok();
140        Err(Error::ResponseError(ResponseContent { status, content, entity }))
141    }
142}
143
144/// Returns the metadata for the contents of an attachment, if it is an archive. For example, if the attachment is a ZIP archive, then information about the files in the archive is returned. Currently, only the ZIP archive format is supported.  Use this operation if you are processing the data without presenting it to the user, as this operation only returns the metadata for the contents of the attachment. Otherwise, to retrieve data to present to the user, use [ Get all metadata for an expanded attachment](#api-rest-api-2-attachment-id-expand-human-get) which also returns the metadata for the attachment itself, such as the attachment's ID and name.  This operation can be accessed anonymously.  **[Permissions](#permissions) required:** For the issue containing the attachment:   *  *Browse projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project that the issue is in.  *  If [issue-level security](https://confluence.atlassian.com/x/J4lKLg) is configured, issue-level security permission to view the issue.
145pub async fn expand_attachment_for_machines(configuration: &configuration::Configuration, id: &str) -> Result<models::AttachmentArchiveImpl, Error<ExpandAttachmentForMachinesError>> {
146    // add a prefix to parameters to efficiently prevent name collisions
147    let p_id = id;
148
149    let uri_str = format!("{}/rest/api/2/attachment/{id}/expand/raw", configuration.base_path, id=crate::apis::urlencode(p_id));
150    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
151
152    if let Some(ref user_agent) = configuration.user_agent {
153        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
154    }
155    if let Some(ref token) = configuration.oauth_access_token {
156        req_builder = req_builder.bearer_auth(token.to_owned());
157    };
158    if let Some(ref auth_conf) = configuration.basic_auth {
159        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
160    };
161
162    let req = req_builder.build()?;
163    let resp = configuration.client.execute(req).await?;
164
165    let status = resp.status();
166
167    if !status.is_client_error() && !status.is_server_error() {
168        let content = resp.text().await?;
169        serde_json::from_str(&content).map_err(Error::from)
170    } else {
171        let content = resp.text().await?;
172        let entity: Option<ExpandAttachmentForMachinesError> = serde_json::from_str(&content).ok();
173        Err(Error::ResponseError(ResponseContent { status, content, entity }))
174    }
175}
176
177/// Returns the metadata for an attachment. Note that the attachment itself is not returned.  This operation can be accessed anonymously.  **[Permissions](#permissions) required:**   *  *Browse projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project that the issue is in.  *  If [issue-level security](https://confluence.atlassian.com/x/J4lKLg) is configured, issue-level security permission to view the issue.
178pub async fn get_attachment(configuration: &configuration::Configuration, id: &str) -> Result<models::AttachmentMetadata, Error<GetAttachmentError>> {
179    // add a prefix to parameters to efficiently prevent name collisions
180    let p_id = id;
181
182    let uri_str = format!("{}/rest/api/2/attachment/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
183    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
184
185    if let Some(ref user_agent) = configuration.user_agent {
186        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
187    }
188    if let Some(ref token) = configuration.oauth_access_token {
189        req_builder = req_builder.bearer_auth(token.to_owned());
190    };
191    if let Some(ref auth_conf) = configuration.basic_auth {
192        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
193    };
194
195    let req = req_builder.build()?;
196    let resp = configuration.client.execute(req).await?;
197
198    let status = resp.status();
199
200    if !status.is_client_error() && !status.is_server_error() {
201        let content = resp.text().await?;
202        serde_json::from_str(&content).map_err(Error::from)
203    } else {
204        let content = resp.text().await?;
205        let entity: Option<GetAttachmentError> = serde_json::from_str(&content).ok();
206        Err(Error::ResponseError(ResponseContent { status, content, entity }))
207    }
208}
209
210/// Returns the attachment settings, that is, whether attachments are enabled and the maximum attachment size allowed.  Note that there are also [project permissions](https://confluence.atlassian.com/x/yodKLg) that restrict whether users can create and delete attachments.  This operation can be accessed anonymously.  **[Permissions](#permissions) required:** None.
211pub async fn get_attachment_meta(configuration: &configuration::Configuration, ) -> Result<models::AttachmentSettings, Error<GetAttachmentMetaError>> {
212
213    let uri_str = format!("{}/rest/api/2/attachment/meta", configuration.base_path);
214    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
215
216    if let Some(ref user_agent) = configuration.user_agent {
217        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
218    }
219    if let Some(ref token) = configuration.oauth_access_token {
220        req_builder = req_builder.bearer_auth(token.to_owned());
221    };
222    if let Some(ref auth_conf) = configuration.basic_auth {
223        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
224    };
225
226    let req = req_builder.build()?;
227    let resp = configuration.client.execute(req).await?;
228
229    let status = resp.status();
230
231    if !status.is_client_error() && !status.is_server_error() {
232        let content = resp.text().await?;
233        serde_json::from_str(&content).map_err(Error::from)
234    } else {
235        let content = resp.text().await?;
236        let entity: Option<GetAttachmentMetaError> = serde_json::from_str(&content).ok();
237        Err(Error::ResponseError(ResponseContent { status, content, entity }))
238    }
239}
240
241/// Deletes an attachment from an issue.  This operation can be accessed anonymously.  **[Permissions](#permissions) required:** For the project holding the issue containing the attachment:   *  *Delete own attachments* [project permission](https://confluence.atlassian.com/x/yodKLg) to delete an attachment created by the calling user.  *  *Delete all attachments* [project permission](https://confluence.atlassian.com/x/yodKLg) to delete an attachment created by any user.
242pub async fn remove_attachment(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<RemoveAttachmentError>> {
243    // add a prefix to parameters to efficiently prevent name collisions
244    let p_id = id;
245
246    let uri_str = format!("{}/rest/api/2/attachment/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
247    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
248
249    if let Some(ref user_agent) = configuration.user_agent {
250        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
251    }
252    if let Some(ref token) = configuration.oauth_access_token {
253        req_builder = req_builder.bearer_auth(token.to_owned());
254    };
255    if let Some(ref auth_conf) = configuration.basic_auth {
256        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
257    };
258
259    let req = req_builder.build()?;
260    let resp = configuration.client.execute(req).await?;
261
262    let status = resp.status();
263
264    if !status.is_client_error() && !status.is_server_error() {
265        Ok(())
266    } else {
267        let content = resp.text().await?;
268        let entity: Option<RemoveAttachmentError> = serde_json::from_str(&content).ok();
269        Err(Error::ResponseError(ResponseContent { status, content, entity }))
270    }
271}
272