Last active
November 3, 2020 11:24
-
-
Save davidrv87/f72cce27dc216f1ee221ffdf8fb859ea to your computer and use it in GitHub Desktop.
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
# Seed AWS_ vars in your own terminal without opening a new shell session | |
function seed_aws_vars() { | |
read -p "Select AWS account [dazn-ar-dev]: " AWS_ACCOUNT | |
AWS_ACCOUNT=${AWS_ACCOUNT:-dazn-ar-dev} | |
dazn aws exec -p dazn-ar-dev env | grep --color=never AWS_ | awk '{print "export " $1}' | |
eval "$(dazn aws exec -p dazn-ar-dev env | grep --color=never AWS_ | awk '{print "export " $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
# Unseed AWS_ variables from your shell | |
function unseed_aws_vars() { | |
env | grep --color=never AWS | awk -F '=' '{print "unset " $1}' | |
eval "$(env | grep --color=never AWS | awk -F '=' '{print "unset " $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
# Command line tool for MFA | |
oathtool -b --totp <QR_CODE_TEXT> | tr -d '\n' | pbcopy |
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
# Seed local environment from a file | |
function seed_local_env() { | |
if [ -z "$1" ]; then | |
read -p "Select environment file [.env]: " ENV_FILE | |
ENV_FILE=${ENV_FILE:-.env} | |
else | |
ENV_FILE=$1 | |
fi | |
if test -f $ENV_FILE; then | |
eval "$(cat $ENV_FILE | awk '{print "export " $1}')" | |
echo "Local environment seeded from '$ENV_FILE' file!" | |
else | |
echo "File '$ENV_FILE' does not exist" | |
fi | |
} |
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
This gist is about useful utilities |
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 vtl() { | |
echo "Copying Vault token to the clipboard..." | |
read -p " Do you want to update environment file too? [Y/n]: " UPDATE_ENV_FILE | |
UPDATE_ENV_FILE=${UPDATE_ENV_FILE:-Y} | |
if [ "$UPDATE_ENV_FILE" = "Y" ]; then | |
read -p "Enter the name of the file [.env]: " ENV_FILE | |
ENV_FILE=${ENV_FILE:-.env} | |
if test -f $ENV_FILE; then | |
mv ${ENV_FILE} updated_file | |
echo "Updating $ENV_FILE file..." | |
TOKEN=$(get_vault_token) | |
sed -i '' "s/vault_auth_token=.*/vault_auth_token=$TOKEN/" updated_file | |
sed -i '' "s/vault_auth_token__receipts=.*/vault_auth_token__receipts=$TOKEN/" updated_file | |
sed -i '' "s/VAULT_PERIODIC_TOKEN=.*/VAULT_PERIODIC_TOKEN=$TOKEN/" updated_file | |
mv updated_file $ENV_FILE | |
else | |
echo "$ENV_FILE file does not exist. Skipping update" | |
fi | |
else | |
echo "Skipping environment file update" | |
fi | |
echo "Vault token copied to the clipboard!" | |
echo $TOKEN | tr -d '[:space:]'| pbcopy | |
read -p " Do you want me to seed your local environment for you? [Y/n]: " SEED_ENVIRONMENT | |
SEED_ENVIRONMENT=${SEED_ENVIRONMENT:-Y} | |
if [ "$SEED_ENVIRONMENT" = "Y" ]; then | |
echo "Seeding environment..." | |
seed_local_env $ENV_FILE | |
else | |
echo "Local environment not seeded. Use 'seed_local_env' to seed manually" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment