Skip to content

Commit

Permalink
Merge pull request #8 from cytopia/unset
Browse files Browse the repository at this point in the history
Be able to unset AWS variables
  • Loading branch information
cytopia authored May 16, 2018
2 parents 1d3fa75 + ff04229 commit c29d9ec
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 6 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,25 +97,36 @@ AWS_DELEGATION_TOKEN="XXXXXXXXXXXXXXXXx/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/XXXXXXXXX
AWS_REGION="eu-central-1"
```

#### Unset all AWS_ variables
```bash
user> $(aws-export-profile -u)
```


## Usage

```bash
Usage: aws-export-profile [profile] [credentials] [config]
aws-export-profile --unset, -u
aws-export-profile --help|-h
aws-export-profile --version|-v

This bash helper will output AWS export statements of your chosen aws boto profile.
Wrap this script in $(aws-export-profile) to export those environment variables.

Optional arguments:
Optional parameter:
[profile] Boto profile name to export. Default is 'default'
[credentials] Path to your aws credentials file.
Default is ~/.aws/credentials
[config] Path to your aws config file.
If no config file is found, AWS_REGION export will not be available.
Default is ~/.aws/config

Arguments:
--unset, -u Unset currently set AWS variables from env
--help, -h Show this help screen
--version, -v Show version

Available exports:
AWS_ACCESS_KEY_ID
AWS_ACCESS_KEY
Expand All @@ -133,6 +144,9 @@ Examples to show output:
Examples to export:
$(aws-export-profile testing)
$(aws-export-profile production /jenkins/aws/credentials /jenkins/aws/config)

Examples to unset all AWS variables
\$(aws-export-profile -u)
```

## License
Expand Down
41 changes: 36 additions & 5 deletions aws-export-profile
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,57 @@ set -e
set -u
set -o pipefail

unset_environment() {
echo "unset AWS_ACCESS_KEY_ID"
echo "unset AWS_ACCESS_KEY"
echo "unset AWS_SECRET_ACCESS_KEY"
echo "unset AWS_SECRET_KEY"
echo "unset AWS_SESSION_TOKEN"
echo "unset AWS_DELEGATION_TOKEN"
echo "unset AWS_SECURITY_TOKEN"
echo "unset AWS_REGION"
}


# Display usage
if [ "${#}" -gt "0" ]; then
case "${1}" in
-u|--unset)
unset_environment
exit 0
;;

-v|--version)
cat << EOF
aws-export-profile v0.3
aws-export-profile v0.4
EOF
;;
exit 0
;;

-h|--help)
cat << EOF
Usage: aws-export-profile [profile] [credentials] [config]
aws-export-profile --help|-h
aws-export-profile --version|-v
aws-export-profile --unset, -u
aws-export-profile --help, -h
aws-export-profile --version, -v
This bash helper will output AWS export statements of your chosen aws boto profile.
Wrap this script in \$(aws-export-profile) to export those environment variables.
Optional arguments:
Optional parameter:
[profile] Boto profile name to export. Default is 'default'
[credentials] Path to your aws credentials file.
Default is ~/.aws/credentials
[config] Path to your aws config file.
If no config file is found, AWS_REGION export will not be available.
Default is ~/.aws/config
Arguments:
--unset, -u Unset currently set AWS variables from env
--help, -h Show this help screen
--version, -v Show version
Available exports:
AWS_ACCESS_KEY_ID
AWS_ACCESS_KEY
Expand All @@ -48,10 +74,15 @@ Examples to export:
\$(aws-export-profile testing)
\$(aws-export-profile production /jenkins/aws/credentials /jenkins/aws/config)
Examples to unset all AWS variables
\$(aws-export-profile -u)
MIT License
Copyright (c) 2018 cytopia
EOF
exit 0
;;

*)
esac
fi
Expand Down

0 comments on commit c29d9ec

Please sign in to comment.