#env-var #devops #azure

azure_devops_rust_api

Rust API library for Azure DevOps

45 releases (20 breaking)

0.21.0 May 6, 2024
0.19.2 Apr 15, 2024
0.19.1 Mar 25, 2024
0.15.1 Dec 16, 2023
0.1.3 Jul 29, 2022

#103 in Network programming

Download history 9/week @ 2024-01-25 72/week @ 2024-02-01 24/week @ 2024-02-08 182/week @ 2024-02-15 332/week @ 2024-02-22 133/week @ 2024-02-29 205/week @ 2024-03-07 1041/week @ 2024-03-14 1813/week @ 2024-03-21 1305/week @ 2024-03-28 1070/week @ 2024-04-04 1264/week @ 2024-04-11 1193/week @ 2024-04-18 1520/week @ 2024-04-25 1287/week @ 2024-05-02 993/week @ 2024-05-09

5,178 downloads per month

MIT license

11MB
253K SLoC

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.

The crate contains 38 modules

Usage

Usage overview

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

  • Obtain an authentication credential
    • See examples for how to do this using the azure_identity crate
  • Create a client for the feature/module that you want to use
    • Normally you need to create a client for the top-level module that you want to use, (e.g. git_client), and then one for the submodule (e.g. repositories_client).
  • Use the client to make operation requests
    • Each operation has zero or more mandatory parameters and zero or more optional parameters. Mandatory parameters are passed as parameters on the operation request method. Optional parameters may be provided by calling methods on the "builder" object returned by the operation request method. The builder object is finalized by invoking await, which transforms the builder into a Future (via the IntoFuture trait) and awaits the response.

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 = utils::get_credential()

    // 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)
        .await?
        .value;

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

Individual modules 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.21.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:

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

    Note: A personal access token contains your security credentials for Azure DevOps. A PAT identifies you, your accessible organizations, and scopes of access. As such, they're as critical as passwords, so you should treat them the same way. When creating a PAT only grant it the minimum required scopes, and set the expiry time to be short.

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

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

Dependencies

~7–23MB
~328K SLoC