An open API service indexing awesome lists of open source software.

https://github.com/nceas/nceas-gsuite-tool

Example tool for managing GSuite accounts via API
https://github.com/nceas/nceas-gsuite-tool

Last synced: 3 months ago
JSON representation

Example tool for managing GSuite accounts via API

Awesome Lists containing this project

README

        

# NCEAS GSuite Tool

Simple example script showing how to use the Google GSuite AdminAPI for
managing users and groups. The current tool performs simple operations:

- list users in domain
- `./ngt --list`
- list groups for a user
- `./ngt --list [email protected]`
- list members of a group
- `./ngt --members [email protected]`
- update a users email for all of their groups
- `./ngt --update [email protected] [email protected]`

## Installation

The tool uses several python libraries, which need to be installed first via `pip`:

```bash
$ sudo pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib
```

## Authentication

Authentication is provided via a `credentials.json` file that provides the
client id and client secret to be used for all operations. These can be
configured through the [Google API
Dashboard](https://console.developers.google.com/apis/credentials). You will
need to configure an `OAuth 2.0 client ID` with sufficent privledges for the
necessary authentication scopes to be granted:

SCOPES

- `https://www.googleapis.com/auth/admin.directory.user`
- `https://www.googleapis.com/auth/admin.directory.group`
- `https://www.googleapis.com/auth/admin.directory.group.member`

Once the client id is created on the dashboard, download the file to the
directory containing `ngt` and name it `credentials.json`. The first time you
run the tool, you will be requested to authenticate with Google, and allow the
requested scopes. The authorization is cached in a local file so you don't have
to log in again.

## Example usage

```bash
jones@glacier$ ./ngt --list [email protected]
Groups for [email protected]:
[email protected]
[email protected]
jones@glacier$ ./ngt --update [email protected]
Both email and new_email are required for update.
jones@glacier$ ./ngt --update
Both email and new_email are required for update.
jones@glacier$ ./ngt --update [email protected] [email protected]
Updating groups for [email protected]:
Updating group: [email protected]
kind: admin#directory#member
etag: "nM32qckM4XsKqhG-zylXvkNQRY8/yg30o1EeD9k6UTZZd-yqkT98JUs"
id: 105267514831512253030
email: [email protected]
role: MEMBER
type: USER
status: ACTIVE
delivery_settings: ALL_MAIL
Updating group: [email protected]
kind: admin#directory#member
etag: "nM32qckM4XsKqhG-zylXvkNQRY8/yg30o1EeD9k6UTZZd-yqkT98JUs"
id: 105267514831512253030
email: [email protected]
role: MEMBER
type: USER
status: ACTIVE
delivery_settings: ALL_MAIL
jones@glacier$ ./ngt --list [email protected]
Groups for [email protected]:
[email protected]
[email protected]
jones@glacier$
```