openapi_github/apis/
secret_scanning_api.rs

1/*
2 * GitHub's official OpenAPI spec + Octokit extension
3 *
4 * OpenAPI specs from https://github.com/github/rest-api-description with the 'x-octokit' extension required by the Octokit SDKs
5 *
6 * The version of the OpenAPI document: 16.6.0
7 * 
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 [`secret_scanning_slash_get_alert`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum SecretScanningSlashGetAlertError {
22    Status404(),
23    Status503(models::SecretScanningListAlertsForEnterprise503Response),
24    UnknownValue(serde_json::Value),
25}
26
27/// struct for typed errors of method [`secret_scanning_slash_list_alerts_for_enterprise`]
28#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(untagged)]
30pub enum SecretScanningSlashListAlertsForEnterpriseError {
31    Status404(models::BasicError),
32    Status503(models::SecretScanningListAlertsForEnterprise503Response),
33    UnknownValue(serde_json::Value),
34}
35
36/// struct for typed errors of method [`secret_scanning_slash_list_alerts_for_org`]
37#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(untagged)]
39pub enum SecretScanningSlashListAlertsForOrgError {
40    Status404(models::BasicError),
41    Status503(models::SecretScanningListAlertsForEnterprise503Response),
42    UnknownValue(serde_json::Value),
43}
44
45/// struct for typed errors of method [`secret_scanning_slash_list_alerts_for_repo`]
46#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum SecretScanningSlashListAlertsForRepoError {
49    Status404(),
50    Status503(models::SecretScanningListAlertsForEnterprise503Response),
51    UnknownValue(serde_json::Value),
52}
53
54/// struct for typed errors of method [`secret_scanning_slash_list_locations_for_alert`]
55#[derive(Debug, Clone, Serialize, Deserialize)]
56#[serde(untagged)]
57pub enum SecretScanningSlashListLocationsForAlertError {
58    Status404(),
59    Status503(models::SecretScanningListAlertsForEnterprise503Response),
60    UnknownValue(serde_json::Value),
61}
62
63/// struct for typed errors of method [`secret_scanning_slash_update_alert`]
64#[derive(Debug, Clone, Serialize, Deserialize)]
65#[serde(untagged)]
66pub enum SecretScanningSlashUpdateAlertError {
67    Status400(),
68    Status404(),
69    Status422(),
70    Status503(models::SecretScanningListAlertsForEnterprise503Response),
71    UnknownValue(serde_json::Value),
72}
73
74
75/// Gets a single secret scanning alert detected in an eligible repository.  The authenticated user must be an administrator for the repository or for the organization that owns the repository to use this endpoint.  OAuth app tokens and personal access tokens (classic) need the `repo` or `security_events` scope to use this endpoint. If this endpoint is only used with public repositories, the token can use the `public_repo` scope instead.
76pub async fn secret_scanning_slash_get_alert(configuration: &configuration::Configuration, owner: &str, repo: &str, alert_number: i32) -> Result<models::SecretScanningAlert, Error<SecretScanningSlashGetAlertError>> {
77    let local_var_configuration = configuration;
78
79    let local_var_client = &local_var_configuration.client;
80
81    let local_var_uri_str = format!("{}/repos/{owner}/{repo}/secret-scanning/alerts/{alert_number}", local_var_configuration.base_path, owner=crate::apis::urlencode(owner), repo=crate::apis::urlencode(repo), alert_number=alert_number);
82    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
83
84    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
85        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
86    }
87
88    let local_var_req = local_var_req_builder.build()?;
89    let local_var_resp = local_var_client.execute(local_var_req).await?;
90
91    let local_var_status = local_var_resp.status();
92    let local_var_content = local_var_resp.text().await?;
93
94    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
95        serde_json::from_str(&local_var_content).map_err(Error::from)
96    } else {
97        let local_var_entity: Option<SecretScanningSlashGetAlertError> = serde_json::from_str(&local_var_content).ok();
98        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
99        Err(Error::ResponseError(local_var_error))
100    }
101}
102
103/// Lists secret scanning alerts for eligible repositories in an enterprise, from newest to oldest.  Alerts are only returned for organizations in the enterprise for which the authenticated user is an organization owner or a [security manager](https://docs.github.com/organizations/managing-peoples-access-to-your-organization-with-roles/managing-security-managers-in-your-organization).  The authenticated user must be a member of the enterprise in order to use this endpoint.  OAuth app tokens and personal access tokens (classic) need the `repo` scope or `security_events` scope to use this endpoint.
104pub async fn secret_scanning_slash_list_alerts_for_enterprise(configuration: &configuration::Configuration, enterprise: &str, state: Option<&str>, secret_type: Option<&str>, resolution: Option<&str>, sort: Option<&str>, direction: Option<&str>, per_page: Option<i32>, before: Option<&str>, after: Option<&str>, validity: Option<&str>) -> Result<Vec<models::OrganizationSecretScanningAlert>, Error<SecretScanningSlashListAlertsForEnterpriseError>> {
105    let local_var_configuration = configuration;
106
107    let local_var_client = &local_var_configuration.client;
108
109    let local_var_uri_str = format!("{}/enterprises/{enterprise}/secret-scanning/alerts", local_var_configuration.base_path, enterprise=crate::apis::urlencode(enterprise));
110    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
111
112    if let Some(ref local_var_str) = state {
113        local_var_req_builder = local_var_req_builder.query(&[("state", &local_var_str.to_string())]);
114    }
115    if let Some(ref local_var_str) = secret_type {
116        local_var_req_builder = local_var_req_builder.query(&[("secret_type", &local_var_str.to_string())]);
117    }
118    if let Some(ref local_var_str) = resolution {
119        local_var_req_builder = local_var_req_builder.query(&[("resolution", &local_var_str.to_string())]);
120    }
121    if let Some(ref local_var_str) = sort {
122        local_var_req_builder = local_var_req_builder.query(&[("sort", &local_var_str.to_string())]);
123    }
124    if let Some(ref local_var_str) = direction {
125        local_var_req_builder = local_var_req_builder.query(&[("direction", &local_var_str.to_string())]);
126    }
127    if let Some(ref local_var_str) = per_page {
128        local_var_req_builder = local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
129    }
130    if let Some(ref local_var_str) = before {
131        local_var_req_builder = local_var_req_builder.query(&[("before", &local_var_str.to_string())]);
132    }
133    if let Some(ref local_var_str) = after {
134        local_var_req_builder = local_var_req_builder.query(&[("after", &local_var_str.to_string())]);
135    }
136    if let Some(ref local_var_str) = validity {
137        local_var_req_builder = local_var_req_builder.query(&[("validity", &local_var_str.to_string())]);
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
143    let local_var_req = local_var_req_builder.build()?;
144    let local_var_resp = local_var_client.execute(local_var_req).await?;
145
146    let local_var_status = local_var_resp.status();
147    let local_var_content = local_var_resp.text().await?;
148
149    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
150        serde_json::from_str(&local_var_content).map_err(Error::from)
151    } else {
152        let local_var_entity: Option<SecretScanningSlashListAlertsForEnterpriseError> = serde_json::from_str(&local_var_content).ok();
153        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
154        Err(Error::ResponseError(local_var_error))
155    }
156}
157
158/// Lists secret scanning alerts for eligible repositories in an organization, from newest to oldest.  The authenticated user must be an administrator or security manager for the organization to use this endpoint.  OAuth app tokens and personal access tokens (classic) need the `repo` or `security_events` scope to use this endpoint. If this endpoint is only used with public repositories, the token can use the `public_repo` scope instead.
159pub async fn secret_scanning_slash_list_alerts_for_org(configuration: &configuration::Configuration, org: &str, state: Option<&str>, secret_type: Option<&str>, resolution: Option<&str>, sort: Option<&str>, direction: Option<&str>, page: Option<i32>, per_page: Option<i32>, before: Option<&str>, after: Option<&str>, validity: Option<&str>) -> Result<Vec<models::OrganizationSecretScanningAlert>, Error<SecretScanningSlashListAlertsForOrgError>> {
160    let local_var_configuration = configuration;
161
162    let local_var_client = &local_var_configuration.client;
163
164    let local_var_uri_str = format!("{}/orgs/{org}/secret-scanning/alerts", local_var_configuration.base_path, org=crate::apis::urlencode(org));
165    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
166
167    if let Some(ref local_var_str) = state {
168        local_var_req_builder = local_var_req_builder.query(&[("state", &local_var_str.to_string())]);
169    }
170    if let Some(ref local_var_str) = secret_type {
171        local_var_req_builder = local_var_req_builder.query(&[("secret_type", &local_var_str.to_string())]);
172    }
173    if let Some(ref local_var_str) = resolution {
174        local_var_req_builder = local_var_req_builder.query(&[("resolution", &local_var_str.to_string())]);
175    }
176    if let Some(ref local_var_str) = sort {
177        local_var_req_builder = local_var_req_builder.query(&[("sort", &local_var_str.to_string())]);
178    }
179    if let Some(ref local_var_str) = direction {
180        local_var_req_builder = local_var_req_builder.query(&[("direction", &local_var_str.to_string())]);
181    }
182    if let Some(ref local_var_str) = page {
183        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
184    }
185    if let Some(ref local_var_str) = per_page {
186        local_var_req_builder = local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
187    }
188    if let Some(ref local_var_str) = before {
189        local_var_req_builder = local_var_req_builder.query(&[("before", &local_var_str.to_string())]);
190    }
191    if let Some(ref local_var_str) = after {
192        local_var_req_builder = local_var_req_builder.query(&[("after", &local_var_str.to_string())]);
193    }
194    if let Some(ref local_var_str) = validity {
195        local_var_req_builder = local_var_req_builder.query(&[("validity", &local_var_str.to_string())]);
196    }
197    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
198        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
199    }
200
201    let local_var_req = local_var_req_builder.build()?;
202    let local_var_resp = local_var_client.execute(local_var_req).await?;
203
204    let local_var_status = local_var_resp.status();
205    let local_var_content = local_var_resp.text().await?;
206
207    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
208        serde_json::from_str(&local_var_content).map_err(Error::from)
209    } else {
210        let local_var_entity: Option<SecretScanningSlashListAlertsForOrgError> = serde_json::from_str(&local_var_content).ok();
211        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
212        Err(Error::ResponseError(local_var_error))
213    }
214}
215
216/// Lists secret scanning alerts for an eligible repository, from newest to oldest.  The authenticated user must be an administrator for the repository or for the organization that owns the repository to use this endpoint.  OAuth app tokens and personal access tokens (classic) need the `repo` or `security_events` scope to use this endpoint. If this endpoint is only used with public repositories, the token can use the `public_repo` scope instead.
217pub async fn secret_scanning_slash_list_alerts_for_repo(configuration: &configuration::Configuration, owner: &str, repo: &str, state: Option<&str>, secret_type: Option<&str>, resolution: Option<&str>, sort: Option<&str>, direction: Option<&str>, page: Option<i32>, per_page: Option<i32>, before: Option<&str>, after: Option<&str>, validity: Option<&str>) -> Result<Vec<models::SecretScanningAlert>, Error<SecretScanningSlashListAlertsForRepoError>> {
218    let local_var_configuration = configuration;
219
220    let local_var_client = &local_var_configuration.client;
221
222    let local_var_uri_str = format!("{}/repos/{owner}/{repo}/secret-scanning/alerts", local_var_configuration.base_path, owner=crate::apis::urlencode(owner), repo=crate::apis::urlencode(repo));
223    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
224
225    if let Some(ref local_var_str) = state {
226        local_var_req_builder = local_var_req_builder.query(&[("state", &local_var_str.to_string())]);
227    }
228    if let Some(ref local_var_str) = secret_type {
229        local_var_req_builder = local_var_req_builder.query(&[("secret_type", &local_var_str.to_string())]);
230    }
231    if let Some(ref local_var_str) = resolution {
232        local_var_req_builder = local_var_req_builder.query(&[("resolution", &local_var_str.to_string())]);
233    }
234    if let Some(ref local_var_str) = sort {
235        local_var_req_builder = local_var_req_builder.query(&[("sort", &local_var_str.to_string())]);
236    }
237    if let Some(ref local_var_str) = direction {
238        local_var_req_builder = local_var_req_builder.query(&[("direction", &local_var_str.to_string())]);
239    }
240    if let Some(ref local_var_str) = page {
241        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
242    }
243    if let Some(ref local_var_str) = per_page {
244        local_var_req_builder = local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
245    }
246    if let Some(ref local_var_str) = before {
247        local_var_req_builder = local_var_req_builder.query(&[("before", &local_var_str.to_string())]);
248    }
249    if let Some(ref local_var_str) = after {
250        local_var_req_builder = local_var_req_builder.query(&[("after", &local_var_str.to_string())]);
251    }
252    if let Some(ref local_var_str) = validity {
253        local_var_req_builder = local_var_req_builder.query(&[("validity", &local_var_str.to_string())]);
254    }
255    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
256        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
257    }
258
259    let local_var_req = local_var_req_builder.build()?;
260    let local_var_resp = local_var_client.execute(local_var_req).await?;
261
262    let local_var_status = local_var_resp.status();
263    let local_var_content = local_var_resp.text().await?;
264
265    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
266        serde_json::from_str(&local_var_content).map_err(Error::from)
267    } else {
268        let local_var_entity: Option<SecretScanningSlashListAlertsForRepoError> = serde_json::from_str(&local_var_content).ok();
269        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
270        Err(Error::ResponseError(local_var_error))
271    }
272}
273
274/// Lists all locations for a given secret scanning alert for an eligible repository.  The authenticated user must be an administrator for the repository or for the organization that owns the repository to use this endpoint.  OAuth app tokens and personal access tokens (classic) need the `repo` or `security_events` scope to use this endpoint. If this endpoint is only used with public repositories, the token can use the `public_repo` scope instead.
275pub async fn secret_scanning_slash_list_locations_for_alert(configuration: &configuration::Configuration, owner: &str, repo: &str, alert_number: i32, page: Option<i32>, per_page: Option<i32>) -> Result<Vec<models::SecretScanningLocation>, Error<SecretScanningSlashListLocationsForAlertError>> {
276    let local_var_configuration = configuration;
277
278    let local_var_client = &local_var_configuration.client;
279
280    let local_var_uri_str = format!("{}/repos/{owner}/{repo}/secret-scanning/alerts/{alert_number}/locations", local_var_configuration.base_path, owner=crate::apis::urlencode(owner), repo=crate::apis::urlencode(repo), alert_number=alert_number);
281    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
282
283    if let Some(ref local_var_str) = page {
284        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
285    }
286    if let Some(ref local_var_str) = per_page {
287        local_var_req_builder = local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
288    }
289    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
290        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
291    }
292
293    let local_var_req = local_var_req_builder.build()?;
294    let local_var_resp = local_var_client.execute(local_var_req).await?;
295
296    let local_var_status = local_var_resp.status();
297    let local_var_content = local_var_resp.text().await?;
298
299    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
300        serde_json::from_str(&local_var_content).map_err(Error::from)
301    } else {
302        let local_var_entity: Option<SecretScanningSlashListLocationsForAlertError> = serde_json::from_str(&local_var_content).ok();
303        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
304        Err(Error::ResponseError(local_var_error))
305    }
306}
307
308/// Updates the status of a secret scanning alert in an eligible repository.  The authenticated user must be an administrator for the repository or for the organization that owns the repository to use this endpoint.  OAuth app tokens and personal access tokens (classic) need the `repo` or `security_events` scope to use this endpoint. If this endpoint is only used with public repositories, the token can use the `public_repo` scope instead.
309pub async fn secret_scanning_slash_update_alert(configuration: &configuration::Configuration, owner: &str, repo: &str, alert_number: i32, secret_scanning_update_alert_request: models::SecretScanningUpdateAlertRequest) -> Result<models::SecretScanningAlert, Error<SecretScanningSlashUpdateAlertError>> {
310    let local_var_configuration = configuration;
311
312    let local_var_client = &local_var_configuration.client;
313
314    let local_var_uri_str = format!("{}/repos/{owner}/{repo}/secret-scanning/alerts/{alert_number}", local_var_configuration.base_path, owner=crate::apis::urlencode(owner), repo=crate::apis::urlencode(repo), alert_number=alert_number);
315    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
316
317    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
318        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
319    }
320    local_var_req_builder = local_var_req_builder.json(&secret_scanning_update_alert_request);
321
322    let local_var_req = local_var_req_builder.build()?;
323    let local_var_resp = local_var_client.execute(local_var_req).await?;
324
325    let local_var_status = local_var_resp.status();
326    let local_var_content = local_var_resp.text().await?;
327
328    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
329        serde_json::from_str(&local_var_content).map_err(Error::from)
330    } else {
331        let local_var_entity: Option<SecretScanningSlashUpdateAlertError> = serde_json::from_str(&local_var_content).ok();
332        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
333        Err(Error::ResponseError(local_var_error))
334    }
335}
336