]> git.immae.eu Git - perso/Immae/Config/Ansible.git/blob - roles/contexts/fretlink/templates/environment.j2
Add new environment variables
[perso/Immae/Config/Ansible.git] / roles / contexts / fretlink / templates / environment.j2
1 # vim: filetype=sh
2 # Macaron
3 # openssl rand -hex 32
4 # URI: postgres:///db_name
5
6 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
7 if ! $(echo "$PATH" | grep -q "$DIR/toolbox/scripts"); then
8 PATH="$DIR/toolbox/scripts:$PATH"
9 fi
10
11 p() {
12 if [ -z "$2" ]; then
13 pass show Travail/Fretlink/$1
14 else
15 pass show Travail/Fretlink/$1 | grep "^$2:" | sed -e "s/^$2: //"
16 fi | head -n1
17 }
18
19 build_macaroon() {
20 if [ "$1" = "--old" ]; then
21 shift
22 action="old-realms"
23 ttl=""
24 else
25 action="new"
26 ttl="--no-ttl"
27 fi
28
29 if [ -z "$1" -o -z "$2" -o -z "$3" -o -z "$4" ]; then
30 echo "build_macaroon [--old] secret src-key-id target realm" >&2
31 return
32 fi
33
34 secret="$1"
35 src="$2"
36 target="uri://fretlink/$3"
37 realm="$4"
38
39 pushd "$HOME/workdir/haskell-commons" >/dev/null 2>/dev/null
40 MACAROON_PRIVATE_KEY="$secret" MACAROON_SECRET="$secret" stack exec macaroon-bakery -- $action --location "$target" --key-id "$src" $ttl "$realm"
41 popd 2>/dev/null >/dev/null
42 }
43
44 APP=$(basename $(pwd))
45
46 FL_APPS_HOST="localhost"
47 FL_APPS_SCHEME="http"
48
49 FL_ADMIN_ROOT_PORT=8079
50 FL_ADMIN_ROOT_PRIVATE_KEY="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/AdminRoot subkey=PrivateKey') }}"
51 FL_ADMIN_ROOT_URL="$FL_APPS_SCHEME://$FL_APPS_HOST:$FL_ADMIN_ROOT_PORT/api/"
52
53 FL_APP_PORT=8080
54 FL_APP_MONGO_URI="mongodb://localhost:27017/fretlink"
55 FL_APP_SECRET="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/App subkey=Secret') }}"
56 FL_APP_URL="$FL_APPS_SCHEME://$FL_APPS_HOST:$FL_APP_PORT"
57
58 FL_CARRIER_DIRECTORY_PORT=8082
59 FL_CARRIER_DIRECTORY_SECRET="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/CarrierDirectory subkey=Secret') }}"
60 FL_CARRIER_DIRECTORY_PRIVATE_KEY="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/CarrierDirectory subkey=PrivateKey') }}"
61 FL_CARRIER_DIRECTORY_URL="$FL_APPS_SCHEME://$FL_APPS_HOST:$FL_CARRIER_DIRECTORY_PORT/api/"
62
63 FL_NOTIFIER_PORT=8081
64 FL_NOTIFIER_SECRET="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/Notifier subkey=Secret') }}"
65 FL_NOTIFIER_PRIVATE_KEY="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/Notifier subkey=PrivateKey') }}"
66 FL_NOTIFIER_URL="$FL_APPS_SCHEME://$FL_APPS_HOST:$FL_NOTIFIER_PORT/api"
67
68 FL_PRICER_PORT=8083
69 FL_PRICER_PRIVATE_KEY="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/Pricer subkey=PrivateKey') }}"
70
71 FL_FREIGHT_PORT=8084
72 FL_FREIGHT_SECRET="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/Freight subkey=Secret') }}"
73
74 FL_BOOKKEEPING_SECRET="dummy"
75 FL_LANE_EXPLORER_SECRET="dummy"
76
77 FL_PSQL_HOST="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Local subkey=Host') }}"
78 FL_PSQL_PORT="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Local subkey=Port') }}"
79 FL_PSQL_USER="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Local subkey=User') }}"
80 FL_PSQL_PASSWORD="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Local') }}"
81
82 FL_CARRIER_DIRECTORY_DEV_PSQL_HOST="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Dev/CarrierDirectory subkey=Host') }}"
83 FL_CARRIER_DIRECTORY_DEV_PSQL_PORT="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Dev/CarrierDirectory subkey=Port') }}"
84 FL_CARRIER_DIRECTORY_DEV_PSQL_USER="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Dev/CarrierDirectory subkey=User') }}"
85 FL_CARRIER_DIRECTORY_DEV_PSQL_PASSWORD="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Dev/CarrierDirectory') }}"
86 FL_CARRIER_DIRECTORY_DEV_PSQL_DB="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Dev/CarrierDirectory subkey=Database') }}"
87
88 FL_GEODATA_DEV_PSQL_HOST="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Dev/Geodata subkey=Host') }}"
89 FL_GEODATA_DEV_PSQL_PORT="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Dev/Geodata subkey=Port') }}"
90 FL_GEODATA_DEV_PSQL_USER="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Dev/Geodata subkey=User') }}"
91 FL_GEODATA_DEV_PSQL_PASSWORD="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Dev/Geodata') }}"
92 FL_GEODATA_DEV_PSQL_DB="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Dev/Geodata subkey=Database') }}"
93
94 FL_NOTIFIER_DEV_PSQL_HOST="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Dev/Notifier subkey=Host') }}"
95 FL_NOTIFIER_DEV_PSQL_PORT="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Dev/Notifier subkey=Port') }}"
96 FL_NOTIFIER_DEV_PSQL_USER="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Dev/Notifier subkey=User') }}"
97 FL_NOTIFIER_DEV_PSQL_PASSWORD="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Dev/Notifier') }}"
98 FL_NOTIFIER_DEV_PSQL_DB="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Dev/Notifier subkey=Database') }}"
99
100 FL_TOOLBOX_AGENT_MACAROON="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/ToolboxAgent') }}"
101
102 if [ -f "local.env.example" ]; then
103 source local.env.example
104 fi
105
106 if [ "$APP" != "app" ]; then
107 name="${APP//-/_}"
108 port_var="FL_${name^^}_PORT"
109 secret_var="FL_${name^^}_SECRET"
110 private_key_var="FL_${name^^}_PRIVATE_KEY"
111
112 if [ -n "${!secret_var}" ]; then
113 export MACAROON_SECRET="${!secret_var}"
114 fi
115 if [ -n "${!private_key_var}" ]; then
116 export MACAROON_PRIVATE_KEY="${!private_key_var}"
117 fi
118 export PORT="${!port_var}"
119 export PG_URI="postgres:///$name"
120
121 if [ -z "$FL_ENV" ]; then
122 export POSTGRESQL_ADDON_HOST="$FL_PSQL_HOST"
123 export POSTGRESQL_ADDON_PORT="$FL_PSQL_PORT"
124 export POSTGRESQL_ADDON_USER="$FL_PSQL_USER"
125 export POSTGRESQL_ADDON_PASSWORD="$FL_PSQL_PASSWORD"
126 export POSTGRESQL_ADDON_DB="$name"
127 else
128 postgresql_host="FL_${name^^}_${FL_ENV^^}_PSQL_HOST"
129 postgresql_port="FL_${name^^}_${FL_ENV^^}_PSQL_PORT"
130 postgresql_user="FL_${name^^}_${FL_ENV^^}_PSQL_USER"
131 postgresql_password="FL_${name^^}_${FL_ENV^^}_PSQL_PASSWORD"
132 postgresql_db="FL_${name^^}_${FL_ENV^^}_PSQL_DB"
133 export FRETLINK_ENV="$FL_ENV"
134 export POSTGRESQL_ADDON_HOST="${!postgresql_host}"
135 export POSTGRESQL_ADDON_PORT="${!postgresql_port}"
136 export POSTGRESQL_ADDON_USER="${!postgresql_user}"
137 export POSTGRESQL_ADDON_PASSWORD="${!postgresql_password}"
138 export POSTGRESQL_ADDON_DB="${!postgresql_db}"
139 fi
140 fi
141
142 if [ "$APP" = "app" ]; then
143 export FRETLINK_MONGO_URI="$FL_APP_MONGO_URI"
144 export FRETLINK_PORT="$FL_APP_PORT"
145 export FRETLINK_BASE_URL="$FL_APP_URL"
146
147 # Dummies mandatory but not defined by default
148 export FRETLINK_SMTP_PASSWORD="password"
149 export FRETLINK_AMAZON_PUBLIC_KEY="password"
150 export FRETLINK_AMAZON_PRIVATE_KEY="password"
151 export FRETLINK_GMAPS_API_KEY="password"
152
153 # secret
154 export FRETLINK_MACAROON_SECRET=$FL_APP_SECRET
155
156 # carrier directory
157 export CARRIER_DIRECTORY_URI="$FL_CARRIER_DIRECTORY_URL"
158 export FRETLINK_CARDIR_URL="$FL_CARRIER_DIRECTORY_URL"
159 export FRETLINK_CARDIR_ENABLED="true"
160
161 # notifier
162 export FRETLINK_NOTIFIER_API=$FL_NOTIFIER_URL
163 export FRETLINK_NOTIFIER_ACCESS_KEY="$(build_macaroon $FL_NOTIFIER_SECRET notifier notifier messaging)"
164 export FRETLINK_NOTIFIER_TRANSPOREON_ACCESS_KEY="$(build_macaroon --old $FL_NOTIFIER_PRIVATE_KEY notifier notifier external)"
165 export FRETLINK_NOTIFIER_TRANSPOREON_ENABLED="true"
166
167 export FRETLINK_NOTIFIER_ENABLED="true"
168 export FRETLINK_NOTIFIER_AMQP_ENABLED="true"
169 export FRETLINK_NOTIFIER_AMQP_TLS="{{ lookup('passwordstore', 'Travail/Fretlink/Rabbitmq/Local/Notifier subkey=TLS') }}"
170 export FRETLINK_NOTIFIER_AMQP_USER="{{ lookup('passwordstore', 'Travail/Fretlink/Rabbitmq/Local/Notifier subkey=User') }}"
171 export FRETLINK_NOTIFIER_AMQP_PASSWORD="{{ lookup('passwordstore', 'Travail/Fretlink/Rabbitmq/Local/Notifier') }}"
172 export FRETLINK_NOTIFIER_AMQP_HOSTS="{{ lookup('passwordstore', 'Travail/Fretlink/Rabbitmq/Local/Notifier subkey=Hosts') }}"
173 export FRETLINK_NOTIFIER_AMQP_QUEUE="{{ lookup('passwordstore', 'Travail/Fretlink/Rabbitmq/Local/Notifier subkey=Queue') }}"
174 export FRETLINK_NOTIFIER_AMQP_EXCHANGE="{{ lookup('passwordstore', 'Travail/Fretlink/Rabbitmq/Local/Notifier subkey=Exchange') }}"
175 export FRETLINK_NOTIFIER_AMQP_PORT="{{ lookup('passwordstore', 'Travail/Fretlink/Rabbitmq/Local/Notifier subkey=Port') }}"
176 export FRETLINK_NOTIFIER_AMQP_VHOST="{{ lookup('passwordstore', 'Travail/Fretlink/Rabbitmq/Local/Notifier subkey=Vhost') }}"
177
178
179 # admin-root
180 export FRETLINK_ADMINROOT_URL=$FL_ADMIN_ROOT_URL
181 export FRETLINK_ADMINROOT_ACCESS_KEY="$(build_macaroon $FL_ADMIN_ROOT_PRIVATE_KEY admin-root admin-root admin-root::token-delivery)"
182
183 # geodata
184 export FRETLINK_GEODATA_API="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/GeodataDev subkey=Url') }}"
185 export FRETLINK_GEODATA_ACCESS_KEY="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/GeodataDev') }}"
186 fi
187
188 if [ "$APP" = "admin-root" ]; then
189 export BASE_URL=$FL_APPS_HOST
190 export API_ROOT="http://$BASE_URL:$PORT/api"
191 export UI_ROOT="http://$BASE_URL:$PORT/admin"
192 export TOK="$(build_macaroon $FL_ADMIN_ROOT_PRIVATE_KEY admin-root admin-root admin-root::provisioning)"
193
194 export CARDIR_MACAROON_SECRET=$FL_CARRIER_DIRECTORY_SECRET
195 export NOTIFIER_MACAROON_SECRET=$FL_NOTIFIER_SECRET
196 export BOOKKEEPING_MACAROON_SECRET=$FL_BOOKKEEPING_SECRET
197 export LANE_EXPLORER_MACAROON_SECRET=$FL_LANE_EXPLORER_SECRET
198 fi
199
200 if [ "$APP" = "carrier-directory" ]; then
201 export ADMIN_BASE_URL=$FL_APP_URL
202 fi
203
204 if [ "$APP" = "notifier" ]; then
205 export MAILGUN_API_KEY="dummy"
206 export MAILGUN_DOMAIN="dummy"
207 export TEMPLATES_ASSETS_BASE_URL="http://dummy/"
208 export TRANSPOREON_USER="{{ lookup('passwordstore', 'Travail/Fretlink/Transporeon/ApiTest subkey=Login') }}"
209 export TRANSPOREON_PASSWORD="{{ lookup('passwordstore', 'Travail/Fretlink/Transporeon/ApiTest') }}"
210 export TRANSPOREON_HOST="api.test.transporeon.com"
211 export TRANSPOREON_CALLBACK_USER="{{ lookup('passwordstore', 'Travail/Fretlink/Transporeon/NotifierCallbackTest subkey=Login') }}"
212 export TRANSPOREON_CALLBACK_PASSWORD="{{ lookup('passwordstore', 'Travail/Fretlink/Transporeon/NotifierCallbackTest') }}"
213
214 # Used by curl
215 # v2
216 #export MACAROON="$(build_macaroon $FL_NOTIFIER_SECRET notifier notifier external)"
217 # v1
218 export MACAROON="$(build_macaroon --old $FL_NOTIFIER_PRIVATE_KEY notifier notifier external)"
219
220 # To push transporeon cargos to app
221 export TRANSPOREON_APP_PUSH_URL="http://localhost:8080/api/transporeon/cargo"
222 export TRANSPOREON_APP_PUSH_MACAROON="$(build_macaroon $FL_APP_SECRET notifier app app::transporeon-cargos-write)"
223
224 # AMQP
225 export AMQP_VHOST="notifier"
226 export AMQP_USER="notifier"
227 export AMQP_PASSWORD="notifier"
228 export AMQP_QUEUE="notifier"
229 export AMQP_SERVER="localhost"
230 export AMQP_TLS="false"
231 fi
232
233 if [ "$APP" = "pricer" ]; then
234 export GOOGLE_AUTH_CLIENT_ID="dummy"
235 fi
236
237 if [ "$APP" = "toolbox" ]; then
238 export AGENT_HOST=$FL_APP_URL
239 export AGENT_PATH="/"
240 export AGENT_MACAROON=$FL_TOOLBOX_AGENT_MACAROON
241 fi