azure_devops_rust_api/token_admin/
mod.rs1#![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 = 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::Transport>) -> 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, None).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 None,
125 );
126 Self {
127 endpoint,
128 credential,
129 scopes,
130 pipeline,
131 }
132 }
133 pub fn personal_access_tokens_client(&self) -> personal_access_tokens::Client {
134 personal_access_tokens::Client(self.clone())
135 }
136 pub fn revocation_rules_client(&self) -> revocation_rules::Client {
137 revocation_rules::Client(self.clone())
138 }
139 pub fn revocations_client(&self) -> revocations::Client {
140 revocations::Client(self.clone())
141 }
142}
143pub mod personal_access_tokens {
144 use super::models;
145 #[cfg(not(target_arch = "wasm32"))]
146 use futures::future::BoxFuture;
147 #[cfg(target_arch = "wasm32")]
148 use futures::future::LocalBoxFuture as BoxFuture;
149 pub struct Client(pub(crate) super::Client);
150 impl Client {
151 #[doc = "Lists of all the session token details of the personal access tokens (PATs) for a particular user."]
152 #[doc = ""]
153 #[doc = "Arguments:"]
154 #[doc = "* `organization`: The name of the Azure DevOps organization."]
155 #[doc = "* `subject_descriptor`: The descriptor of the target user."]
156 pub fn list(
157 &self,
158 organization: impl Into<String>,
159 subject_descriptor: impl Into<String>,
160 ) -> list::RequestBuilder {
161 list::RequestBuilder {
162 client: self.0.clone(),
163 organization: organization.into(),
164 subject_descriptor: subject_descriptor.into(),
165 page_size: None,
166 continuation_token: None,
167 is_public: None,
168 }
169 }
170 }
171 pub mod list {
172 use super::models;
173 #[cfg(not(target_arch = "wasm32"))]
174 use futures::future::BoxFuture;
175 #[cfg(target_arch = "wasm32")]
176 use futures::future::LocalBoxFuture as BoxFuture;
177 #[derive(Debug)]
178 pub struct Response(
179 azure_core::http::Response<
180 models::TokenAdminPagedSessionTokens,
181 azure_core::http::JsonFormat,
182 >,
183 );
184 impl Response {
185 pub fn into_body(self) -> azure_core::Result<models::TokenAdminPagedSessionTokens> {
186 self.0.into_model()
187 }
188 pub fn into_raw_response(self) -> azure_core::http::RawResponse {
189 self.0.into()
190 }
191 }
192 #[derive(Clone)]
193 #[doc = r" `RequestBuilder` provides a mechanism for setting optional parameters on a request."]
194 #[doc = r""]
195 #[doc = r" Each `RequestBuilder` parameter method call returns `Self`, so setting of multiple"]
196 #[doc = r" parameters can be chained."]
197 #[doc = r""]
198 #[doc = r" To finalize and submit the request, invoke `.await`, which"]
199 #[doc = r" converts the [`RequestBuilder`] into a future,"]
200 #[doc = r" executes the request and returns a `Result` with the parsed"]
201 #[doc = r" response."]
202 #[doc = r""]
203 #[doc = r" If you need lower-level access to the raw response details"]
204 #[doc = r" (e.g. to inspect response headers or raw body data) then you"]
205 #[doc = r" can finalize the request using the"]
206 #[doc = r" [`RequestBuilder::send()`] method which returns a future"]
207 #[doc = r" that resolves to a lower-level [`Response`] value."]
208 pub struct RequestBuilder {
209 pub(crate) client: super::super::Client,
210 pub(crate) organization: String,
211 pub(crate) subject_descriptor: String,
212 pub(crate) page_size: Option<i32>,
213 pub(crate) continuation_token: Option<String>,
214 pub(crate) is_public: Option<bool>,
215 }
216 impl RequestBuilder {
217 #[doc = "The maximum number of results to return on each page."]
218 pub fn page_size(mut self, page_size: i32) -> Self {
219 self.page_size = Some(page_size);
220 self
221 }
222 #[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."]
223 pub fn continuation_token(mut self, continuation_token: impl Into<String>) -> Self {
224 self.continuation_token = Some(continuation_token.into());
225 self
226 }
227 #[doc = "Set to false for PAT tokens and true for SSH tokens."]
228 pub fn is_public(mut self, is_public: bool) -> Self {
229 self.is_public = Some(is_public);
230 self
231 }
232 #[doc = "Returns a future that sends the request and returns a [`Response`] object that provides low-level access to full response details."]
233 #[doc = ""]
234 #[doc = "You should typically use `.await` (which implicitly calls `IntoFuture::into_future()`) to finalize and send requests rather than `send()`."]
235 #[doc = "However, this function can provide more flexibility when required."]
236 pub fn send(self) -> BoxFuture<'static, azure_core::Result<Response>> {
237 Box::pin({
238 let this = self.clone();
239 async move {
240 let url = this.url()?;
241 let mut req =
242 azure_core::http::Request::new(url, azure_core::http::Method::Get);
243 if let Some(auth_header) = this
244 .client
245 .token_credential()
246 .http_authorization_header(&this.client.scopes())
247 .await?
248 {
249 req.insert_header(
250 azure_core::http::headers::AUTHORIZATION,
251 auth_header,
252 );
253 }
254 if let Some(page_size) = &this.page_size {
255 req.url_mut()
256 .query_pairs_mut()
257 .append_pair("pageSize", &page_size.to_string());
258 }
259 if let Some(continuation_token) = &this.continuation_token {
260 req.url_mut()
261 .query_pairs_mut()
262 .append_pair("continuationToken", continuation_token);
263 }
264 if let Some(is_public) = &this.is_public {
265 req.url_mut()
266 .query_pairs_mut()
267 .append_pair("isPublic", &is_public.to_string());
268 }
269 let req_body = azure_core::Bytes::new();
270 req.set_body(req_body);
271 Ok(Response(this.client.send(&mut req).await?.into()))
272 }
273 })
274 }
275 fn url(&self) -> azure_core::Result<azure_core::http::Url> {
276 let mut url = azure_core::http::Url::parse(&format!(
277 "{}/{}/_apis/tokenadmin/personalaccesstokens/{}",
278 self.client.endpoint(),
279 &self.organization,
280 &self.subject_descriptor
281 ))?;
282 let has_api_version_already = url.query_pairs().any(|(k, _)| k == "api-version");
283 if !has_api_version_already {
284 url.query_pairs_mut()
285 .append_pair("api-version", "7.1-preview");
286 }
287 Ok(url)
288 }
289 }
290 impl std::future::IntoFuture for RequestBuilder {
291 type Output = azure_core::Result<models::TokenAdminPagedSessionTokens>;
292 type IntoFuture =
293 BoxFuture<'static, azure_core::Result<models::TokenAdminPagedSessionTokens>>;
294 #[doc = "Returns a future that sends the request and returns the parsed response body."]
295 #[doc = ""]
296 #[doc = "You should not normally call this method directly, simply invoke `.await` which implicitly calls `IntoFuture::into_future`."]
297 #[doc = ""]
298 #[doc = "See [IntoFuture documentation](https://doc.rust-lang.org/std/future/trait.IntoFuture.html) for more details."]
299 fn into_future(self) -> Self::IntoFuture {
300 Box::pin(async move { self.send().await?.into_body() })
301 }
302 }
303 }
304}
305pub mod revocation_rules {
306 use super::models;
307 #[cfg(not(target_arch = "wasm32"))]
308 use futures::future::BoxFuture;
309 #[cfg(target_arch = "wasm32")]
310 use futures::future::LocalBoxFuture as BoxFuture;
311 pub struct Client(pub(crate) super::Client);
312 impl Client {
313 #[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."]
314 #[doc = ""]
315 #[doc = "Arguments:"]
316 #[doc = "* `organization`: The name of the Azure DevOps organization."]
317 #[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."]
318 pub fn create(
319 &self,
320 organization: impl Into<String>,
321 body: impl Into<models::TokenAdminRevocationRule>,
322 ) -> create::RequestBuilder {
323 create::RequestBuilder {
324 client: self.0.clone(),
325 organization: organization.into(),
326 body: body.into(),
327 }
328 }
329 }
330 pub mod create {
331 use super::models;
332 #[cfg(not(target_arch = "wasm32"))]
333 use futures::future::BoxFuture;
334 #[cfg(target_arch = "wasm32")]
335 use futures::future::LocalBoxFuture as BoxFuture;
336 #[derive(Debug)]
337 pub struct Response(azure_core::http::Response<(), azure_core::http::NoFormat>);
338 impl Response {
339 pub fn into_raw_response(self) -> azure_core::http::RawResponse {
340 self.0.into()
341 }
342 }
343 #[derive(Clone)]
344 #[doc = r" `RequestBuilder` provides a mechanism for setting optional parameters on a request."]
345 #[doc = r""]
346 #[doc = r" Each `RequestBuilder` parameter method call returns `Self`, so setting of multiple"]
347 #[doc = r" parameters can be chained."]
348 #[doc = r""]
349 #[doc = r" To finalize and submit the request, invoke `.await`, which"]
350 #[doc = r" converts the [`RequestBuilder`] into a future,"]
351 #[doc = r" executes the request and returns a `Result` with the parsed"]
352 #[doc = r" response."]
353 #[doc = r""]
354 #[doc = r" If you need lower-level access to the raw response details"]
355 #[doc = r" (e.g. to inspect response headers or raw body data) then you"]
356 #[doc = r" can finalize the request using the"]
357 #[doc = r" [`RequestBuilder::send()`] method which returns a future"]
358 #[doc = r" that resolves to a lower-level [`Response`] value."]
359 pub struct RequestBuilder {
360 pub(crate) client: super::super::Client,
361 pub(crate) organization: String,
362 pub(crate) body: models::TokenAdminRevocationRule,
363 }
364 impl RequestBuilder {
365 #[doc = "Returns a future that sends the request and returns a [`Response`] object that provides low-level access to full response details."]
366 #[doc = ""]
367 #[doc = "You should typically use `.await` (which implicitly calls `IntoFuture::into_future()`) to finalize and send requests rather than `send()`."]
368 #[doc = "However, this function can provide more flexibility when required."]
369 pub fn send(self) -> BoxFuture<'static, azure_core::Result<Response>> {
370 Box::pin({
371 let this = self.clone();
372 async move {
373 let url = this.url()?;
374 let mut req =
375 azure_core::http::Request::new(url, azure_core::http::Method::Post);
376 if let Some(auth_header) = this
377 .client
378 .token_credential()
379 .http_authorization_header(&this.client.scopes())
380 .await?
381 {
382 req.insert_header(
383 azure_core::http::headers::AUTHORIZATION,
384 auth_header,
385 );
386 }
387 req.insert_header("content-type", "application/json");
388 let req_body = azure_core::json::to_json(&this.body)?;
389 req.set_body(req_body);
390 Ok(Response(this.client.send(&mut req).await?.into()))
391 }
392 })
393 }
394 fn url(&self) -> azure_core::Result<azure_core::http::Url> {
395 let mut url = azure_core::http::Url::parse(&format!(
396 "{}/{}/_apis/tokenadmin/revocationrules",
397 self.client.endpoint(),
398 &self.organization
399 ))?;
400 let has_api_version_already = url.query_pairs().any(|(k, _)| k == "api-version");
401 if !has_api_version_already {
402 url.query_pairs_mut()
403 .append_pair("api-version", "7.1-preview");
404 }
405 Ok(url)
406 }
407 }
408 impl std::future::IntoFuture for RequestBuilder {
409 type Output = azure_core::Result<()>;
410 type IntoFuture = BoxFuture<'static, azure_core::Result<()>>;
411 #[doc = "Returns a future that sends the request and waits for the response."]
412 #[doc = ""]
413 #[doc = "You should not normally call this method directly, simply invoke `.await` which implicitly calls `IntoFuture::into_future`."]
414 #[doc = ""]
415 #[doc = "See [IntoFuture documentation](https://doc.rust-lang.org/std/future/trait.IntoFuture.html) for more details."]
416 fn into_future(self) -> Self::IntoFuture {
417 Box::pin(async move {
418 let _rsp = self.send().await?;
419 Ok(())
420 })
421 }
422 }
423 }
424}
425pub mod revocations {
426 use super::models;
427 #[cfg(not(target_arch = "wasm32"))]
428 use futures::future::BoxFuture;
429 #[cfg(target_arch = "wasm32")]
430 use futures::future::LocalBoxFuture as BoxFuture;
431 pub struct Client(pub(crate) super::Client);
432 impl Client {
433 #[doc = "Revokes the listed OAuth authorizations."]
434 #[doc = ""]
435 #[doc = "Arguments:"]
436 #[doc = "* `organization`: The name of the Azure DevOps organization."]
437 #[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."]
438 pub fn revoke_authorizations(
439 &self,
440 organization: impl Into<String>,
441 body: Vec<models::TokenAdminRevocation>,
442 ) -> revoke_authorizations::RequestBuilder {
443 revoke_authorizations::RequestBuilder {
444 client: self.0.clone(),
445 organization: organization.into(),
446 body,
447 is_public: None,
448 }
449 }
450 }
451 pub mod revoke_authorizations {
452 use super::models;
453 #[cfg(not(target_arch = "wasm32"))]
454 use futures::future::BoxFuture;
455 #[cfg(target_arch = "wasm32")]
456 use futures::future::LocalBoxFuture as BoxFuture;
457 #[derive(Debug)]
458 pub struct Response(azure_core::http::Response<(), azure_core::http::NoFormat>);
459 impl Response {
460 pub fn into_raw_response(self) -> azure_core::http::RawResponse {
461 self.0.into()
462 }
463 }
464 #[derive(Clone)]
465 #[doc = r" `RequestBuilder` provides a mechanism for setting optional parameters on a request."]
466 #[doc = r""]
467 #[doc = r" Each `RequestBuilder` parameter method call returns `Self`, so setting of multiple"]
468 #[doc = r" parameters can be chained."]
469 #[doc = r""]
470 #[doc = r" To finalize and submit the request, invoke `.await`, which"]
471 #[doc = r" converts the [`RequestBuilder`] into a future,"]
472 #[doc = r" executes the request and returns a `Result` with the parsed"]
473 #[doc = r" response."]
474 #[doc = r""]
475 #[doc = r" If you need lower-level access to the raw response details"]
476 #[doc = r" (e.g. to inspect response headers or raw body data) then you"]
477 #[doc = r" can finalize the request using the"]
478 #[doc = r" [`RequestBuilder::send()`] method which returns a future"]
479 #[doc = r" that resolves to a lower-level [`Response`] value."]
480 pub struct RequestBuilder {
481 pub(crate) client: super::super::Client,
482 pub(crate) organization: String,
483 pub(crate) body: Vec<models::TokenAdminRevocation>,
484 pub(crate) is_public: Option<bool>,
485 }
486 impl RequestBuilder {
487 #[doc = "Set to false for PAT tokens and true for SSH tokens."]
488 pub fn is_public(mut self, is_public: bool) -> Self {
489 self.is_public = Some(is_public);
490 self
491 }
492 #[doc = "Returns a future that sends the request and returns a [`Response`] object that provides low-level access to full response details."]
493 #[doc = ""]
494 #[doc = "You should typically use `.await` (which implicitly calls `IntoFuture::into_future()`) to finalize and send requests rather than `send()`."]
495 #[doc = "However, this function can provide more flexibility when required."]
496 pub fn send(self) -> BoxFuture<'static, azure_core::Result<Response>> {
497 Box::pin({
498 let this = self.clone();
499 async move {
500 let url = this.url()?;
501 let mut req =
502 azure_core::http::Request::new(url, azure_core::http::Method::Post);
503 if let Some(auth_header) = this
504 .client
505 .token_credential()
506 .http_authorization_header(&this.client.scopes())
507 .await?
508 {
509 req.insert_header(
510 azure_core::http::headers::AUTHORIZATION,
511 auth_header,
512 );
513 }
514 req.insert_header("content-type", "application/json");
515 let req_body = azure_core::json::to_json(&this.body)?;
516 if let Some(is_public) = &this.is_public {
517 req.url_mut()
518 .query_pairs_mut()
519 .append_pair("isPublic", &is_public.to_string());
520 }
521 req.set_body(req_body);
522 Ok(Response(this.client.send(&mut req).await?.into()))
523 }
524 })
525 }
526 fn url(&self) -> azure_core::Result<azure_core::http::Url> {
527 let mut url = azure_core::http::Url::parse(&format!(
528 "{}/{}/_apis/tokenadmin/revocations",
529 self.client.endpoint(),
530 &self.organization
531 ))?;
532 let has_api_version_already = url.query_pairs().any(|(k, _)| k == "api-version");
533 if !has_api_version_already {
534 url.query_pairs_mut()
535 .append_pair("api-version", "7.1-preview");
536 }
537 Ok(url)
538 }
539 }
540 impl std::future::IntoFuture for RequestBuilder {
541 type Output = azure_core::Result<()>;
542 type IntoFuture = BoxFuture<'static, azure_core::Result<()>>;
543 #[doc = "Returns a future that sends the request and waits for the response."]
544 #[doc = ""]
545 #[doc = "You should not normally call this method directly, simply invoke `.await` which implicitly calls `IntoFuture::into_future`."]
546 #[doc = ""]
547 #[doc = "See [IntoFuture documentation](https://doc.rust-lang.org/std/future/trait.IntoFuture.html) for more details."]
548 fn into_future(self) -> Self::IntoFuture {
549 Box::pin(async move {
550 let _rsp = self.send().await?;
551 Ok(())
552 })
553 }
554 }
555 }
556}