Crate lib_vminfo

source ·
Expand description

A small library designed to make querying detailed VM information from Azure Resource Graph as simple and painless as possible

§Installation

To install and use this library, simply add it to your [dependencies] in your Cargo.toml

§Getting Started

The first thing to setup is your App Registration which will be used either as a client directly or through user-impersonation from an AAD user.

§Create the App Registration

Create an App Registration with a name of your choosing and ensure that the Enterprise App is able to read all on the tenant.

then ensure the following API permissions are set:

  • Azure Service Management > user_impersonation
  • Migrosoft Graph > User.Read

Then make sure an admin provides consent for the Directory which contains your AAD users. Also make sure that any users that should be able to impersonate the Enterprise App are added as owners in the App Registration

Under the Authentication section, add a redirect URI: https://global.consent.azure-apim.net/redirect then ensure that you check the boxes to allow Access tokens to be issued by the authroization endpoint

Finally, under Advanced settings in the Authentication section, switch Allow public client flows to “Yes”.

§Decide on an Authentication Method

  • Client Credentials (uses the Service Account (Enterprise App) directly)
  • User Impersonation (uses a user account to impersonate the Service Account (Enterprise App))

§Client Credentials

Create a Secret in the Certificates and Secrets section of the App Registration. Record the Secret value as well as tenant ID and Client(app) ID for later.

§User Impersonation

Record the Tenant ID and Client(app) ID for the App Registration from the Overview Section for later.

[dependencies]
lib_vminfo = { version = "1.0", path = "./lib_vminfo" }

§Basic Usage

Below is basic usage of the VMInfo Client to grab VMs matching a regular expression and caching credentials locally in a file.


// get the first 100 VMs that match the provided regexp
let resp: QueryResponse = client.query_vminfo(
	vec!["ubuntu-vm[0-9]+"],
	true,
	false,
	Some(0),
	Some(100),
)?;

...

§Maintainer(s)

  • Ben Sykes (ben.sykes@statcan.gc.ca)

Modules§

  • defines authentication behaviour and data types for handling Azure authentication
  • defines data structures for caching API responses for various requests
  • defines error and result types used in the client library
  • defines types for handling persistence of authentication details (tokens / client credentials)
  • Query Request and Response types
  • Virtual Machine Response Types

Structs§

  • Defines AuthTokens as a pair of access and refresh tokens
  • Defines the vminfo Client (with caching)

Type Aliases§

  • defines a Client which uses local disk storage to persist credential/token data for vminfo