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
- Host: GitHub
- URL: https://github.com/nceas/nceas-gsuite-tool
- Owner: NCEAS
- License: apache-2.0
- Created: 2019-10-25T02:12:48.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-10-26T00:32:01.000Z (over 5 years ago)
- Last Synced: 2025-01-10T19:47:21.390Z (5 months ago)
- Language: Python
- Size: 11.7 KB
- Stars: 0
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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$
```