Created
August 29, 2019 18:26
-
-
Save rca/3a5947ce0432a71968f0dfdbe3d3d9be to your computer and use it in GitHub Desktop.
Converts key/value pairs returned by a vault command into 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
#!/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