pub struct PatTokenManager {
    pub ad_token: AzureADToken,
    pub client: Client,
}
Expand description

PatTokenManager is a struct that manages the creation, listing, getting and deletion of PAT tokens. It uses the Azure AD token to authenticate with Azure DevOps.

Example

use pattrick::PatTokenManager;
use pattrick::azure::get_ad_token_for_devops;
use reqwest::Client;

let pat_manager = PatTokenManager {
    ad_token: get_ad_token_for_devops(1).await?,
    client: Client::new(),
};

Fields§

§ad_token: AzureADToken

Azure AD token used to authenticate with Azure DevOps

§client: Client

Reqwest client used to make requests

Implementations§

source§

impl PatTokenManager

source

pub async fn create_pat_token( &self, create_request: PatTokenCreateRequest ) -> Result<PatToken, Box<dyn Error>>

Create a new PAT token

Example
use pattrick::{PatTokenManager, PatTokenCreateRequest};
use pattrick_clap::Scope;
use pattrick::azure::get_ad_token_for_devops;
use chrono::{Utc, Duration};

let pat_manager = PatTokenManager::new(get_ad_token_for_devops(1).await?);

let pat_token = pat_manager.create_pat_token(
   PatTokenCreateRequest {
     all_orgs: false,
     display_name: String::from("awesome-pat"),
     scope: vec![Scope::Build],
     valid_to: (Utc::now() + Duration::seconds(30)),
 }
).await?;
source§

impl PatTokenManager

source

pub async fn delete_pat_token( &self, delete_request: PatTokenDeleteRequest ) -> Result<StatusCode, Box<dyn Error>>

Delete a PAT token

Example
use pattrick::{PatTokenManager, PatTokenDeleteRequest};
use pattrick::azure::get_ad_token_for_devops;

let pat_manager = PatTokenManager::new(get_ad_token_for_devops(1).await?);

pat_manager.delete_pat_token(
   PatTokenDeleteRequest {
    authorization_id: String::from("12345678-1234-1234-1234-123456789012")
 }
).await?;
source§

impl PatTokenManager

source

pub async fn get_pat_token( &self, get_request: PatTokenGetRequest ) -> Result<PatToken, Box<dyn Error>>

Get a PAT token

Example
use pattrick::{PatTokenManager, PatTokenGetRequest};
use pattrick::azure::get_ad_token_for_devops;

let pat_manager = PatTokenManager::new(get_ad_token_for_devops(1).await?);

let pat_token = pat_manager.get_pat_token(
   PatTokenGetRequest {
      authorization_id: String::from("12345678-1234-1234-1234-123456789012")
  }
).await?;
source

pub async fn get_pat_token_by_name( &self, name: &str ) -> Result<Option<PatToken>, Box<dyn Error>>

Get a PAT token by name

Example
use pattrick::PatTokenManager;
use pattrick::azure::get_ad_token_for_devops;

let pat_manager = PatTokenManager::new(get_ad_token_for_devops(1).await?);

let pat_token = pat_manager.get_pat_token_by_name("awesome-pat").await?;
source§

impl PatTokenManager

source

pub async fn list_pat_tokens( &self, list_request: PatTokenListRequest ) -> Result<Vec<PatToken>, Box<dyn Error>>

List PAT tokens

Example
use pattrick::{PatTokenManager, PatTokenListRequest, DisplayFilterOption};
use pattrick::azure::get_ad_token_for_devops;

let pat_manager = PatTokenManager::new(get_ad_token_for_devops(1).await?);

let pat_tokens = pat_manager.list_pat_tokens(
    PatTokenListRequest {
        display_filter_option: DisplayFilterOption::All
    }
).await?;
source§

impl PatTokenManager

source

pub fn new(ad_token: AzureADToken) -> Self

Create a new PatTokenManager

Example
use pattrick::PatTokenManager;
use pattrick::azure::get_ad_token_for_devops;

let pat_manager = PatTokenManager::new(get_ad_token_for_devops(1).await?);
source

pub async fn get_latest_version(self) -> Result<String, Box<dyn Error>>

Get the lastest released version of the Pattrick CLI from GitHub

Example
use pattrick::PatTokenManager;
use pattrick::azure::get_ad_token_for_devops;

let pat_manager = PatTokenManager::new(get_ad_token_for_devops(1).await?);

let latest_version = pat_manager.get_latest_version().await?;

println!("Latest version: {}", latest_version);

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more