azure_devops_rust_api/token_admin/
mod.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3#![allow(unused_mut)]
4#![allow(unused_variables)]
5#![allow(unused_imports)]
6#![allow(clippy::redundant_clone)]
7#![allow(clippy::too_many_arguments)]
8#![allow(clippy::module_inception)]
9pub mod models;
10#[derive(Clone)]
11pub struct Client {
12    endpoint: azure_core::http::Url,
13    credential: crate::Credential,
14    scopes: Vec<String>,
15    pipeline: azure_core::http::Pipeline,
16}
17#[derive(Clone)]
18pub struct ClientBuilder {
19    credential: crate::Credential,
20    endpoint: Option<azure_core::http::Url>,
21    scopes: Option<Vec<String>>,
22    options: azure_core::http::ClientOptions,
23}
24azure_core::static_url!(DEFAULT_ENDPOINT, "https://vssps.dev.azure.com");
25impl ClientBuilder {
26    #[doc = "Create a new instance of `ClientBuilder`."]
27    #[must_use]
28    pub fn new(credential: crate::Credential) -> Self {
29        Self {
30            credential,
31            endpoint: None,
32            scopes: None,
33            options: azure_core::http::ClientOptions::default(),
34        }
35    }
36    #[doc = "Set the endpoint."]
37    #[must_use]
38    pub fn endpoint(mut self, endpoint: impl Into<azure_core::http::Url>) -> Self {
39        self.endpoint = Some(endpoint.into());
40        self
41    }
42    #[doc = "Set the scopes."]
43    #[must_use]
44    pub fn scopes(mut self, scopes: &[&str]) -> Self {
45        self.scopes = Some(scopes.iter().map(|scope| (*scope).to_owned()).collect());
46        self
47    }
48    #[doc = "Set the retry options."]
49    #[must_use]
50    pub fn retry(mut self, retry: impl Into<azure_core::http::RetryOptions>) -> Self {
51        self.options.retry = Some(retry.into());
52        self
53    }
54    #[doc = "Set the transport options."]
55    #[must_use]
56    pub fn transport(mut self, transport: impl Into<azure_core::http::TransportOptions>) -> Self {
57        self.options.transport = Some(transport.into());
58        self
59    }
60    #[doc = "Set per-call policies."]
61    #[must_use]
62    pub fn per_call_policies(
63        mut self,
64        policies: impl Into<Vec<std::sync::Arc<dyn azure_core::http::policies::Policy>>>,
65    ) -> Self {
66        self.options.per_call_policies = policies.into();
67        self
68    }
69    #[doc = "Set per-try policies."]
70    #[must_use]
71    pub fn per_try_policies(
72        mut self,
73        policies: impl Into<Vec<std::sync::Arc<dyn azure_core::http::policies::Policy>>>,
74    ) -> Self {
75        self.options.per_try_policies = policies.into();
76        self
77    }
78    #[doc = "Convert the builder into a `Client` instance."]
79    pub fn build(self) -> Client {
80        let endpoint = self.endpoint.unwrap_or_else(|| DEFAULT_ENDPOINT.to_owned());
81        let scopes = self
82            .scopes
83            .unwrap_or_else(|| vec![crate::ADO_SCOPE.to_string()]);
84        Client::new(endpoint, self.credential, scopes, self.options)
85    }
86}
87impl Client {
88    pub(crate) fn endpoint(&self) -> &azure_core::http::Url {
89        &self.endpoint
90    }
91    pub(crate) fn token_credential(&self) -> &crate::Credential {
92        &self.credential
93    }
94    pub(crate) fn scopes(&self) -> Vec<&str> {
95        self.scopes.iter().map(String::as_str).collect()
96    }
97    pub(crate) async fn send(
98        &self,
99        request: &mut azure_core::http::Request,
100    ) -> azure_core::Result<azure_core::http::RawResponse> {
101        let context = azure_core::http::Context::default();
102        self.pipeline.send(&context, request).await
103    }
104    #[doc = "Create a new `ClientBuilder`."]
105    #[must_use]
106    pub fn builder(credential: crate::Credential) -> ClientBuilder {
107        ClientBuilder::new(credential)
108    }
109    #[doc = "Create a new `Client`."]
110    #[must_use]
111    pub fn new(
112        endpoint: impl Into<azure_core::http::Url>,
113        credential: crate::Credential,
114        scopes: Vec<String>,
115        options: azure_core::http::ClientOptions,
116    ) -> Self {
117        let endpoint = endpoint.into();
118        let pipeline = azure_core::http::Pipeline::new(
119            option_env!("CARGO_PKG_NAME"),
120            option_env!("CARGO_PKG_VERSION"),
121            options,
122            Vec::new(),
123            Vec::new(),
124        );
125        Self {
126            endpoint,
127            credential,
128            scopes,
129            pipeline,
130        }
131    }
132    pub fn personal_access_tokens_client(&self) -> personal_access_tokens::Client {
133        personal_access_tokens::Client(self.clone())
134    }
135    pub fn revocation_rules_client(&self) -> revocation_rules::Client {
136        revocation_rules::Client(self.clone())
137    }
138    pub fn revocations_client(&self) -> revocations::Client {
139        revocations::Client(self.clone())
140    }
141}
142pub mod personal_access_tokens {
143    use super::models;
144    #[cfg(not(target_arch = "wasm32"))]
145    use futures::future::BoxFuture;
146    #[cfg(target_arch = "wasm32")]
147    use futures::future::LocalBoxFuture as BoxFuture;
148    pub struct Client(pub(crate) super::Client);
149    impl Client {
150        #[doc = "Lists of all the session token details of the personal access tokens (PATs) for a particular user."]
151        #[doc = ""]
152        #[doc = "Arguments:"]
153        #[doc = "* `organization`: The name of the Azure DevOps organization."]
154        #[doc = "* `subject_descriptor`: The descriptor of the target user."]
155        pub fn list(
156            &self,
157            organization: impl Into<String>,
158            subject_descriptor: impl Into<String>,
159        ) -> list::RequestBuilder {
160            list::RequestBuilder {
161                client: self.0.clone(),
162                organization: organization.into(),
163                subject_descriptor: subject_descriptor.into(),
164                page_size: None,
165                continuation_token: None,
166                is_public: None,
167            }
168        }
169    }
170    pub mod list {
171        use super::models;
172        #[cfg(not(target_arch = "wasm32"))]
173        use futures::future::BoxFuture;
174        #[cfg(target_arch = "wasm32")]
175        use futures::future::LocalBoxFuture as BoxFuture;
176        #[derive(Debug)]
177        pub struct Response(
178            azure_core::http::Response<
179                models::TokenAdminPagedSessionTokens,
180                azure_core::http::JsonFormat,
181            >,
182        );
183        impl Response {
184            pub async fn into_body(
185                self,
186            ) -> azure_core::Result<models::TokenAdminPagedSessionTokens> {
187                self.0.into_body().await
188            }
189            pub fn into_raw_response(self) -> azure_core::http::RawResponse {
190                self.0.into()
191            }
192        }
193        #[derive(Clone)]
194        #[doc = r" `RequestBuilder` provides a mechanism for setting optional parameters on a request."]
195        #[doc = r""]
196        #[doc = r" Each `RequestBuilder` parameter method call returns `Self`, so setting of multiple"]
197        #[doc = r" parameters can be chained."]
198        #[doc = r""]
199        #[doc = r" To finalize and submit the request, invoke `.await`, which"]
200        #[doc = r" converts the [`RequestBuilder`] into a future,"]
201        #[doc = r" executes the request and returns a `Result` with the parsed"]
202        #[doc = r" response."]
203        #[doc = r""]
204        #[doc = r" If you need lower-level access to the raw response details"]
205        #[doc = r" (e.g. to inspect response headers or raw body data) then you"]
206        #[doc = r" can finalize the request using the"]
207        #[doc = r" [`RequestBuilder::send()`] method which returns a future"]
208        #[doc = r" that resolves to a lower-level [`Response`] value."]
209        pub struct RequestBuilder {
210            pub(crate) client: super::super::Client,
211            pub(crate) organization: String,
212            pub(crate) subject_descriptor: String,
213            pub(crate) page_size: Option<i32>,
214            pub(crate) continuation_token: Option<String>,
215            pub(crate) is_public: Option<bool>,
216        }
217        impl RequestBuilder {
218            #[doc = "The maximum number of results to return on each page."]
219            pub fn page_size(mut self, page_size: i32) -> Self {
220                self.page_size = Some(page_size);
221                self
222            }
223            #[doc = "An opaque data blob that allows the next page of data to resume immediately after where the previous page ended. The only reliable way to know if there is more data left is the presence of a continuation token."]
224            pub fn continuation_token(mut self, continuation_token: impl Into<String>) -> Self {
225                self.continuation_token = Some(continuation_token.into());
226                self
227            }
228            #[doc = "Set to false for PAT tokens and true for SSH tokens."]
229            pub fn is_public(mut self, is_public: bool) -> Self {
230                self.is_public = Some(is_public);
231                self
232            }
233            #[doc = "Returns a future that sends the request and returns a [`Response`] object that provides low-level access to full response details."]
234            #[doc = ""]
235            #[doc = "You should typically use `.await` (which implicitly calls `IntoFuture::into_future()`) to finalize and send requests rather than `send()`."]
236            #[doc = "However, this function can provide more flexibility when required."]
237            pub fn send(self) -> BoxFuture<'static, azure_core::Result<Response>> {
238                Box::pin({
239                    let this = self.clone();
240                    async move {
241                        let url = this.url()?;
242                        let mut req =
243                            azure_core::http::Request::new(url, azure_core::http::Method::Get);
244                        if let Some(auth_header) = this
245                            .client
246                            .token_credential()
247                            .http_authorization_header(&this.client.scopes())
248                            .await?
249                        {
250                            req.insert_header(
251                                azure_core::http::headers::AUTHORIZATION,
252                                auth_header,
253                            );
254                        }
255                        if let Some(page_size) = &this.page_size {
256                            req.url_mut()
257                                .query_pairs_mut()
258                                .append_pair("pageSize", &page_size.to_string());
259                        }
260                        if let Some(continuation_token) = &this.continuation_token {
261                            req.url_mut()
262                                .query_pairs_mut()
263                                .append_pair("continuationToken", continuation_token);
264                        }
265                        if let Some(is_public) = &this.is_public {
266                            req.url_mut()
267                                .query_pairs_mut()
268                                .append_pair("isPublic", &is_public.to_string());
269                        }
270                        let req_body = azure_core::Bytes::new();
271                        req.set_body(req_body);
272                        Ok(Response(this.client.send(&mut req).await?.into()))
273                    }
274                })
275            }
276            fn url(&self) -> azure_core::Result<azure_core::http::Url> {
277                let mut url = azure_core::http::Url::parse(&format!(
278                    "{}/{}/_apis/tokenadmin/personalaccesstokens/{}",
279                    self.client.endpoint(),
280                    &self.organization,
281                    &self.subject_descriptor
282                ))?;
283                let has_api_version_already = url
284                    .query_pairs()
285                    .any(|(k, _)| k == azure_core::http::headers::query_param::API_VERSION);
286                if !has_api_version_already {
287                    url.query_pairs_mut().append_pair(
288                        azure_core::http::headers::query_param::API_VERSION,
289                        "7.1-preview",
290                    );
291                }
292                Ok(url)
293            }
294        }
295        impl std::future::IntoFuture for RequestBuilder {
296            type Output = azure_core::Result<models::TokenAdminPagedSessionTokens>;
297            type IntoFuture =
298                BoxFuture<'static, azure_core::Result<models::TokenAdminPagedSessionTokens>>;
299            #[doc = "Returns a future that sends the request and returns the parsed response body."]
300            #[doc = ""]
301            #[doc = "You should not normally call this method directly, simply invoke `.await` which implicitly calls `IntoFuture::into_future`."]
302            #[doc = ""]
303            #[doc = "See [IntoFuture documentation](https://doc.rust-lang.org/std/future/trait.IntoFuture.html) for more details."]
304            fn into_future(self) -> Self::IntoFuture {
305                Box::pin(async move { self.send().await?.into_body().await })
306            }
307        }
308    }
309}
310pub mod revocation_rules {
311    use super::models;
312    #[cfg(not(target_arch = "wasm32"))]
313    use futures::future::BoxFuture;
314    #[cfg(target_arch = "wasm32")]
315    use futures::future::LocalBoxFuture as BoxFuture;
316    pub struct Client(pub(crate) super::Client);
317    impl Client {
318        #[doc = "Creates a revocation rule to prevent the further usage of any OAuth authorizations that were created before the current point in time and which match the conditions in the rule.\n\nNot all kinds of OAuth authorizations can be revoked directly.\nSome, such as self-describing session tokens, must instead by revoked by creating a rule\nwhich will be evaluated and used to reject matching OAuth credentials at authentication time.\nRevocation rules created through this endpoint will apply to all credentials that were issued\nbefore the datetime at which the rule was created and which match one or more additional conditions."]
319        #[doc = ""]
320        #[doc = "Arguments:"]
321        #[doc = "* `organization`: The name of the Azure DevOps organization."]
322        #[doc = "* `body`: The revocation rule to create. The rule must specify a space-separated list of scopes, after which preexisting OAuth authorizations that match that any of the scopes will be rejected. For a list of all OAuth scopes supported by VSTS, see:<https://docs>.microsoft.com/en-us/vsts/integrate/get-started/authentication/oauth?view=vsts#scopes The rule may also specify the time before which to revoke tokens."]
323        pub fn create(
324            &self,
325            organization: impl Into<String>,
326            body: impl Into<models::TokenAdminRevocationRule>,
327        ) -> create::RequestBuilder {
328            create::RequestBuilder {
329                client: self.0.clone(),
330                organization: organization.into(),
331                body: body.into(),
332            }
333        }
334    }
335    pub mod create {
336        use super::models;
337        #[cfg(not(target_arch = "wasm32"))]
338        use futures::future::BoxFuture;
339        #[cfg(target_arch = "wasm32")]
340        use futures::future::LocalBoxFuture as BoxFuture;
341        #[derive(Debug)]
342        pub struct Response(azure_core::http::Response<(), azure_core::http::NoFormat>);
343        impl Response {
344            pub fn into_raw_response(self) -> azure_core::http::RawResponse {
345                self.0.into()
346            }
347        }
348        #[derive(Clone)]
349        #[doc = r" `RequestBuilder` provides a mechanism for setting optional parameters on a request."]
350        #[doc = r""]
351        #[doc = r" Each `RequestBuilder` parameter method call returns `Self`, so setting of multiple"]
352        #[doc = r" parameters can be chained."]
353        #[doc = r""]
354        #[doc = r" To finalize and submit the request, invoke `.await`, which"]
355        #[doc = r" converts the [`RequestBuilder`] into a future,"]
356        #[doc = r" executes the request and returns a `Result` with the parsed"]
357        #[doc = r" response."]
358        #[doc = r""]
359        #[doc = r" If you need lower-level access to the raw response details"]
360        #[doc = r" (e.g. to inspect response headers or raw body data) then you"]
361        #[doc = r" can finalize the request using the"]
362        #[doc = r" [`RequestBuilder::send()`] method which returns a future"]
363        #[doc = r" that resolves to a lower-level [`Response`] value."]
364        pub struct RequestBuilder {
365            pub(crate) client: super::super::Client,
366            pub(crate) organization: String,
367            pub(crate) body: models::TokenAdminRevocationRule,
368        }
369        impl RequestBuilder {
370            #[doc = "Returns a future that sends the request and returns a [`Response`] object that provides low-level access to full response details."]
371            #[doc = ""]
372            #[doc = "You should typically use `.await` (which implicitly calls `IntoFuture::into_future()`) to finalize and send requests rather than `send()`."]
373            #[doc = "However, this function can provide more flexibility when required."]
374            pub fn send(self) -> BoxFuture<'static, azure_core::Result<Response>> {
375                Box::pin({
376                    let this = self.clone();
377                    async move {
378                        let url = this.url()?;
379                        let mut req =
380                            azure_core::http::Request::new(url, azure_core::http::Method::Post);
381                        if let Some(auth_header) = this
382                            .client
383                            .token_credential()
384                            .http_authorization_header(&this.client.scopes())
385                            .await?
386                        {
387                            req.insert_header(
388                                azure_core::http::headers::AUTHORIZATION,
389                                auth_header,
390                            );
391                        }
392                        req.insert_header("content-type", "application/json");
393                        let req_body = azure_core::json::to_json(&this.body)?;
394                        req.set_body(req_body);
395                        Ok(Response(this.client.send(&mut req).await?.into()))
396                    }
397                })
398            }
399            fn url(&self) -> azure_core::Result<azure_core::http::Url> {
400                let mut url = azure_core::http::Url::parse(&format!(
401                    "{}/{}/_apis/tokenadmin/revocationrules",
402                    self.client.endpoint(),
403                    &self.organization
404                ))?;
405                let has_api_version_already = url
406                    .query_pairs()
407                    .any(|(k, _)| k == azure_core::http::headers::query_param::API_VERSION);
408                if !has_api_version_already {
409                    url.query_pairs_mut().append_pair(
410                        azure_core::http::headers::query_param::API_VERSION,
411                        "7.1-preview",
412                    );
413                }
414                Ok(url)
415            }
416        }
417        impl std::future::IntoFuture for RequestBuilder {
418            type Output = azure_core::Result<()>;
419            type IntoFuture = BoxFuture<'static, azure_core::Result<()>>;
420            #[doc = "Returns a future that sends the request and waits for the response."]
421            #[doc = ""]
422            #[doc = "You should not normally call this method directly, simply invoke `.await` which implicitly calls `IntoFuture::into_future`."]
423            #[doc = ""]
424            #[doc = "See [IntoFuture documentation](https://doc.rust-lang.org/std/future/trait.IntoFuture.html) for more details."]
425            fn into_future(self) -> Self::IntoFuture {
426                Box::pin(async move {
427                    let _rsp = self.send().await?;
428                    Ok(())
429                })
430            }
431        }
432    }
433}
434pub mod revocations {
435    use super::models;
436    #[cfg(not(target_arch = "wasm32"))]
437    use futures::future::BoxFuture;
438    #[cfg(target_arch = "wasm32")]
439    use futures::future::LocalBoxFuture as BoxFuture;
440    pub struct Client(pub(crate) super::Client);
441    impl Client {
442        #[doc = "Revokes the listed OAuth authorizations."]
443        #[doc = ""]
444        #[doc = "Arguments:"]
445        #[doc = "* `organization`: The name of the Azure DevOps organization."]
446        #[doc = "* `body`: The list of objects containing the authorization IDs of the OAuth authorizations, such as session tokens retrieved by listed a users PATs, that should be revoked."]
447        pub fn revoke_authorizations(
448            &self,
449            organization: impl Into<String>,
450            body: Vec<models::TokenAdminRevocation>,
451        ) -> revoke_authorizations::RequestBuilder {
452            revoke_authorizations::RequestBuilder {
453                client: self.0.clone(),
454                organization: organization.into(),
455                body,
456                is_public: None,
457            }
458        }
459    }
460    pub mod revoke_authorizations {
461        use super::models;
462        #[cfg(not(target_arch = "wasm32"))]
463        use futures::future::BoxFuture;
464        #[cfg(target_arch = "wasm32")]
465        use futures::future::LocalBoxFuture as BoxFuture;
466        #[derive(Debug)]
467        pub struct Response(azure_core::http::Response<(), azure_core::http::NoFormat>);
468        impl Response {
469            pub fn into_raw_response(self) -> azure_core::http::RawResponse {
470                self.0.into()
471            }
472        }
473        #[derive(Clone)]
474        #[doc = r" `RequestBuilder` provides a mechanism for setting optional parameters on a request."]
475        #[doc = r""]
476        #[doc = r" Each `RequestBuilder` parameter method call returns `Self`, so setting of multiple"]
477        #[doc = r" parameters can be chained."]
478        #[doc = r""]
479        #[doc = r" To finalize and submit the request, invoke `.await`, which"]
480        #[doc = r" converts the [`RequestBuilder`] into a future,"]
481        #[doc = r" executes the request and returns a `Result` with the parsed"]
482        #[doc = r" response."]
483        #[doc = r""]
484        #[doc = r" If you need lower-level access to the raw response details"]
485        #[doc = r" (e.g. to inspect response headers or raw body data) then you"]
486        #[doc = r" can finalize the request using the"]
487        #[doc = r" [`RequestBuilder::send()`] method which returns a future"]
488        #[doc = r" that resolves to a lower-level [`Response`] value."]
489        pub struct RequestBuilder {
490            pub(crate) client: super::super::Client,
491            pub(crate) organization: String,
492            pub(crate) body: Vec<models::TokenAdminRevocation>,
493            pub(crate) is_public: Option<bool>,
494        }
495        impl RequestBuilder {
496            #[doc = "Set to false for PAT tokens and true for SSH tokens."]
497            pub fn is_public(mut self, is_public: bool) -> Self {
498                self.is_public = Some(is_public);
499                self
500            }
501            #[doc = "Returns a future that sends the request and returns a [`Response`] object that provides low-level access to full response details."]
502            #[doc = ""]
503            #[doc = "You should typically use `.await` (which implicitly calls `IntoFuture::into_future()`) to finalize and send requests rather than `send()`."]
504            #[doc = "However, this function can provide more flexibility when required."]
505            pub fn send(self) -> BoxFuture<'static, azure_core::Result<Response>> {
506                Box::pin({
507                    let this = self.clone();
508                    async move {
509                        let url = this.url()?;
510                        let mut req =
511                            azure_core::http::Request::new(url, azure_core::http::Method::Post);
512                        if let Some(auth_header) = this
513                            .client
514                            .token_credential()
515                            .http_authorization_header(&this.client.scopes())
516                            .await?
517                        {
518                            req.insert_header(
519                                azure_core::http::headers::AUTHORIZATION,
520                                auth_header,
521                            );
522                        }
523                        req.insert_header("content-type", "application/json");
524                        let req_body = azure_core::json::to_json(&this.body)?;
525                        if let Some(is_public) = &this.is_public {
526                            req.url_mut()
527                                .query_pairs_mut()
528                                .append_pair("isPublic", &is_public.to_string());
529                        }
530                        req.set_body(req_body);
531                        Ok(Response(this.client.send(&mut req).await?.into()))
532                    }
533                })
534            }
535            fn url(&self) -> azure_core::Result<azure_core::http::Url> {
536                let mut url = azure_core::http::Url::parse(&format!(
537                    "{}/{}/_apis/tokenadmin/revocations",
538                    self.client.endpoint(),
539                    &self.organization
540                ))?;
541                let has_api_version_already = url
542                    .query_pairs()
543                    .any(|(k, _)| k == azure_core::http::headers::query_param::API_VERSION);
544                if !has_api_version_already {
545                    url.query_pairs_mut().append_pair(
546                        azure_core::http::headers::query_param::API_VERSION,
547                        "7.1-preview",
548                    );
549                }
550                Ok(url)
551            }
552        }
553        impl std::future::IntoFuture for RequestBuilder {
554            type Output = azure_core::Result<()>;
555            type IntoFuture = BoxFuture<'static, azure_core::Result<()>>;
556            #[doc = "Returns a future that sends the request and waits for the response."]
557            #[doc = ""]
558            #[doc = "You should not normally call this method directly, simply invoke `.await` which implicitly calls `IntoFuture::into_future`."]
559            #[doc = ""]
560            #[doc = "See [IntoFuture documentation](https://doc.rust-lang.org/std/future/trait.IntoFuture.html) for more details."]
561            fn into_future(self) -> Self::IntoFuture {
562                Box::pin(async move {
563                    let _rsp = self.send().await?;
564                    Ok(())
565                })
566            }
567        }
568    }
569}