Skip to content

Instantly share code, notes, and snippets.

@rca
Created August 29, 2019 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rca/3a5947ce0432a71968f0dfdbe3d3d9be to your computer and use it in GitHub Desktop.
Save rca/3a5947ce0432a71968f0dfdbe3d3d9be to your computer and use it in GitHub Desktop.
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