Last active
October 25, 2016 03:37
-
-
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
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
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