-
Notifications
You must be signed in to change notification settings - Fork 1
/
refresh.sh
executable file
·104 lines (90 loc) · 3.14 KB
/
refresh.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/bash
# This script helps make recovering from Salesforce Refreshes easier. It:
# 1. Updates Heroku env vars
# 2. Clears now-invalid user DBs on Heroku apps
# 3. Updates env vars for CircleCI
# To use this script:
# 1. Put the updated env vars in a file (.env generally)
# 2. If you don't already have it installed, run `brew install jq` to install the jq tool
# 3. Get a circleCI token by going to https://app.circleci.com/settings/user/tokens and adding a personal API token.
# 3. Run the script, passing your environment and circle ci token as arguments
VARS_TO_UPDATE_CIRCLE_CI=(
"SALESFORCE_HOST"
"SALESFORCE_INSTANCE_URL"
"SALESFORCE_PASSWORD"
"SALESFORCE_SECURITY_TOKEN"
"SALESFORCE_CLIENT_SECRET"
"SALESFORCE_CLIENT_ID"
"SALESFORCE_INSTANCE_URL"
"COMMUNITY_LOGIN_URL"
"E2E_SALESFORCE_PASSWORD"
"E2E_SALESFORCE_USERNAME"
"E2E_LENDING_INSTITUTION"
"E2E_FLAGGED_RECORD_SET_ID"
)
VARS_TO_UPDATE_HEROKU=(
"SALESFORCE_CLIENT_SECRET"
"SALESFORCE_CLIENT_ID"
"SALESFORCE_INSTANCE_URL"
"COMMUNITY_LOGIN_URL"
)
# Argument defaults
env_file=".env"
while getopts ":he::c:" opt; do
case $opt in
h )
echo "Usage:"
echo " refresh.sh -h Display this help message."
echo " refresh.sh -e <environment> Specify an environment to update, either full or qa."
echo " refresh.sh -c <circle ci token> Provide a CircleCI token."
exit 0
;;
e )
env=$OPTARG
;;
c )
circle_ci_token=$OPTARG
;;
\? ) echo "Usage: cmd [-h] [-f]"
;;
esac
done
echo "Loading environment variables from file: $env_file"
source $env_file
for varname in ${VARS_TO_UPDATE_CIRCLE_CI[@]}; do
value="${!varname}"
echo " Loaded $varname=$value"
done
echo "Starting Heroku credential update for Partners $env"
if [ $env == "full" ]; then
# Get all apps that are dahlia-web-full apps.
heroku_apps=$(heroku apps --team=sfdigitalservices --json | jq '.[].name | select(test("dahlia-lap-full-*"))')
elif [ $env == "qa" ]; then
heroku_apps=('dahlia-lap-qa')
else
echo "Error: environment must be full or qa"
exit 1
fi
for app in ${heroku_apps[@]}
do
# Strip out double quotes from app names
app=$(echo "$app" | tr -d '"')
echo "Updating credentials for $app"
for varname in ${VARS_TO_UPDATE_HEROKU[@]}; do
value="${!varname}"
heroku config:set $varname=$value --app $app
done
echo "echo 'User.destroy_all' | rails c && exit" | heroku run bash --app $app
done
echo "Heroku update complete"
if [ $env == "full" ]; then
echo "Starting CircleCI credential update"
BASE_CIRCLECI_URL="https://circleci.com/api/v1.1/project/github/SFDigitalServices/sf-dahlia-lap/envvar"
for varname in ${VARS_TO_UPDATE_CIRCLE_CI[@]}; do
value="${!varname}"
echo " Resetting env variable: $varname=$value"
curl -s -X DELETE $BASE_CIRCLECI_URL/$varname?circle-token=$circle_ci_token > /dev/null
curl -s -X POST --header "Content-Type: application/json" -d "{\"name\": \"$varname\", \"value\": \"$value\"}" $BASE_CIRCLECI_URL?circle-token=$circle_ci_token > /dev/null
done
echo "Credentials updated for CircleCI"
fi