Last active
January 6, 2018 19:10
-
-
Save NGenetzky/1983866a862da1e3c8346b12cc1499b7 to your computer and use it in GitHub Desktop.
Obtains secrets from secrets.json so they don't have to be in your code.
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
#!/usr/bin/env python | |
'''This reads data from a json file named "secrets.json" | |
Formated like this: | |
{ | |
"trello": { | |
"api_key": "", | |
"token":"", | |
} | |
} | |
''' | |
import os | |
import json | |
SECRETS_FILE = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'secrets.json') | |
# SECRETS_FILE = '/tmp/secrets.json' | |
def get_secret(service, key=None): | |
with open(SECRETS_FILE) as data: | |
s = json.load(data) | |
if key is None: | |
secret = s[service] | |
else: | |
secret = s[service][key] | |
return secret | |
print(get_secret('trello')) | |
print(get_secret('trello','api_key')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment