Skip to content

Latest commit

 

History

History
64 lines (47 loc) · 3.46 KB

README.md

File metadata and controls

64 lines (47 loc) · 3.46 KB

mailing-list-sync

Build Status Codacy Badge Coverage Badge

This program can synchronize a Google Groups mailing list with a new list. It gets the old list of members from Google and compares it to the new list given to it. After that a batch request is sent to Google Directory API which tells it to add members that are only on the new list and remove members that are only on the old list.

Configuring permissions

The app uses a service account and delegated API client to access the necessary Google APIs. To get the needed permissions, create a Google project, add a service account to it and generate a JSON credentials and download it. You also need to have a G Suite admin account from which you need to delegate access rights to your Google Groups. Read the Google documentation for further details. The service account in question needs to also have a read access to the Google sheet and the project needs to have Admin SDK and Sheets APIs enabled.

The service account also needs to have permissions to create service account tokens to itself. To be more specific, it needs to have role roles/iam.serviceAccountTokenCreator assigned to itself. You can find more details here.

There needs to be an environment variable GOOGLE_APPLICATION_CREDENTIALS which contains a path to the service account credentials json file and DELEGATED_USER which is your G Suite admin email address. These can be added to a .env file to the project root.

In production, the GOOGLE_APPLICATION_CREDENTIALS variable is not needed if the application is running in GCP environment. In that case the application will try to use the default service account that is assigned to the machine.

Installing

To get the development environment up, a virtual environment must be established and the dependencies must be installed to it:

virtualenv --python=/usr/bin/python3.6 venv
source venv/bin/activate
pip install pipenv
pipenv install --dev

Running

The cli tool can be run with one of the following command which lists all the available commands:

python -m src

Tests are executed the following command:

make test

Synchronizing a mailing list

At the moment the cli tool can only synchronize a list from a Google sheet.

python -m src sync [SHEET_ID] [CELL_RANGE] [GROUP_NAME]

For example

python -m src sync 1337 Sheet1!A1:A5 [email protected]

will fetch values of the cells A1:A5 in tab Sheet1 from a spreadsheet which has an id of 1337 and synchronize the group [email protected] with the fetched email addresses. If only a cell range A1:A5 is used, the first tab in the sheet will be used.