Created
April 2, 2021 14:48
-
-
Save mattbloomfield/1fd8ad143e5b5f394ac7fe061cf5f74d to your computer and use it in GitHub Desktop.
Useful to refresh your local .env file
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
#!/bin/sh | |
BLUE=\\x1B[34m | |
YELLOW=\\x1B[33m | |
GREEN=\\x1B[32m | |
RED=\\x1B[31m | |
RESET=\\x1b[0m | |
## Useful to refresh your local .env file | |
## Usage: fin refresh_env | |
# Forces whole job to error on failure | |
set -e | |
# Get user's name | |
USER=$(fin config get --env=local DEV_USER) | |
INTERNAL_API_KEY=$(fin config get --env=local INTERNAL_API_KEY) | |
TRANSACTION_ID=$(date +"%Y-%m-%d_%H-%M-%S") | |
if [ -z "$USER" ] | |
then | |
echo "${BLUE}Please enter your internal user name (e.g. matthewb) and press [ENTER]${RESET}" | |
read USER | |
fin config set --env=local DEV_USER=$USER # use your chamber username | |
fi | |
if [ -z "$INTERNAL_API_KEY" ] | |
then | |
echo "${BLUE}Please paste in the Internal API Key and press [ENTER]: \n If you do not have a key, ask your engineering lead${RESET}" | |
read INTERNAL_API_KEY | |
fin config set --env=local INTERNAL_API_KEY=$INTERNAL_API_KEY # use your chamber username | |
fi | |
TMP_FILEPATH=/tmp/${PROJECT}_${TRANSACTION_ID}.env | |
if test -f "./.env"; then | |
echo "${YELLOW} MOVING LOCAL .env FILE TO ${TMP_FILEPATH}...${RESET}" | |
mv -v ./.env $TMP_FILEPATH | |
fi | |
# Get a .env file from remote, feed it user name first | |
echo "${YELLOW} BUILDING LOCAL .env FILE...${RESET}" | |
# Remove quotations at beginning and end if necessary | |
USER="${USER%\"}" | |
USER="${USER#\"}" | |
INTERNAL_API_KEY="${INTERNAL_API_KEY%\"}" | |
INTERNAL_API_KEY="${INTERNAL_API_KEY#\"}" | |
echo "https://xxxxxx.execute-api.us-east-2.amazonaws.com/path/to/function?key=${INTERNAL_API_KEY}&site=${PROJECT}&user=${USER}" | |
curl -o ./.env -k "https://xxxxxx.execute-api.us-east-2.amazonaws.com/path/to/function?key=${INTERNAL_API_KEY}&site=${PROJECT}&user=${USER}" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment