Skip to content

Instantly share code, notes, and snippets.

@andykingking
Last active October 25, 2016 03:37
Show Gist options
  • Save andykingking/38d7db570c966f72d8b8184737fc7b7c to your computer and use it in GitHub Desktop.
Save andykingking/38d7db570c966f72d8b8184737fc7b7c to your computer and use it in GitHub Desktop.
Returns a string that can be `eval`-ed to set secrets as environment variables
import json
import subprocess
def fetch_value(key):
return subprocess.check_output(['credstash', '-r', data['region'], '-t', data['table'], 'get', key])
def create_shell_command(variable, credential):
value = fetch_value(credential)
return 'export {0}="{1}"'.format(variable, value)
with open('creds.json') as data_file:
data = json.load(data_file)
values = [create_shell_command(variable, credential) for credential, variable in data['variables'].iteritems()]
print('; '.join(values))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment