Skip to content

Instantly share code, notes, and snippets.

@rca
Created Aug 29, 2019
Embed
What would you like to do?
Converts key/value pairs returned by a vault command into environment variables
#!/usr/bin/env python3.6
"""
Converts key/value pairs returned by a vault command into environment variables
"""
import json
import sys
KEY_MAP = {
'access_key': 'AWS_ACCESS_KEY_ID',
'secret_key': 'AWS_SECRET_ACCESS_KEY',
'security_token': 'AWS_SECURITY_TOKEN',
}
def main():
content = sys.stdin.read()
data = json.loads(content)
for k, v in data['data'].items():
key = KEY_MAP.get(k, k).upper()
val = v.replace("'", "\\'")
print(f"export {key}='{val}'")
if __name__ == '__main__':
sys.exit(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment