[][src]Crate gsuite_api

A rust library for interacting with the GSuite APIs.

For more information, the GSuite Directory API is documented at developers.google.com/admin-sdk/directory/v1/reference and the Google Groups settings API is documented at developers.google.com/admin-sdk/groups-settings/v1/reference/groups.

Example:

use std::env;

use gsuite_api::GSuite;
use yup_oauth2::{read_service_account_key, ServiceAccountAuthenticator};

async fn get_users() {
    // Get the GSuite credentials file.
    let gsuite_credential_file =
        env::var("GADMIN_CREDENTIAL_FILE").unwrap();
    let gsuite_subject = env::var("GADMIN_SUBJECT").unwrap();
    let gsuite_secret = read_service_account_key(gsuite_credential_file)
        .await
        .expect("failed to read gsuite credential file");
    let auth = ServiceAccountAuthenticator::builder(gsuite_secret)
        .subject(gsuite_subject.to_string())
        .build()
        .await
        .expect("failed to create authenticator");

    // Add the scopes to the secret and get the token.
    let token = auth.token(&[
     "https://www.googleapis.com/auth/admin.directory.group",
     "https://www.googleapis.com/auth/admin.directory.resource.calendar",
     "https://www.googleapis.com/auth/admin.directory.user",
     "https://www.googleapis.com/auth/apps.groups.settings",
 ]).await.expect("failed to get token");

    if token.as_str().is_empty() {
        panic!("empty token is not valid");
    }

    // Initialize the GSuite client.
    let gsuite_client = GSuite::new("customer_id", "domain", token);

    // List users.
    let users = gsuite_client.list_users().await;

    // Iterate over the users.
    for user in users {
        println!("{:?}", user);
    }
}

Structs

Building

A building.

BuildingAddress

A building's address.

BuildingCoordinates

A building's coordinates.

CalendarFeature

A feature of a calendar.

CalendarFeatures

A calendar's features.

CalendarResource

A calendar resource.

GSuite

Entrypoint for interacting with the GSuite APIs.

Group

A Google group.

GroupSettings

A Google group's settings.

User

A user.

UserCustomProperties

Custom properties for a user.

UserEmail

A user's email.

UserGender

A user's gender.

UserLocation

A user's location.

UserName

A user's name.

UserPhone

A user's phone.

UserSSHKey

A user's ssh key.

Functions

generate_password

Generate a random string that we can use as a temporary password for new users when we set up their account.