Skip to content

Latest commit

 

History

History
 
 

azure_devops_rust_api

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Azure DevOps Rust API

Overview

azure_devops_rust_api implements a Rust interface to the Azure DevOps REST API (version 7.1).

The crate is autogenerated from the Azure DevOps OpenAPI spec.

Usage

Usage overview

The crate has many features/modules, but the general approach is similar for all:

  • Obtain an authentication credential
  • Create a client for the feature/module that you want to use
  • Use the client to make operation requests

Code example

Example usage (from examples/git_repo_list.rs):

    // Get authentication credential either from a PAT ("ADO_TOKEN")
    // or via the az cli.
    let credential = match env::var("ADO_TOKEN") {
        Ok(token) => {
            println!("Authenticate using PAT provided via $ADO_TOKEN");
            Credential::from_pat(token)
        }
        Err(_) => {
            println!("Authenticate using Azure CLI");
            Credential::from_token_credential(
                Arc::new(azure_identity::AzureCliCredential::new())
            )
        }
    };

    // Get ADO configuration via environment variables
    let organization = env::var("ADO_ORGANIZATION")
        .expect("Must define ADO_ORGANIZATION");
    let project = env::var("ADO_PROJECT")
        .expect("Must define ADO_PROJECT");

    // Create a git client
    let git_client = git::ClientBuilder::new(credential).build();

    // Get all repositories in the specified organization/project
    let repos = git_client
        .repositories_client()
        .list(organization, project)
        .into_future()
        .await?
        .value;

    // Output repo names
    for repo in repos.iter() {
        println!("{}", repo.name);
    }
    println!("{} repos found", repos.len());

Individual components in the API are enabled via Rust features.

See the features section of Cargo.toml for the full list of features.

Example application Cargo.toml dependency spec showing how to specify desired features:

[dependencies]
...
azure_devops_rust_api = { version = "0.5.0", features = ["git", "pipelines"] }

Examples

See examples directory.

Define environment variables:

export ADO_ORGANIZATION=<organization-name>
export ADO_PROJECT=<project-name>

To run the examples you need to provide authentication credentials either via:

  • A Personal Access Token (PAT), provided via the environment variable ADO_TOKEN
  • The az CLI, where you just need to have authenticated by running az login before running the examples.

Run the example via cargo run --example. You will need to enable the features required by the example. If you don't specify the necessary features you do get a helpful error message.

Example:

cargo run --example git_repo_get --features="git" <repo-name>

Issue reporting

This crate is in early development and only a subset of function has been tested, so there will be issues and breaking changes.

If you find any issues then please raise them via Github.

Useful links