Skip to content

Instantly share code, notes, and snippets.

@NGenetzky
Last active January 6, 2018 19:10
Show Gist options
  • Save NGenetzky/1983866a862da1e3c8346b12cc1499b7 to your computer and use it in GitHub Desktop.
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.
#!/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