Created
August 16, 2020 21:23
-
-
Save pythoninthegrass/90361fe4c0c96d47de46481ba0e35880 to your computer and use it in GitHub Desktop.
Python credentials boilerplate with decouple and getpass
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from decouple import config | |
from getpass import getpass | |
import os | |
# Dynamic prompt for creds stored as tuple | |
# 0: eml_addr | |
# 1: passwd | |
# print(dyn_creds[0:]) # ('nopez@no.com', 'yesnononoyes') | |
def hardcode_death(): | |
eml_addr = input('Please enter your email address: ') | |
passwd = getpass('Enter app-specific password: ') | |
return eml_addr, passwd | |
# decouple library | |
# ~/.env | |
env = os.getcwd() + '/.env' | |
if os.path.exists(env): | |
eml_addr = config('email') | |
passwd = config('password') | |
creds = {'email': eml_addr, | |
'token': passwd} | |
else: | |
dyn_creds = hardcode_death() | |
creds = {'email': dyn_creds[0], | |
'token': dyn_creds[1]} | |
# ~/.cfg | |
if os.path.exists(os.getenv('HOME') + '/.cfg'): | |
client = Client(**get_ini_config()) | |
else: | |
dyn_creds = hardcode_death() | |
testconfig = { | |
'email': dyn_creds[0], | |
'password': dyn_creds[1], | |
'url': 'https://fqdn.com', | |
'token': True | |
} | |
client = Client(**testconfig) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment