Created
February 23, 2019 14:13
-
-
Save kg6zjl/047cac65225ff5a0acd50ec751f7128a to your computer and use it in GitHub Desktop.
Create env vars from single section of ~/.aws/credentials, and set as default.
This file contains hidden or 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
| function activate() { #choose aws creds to push to env vars (example: activate sre-dev) | |
| unset AWS_DEFAULT_PROFILE AWS_PROFILE AWS_SESSION_TOKEN AWS_SECRET_ACCESS_KEY AWS_ACCESS_KEY_ID AWS_SECURITY_TOKEN | |
| eval $(python3 $HOME/git/dotfiles/files/python-ini.py $HOME/.aws/credentials $1) | |
| } |
This file contains hidden or 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/python3 | |
| import configparser | |
| import sys | |
| config = configparser.ConfigParser() | |
| config.read(sys.argv[1]) | |
| #remove default | |
| if config.has_section('default'): | |
| config.remove_section('default') | |
| config.write(open(sys.argv[1],'w')) | |
| #create/recreate default | |
| if not config.has_section('default'): | |
| config.add_section('default') | |
| for l in config[sys.argv[2]]: | |
| print("export",l.upper()+"="+config[sys.argv[2]][l]) | |
| config.set('default', l, config[sys.argv[2]][l]) | |
| #write to file | |
| config.write(open(sys.argv[1],'w')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment