jeremyephron / simplegmail

A simple Gmail API client for applications in Python
MIT License
336 stars 73 forks source link

Enables Using Environment Variable for Authorization - Issue #49 #114

Open Tylerlhess opened 5 months ago

Tylerlhess commented 5 months ago

Solves #49

Added an init option to the Gmail class to respect environment variable SIMPLEGMAIL_CREDENTIALS as an alternative to having the gmail_token.json.

Why:

This provides a solution for dockerizing a project using secrets. While you can mount a secret as a file within k8s and updating that file won't affect the pods operation this is not true with docker. This allows you to set the variable and the container build and manage the auth token file without reauthorization or having to give write permissions to each container sharing the same bind mount.

Use:

set the environment variable in the shell

export SIMPLEGMAIL_CREDENTIALS=$(cat gmail_token.json)  
# script.py
from simplegmail import Gmail

gmail = Gmail(use_envvars=True)