]> git.immae.eu Git - perso/Immae/Config/Ansible.git/blob - roles/contexts/fretlink/templates/environment.j2
bb9328a5e190b605e7eed25739661cb07ff4d9b2
[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 build_macaroon() {
12 if [ "$1" = "--old" ]; then
13 shift
14 action="old-realms"
15 ttl=""
16 else
17 action="new"
18 ttl="--no-ttl"
19 fi
20
21 if [ -z "$1" -o -z "$2" -o -z "$3" -o -z "$4" ]; then
22 echo "build_macaroon [--old] secret src-key-id target realm" >&2
23 return
24 fi
25
26 secret="$1"
27 src="$2"
28 target="uri://fretlink/$3"
29 realm="$4"
30
31 cd "$HOME/workdir/haskell-commons"
32 MACAROON_PRIVATE_KEY="$secret" MACAROON_SECRET="$secret" stack exec macaroon-bakery -- $action --location "$target" --key-id "$src" $ttl "$realm"
33 }
34
35 APP=$(basename $(pwd))
36
37 FL_APPS_HOST="localhost"
38 FL_APPS_SCHEME="http"
39
40 FL_ADMIN_ROOT_PORT=8079
41 FL_ADMIN_ROOT_PRIVATE_KEY="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/AdminRoot subkey=PrivateKey') }}"
42 FL_ADMIN_ROOT_URL="$FL_APPS_SCHEME://$FL_APPS_HOST:$FL_ADMIN_ROOT_PORT/api/"
43
44 FL_APP_PORT=8080
45 FL_APP_MONGO_URI="mongodb://localhost:27017/fretlink"
46 FL_APP_SECRET="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/App subkey=Secret') }}"
47 FL_APP_URL="$FL_APPS_SCHEME://$FL_APPS_HOST:$FL_APP_PORT"
48
49 FL_CARRIER_DIRECTORY_PORT=8082
50 FL_CARRIER_DIRECTORY_SECRET="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/CarrierDirectory subkey=Secret') }}"
51 FL_CARRIER_DIRECTORY_PRIVATE_KEY="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/CarrierDirectory subkey=PrivateKey') }}"
52 FL_CARRIER_DIRECTORY_URL="$FL_APPS_SCHEME://$FL_APPS_HOST:$FL_CARRIER_DIRECTORY_PORT/api/"
53
54 FL_NOTIFIER_PORT=8081
55 FL_NOTIFIER_SECRET="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/Notifier subkey=Secret') }}"
56 FL_NOTIFIER_PRIVATE_KEY="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/Notifier subkey=PrivateKey') }}"
57 FL_NOTIFIER_URL="$FL_APPS_SCHEME://$FL_APPS_HOST:$FL_NOTIFIER_PORT/api"
58
59 FL_PRICER_PORT=8083
60 FL_PRICER_PRIVATE_KEY="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/Pricer subkey=PrivateKey') }}"
61
62 FL_FREIGHT_PORT=8084
63 FL_FREIGHT_SECRET="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/Freight subkey=Secret') }}"
64
65 FL_BOOKKEEPING_SECRET="dummy"
66
67 FL_PSQL_HOST="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Local subkey=Host') }}"
68 FL_PSQL_PORT="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Local subkey=Port') }}"
69 FL_PSQL_USER="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Local subkey=User') }}"
70 FL_PSQL_PASSWORD="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Local') }}"
71
72 FL_GEODATA_DEV_PSQL_HOST="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Dev/Geodata subkey=Host') }}"
73 FL_GEODATA_DEV_PSQL_PORT="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Dev/Geodata subkey=Port') }}"
74 FL_GEODATA_DEV_PSQL_USER="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Dev/Geodata subkey=User') }}"
75 FL_GEODATA_DEV_PSQL_PASSWORD="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Dev/Geodata') }}"
76 FL_GEODATA_DEV_PSQL_DB="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Dev/Geodata subkey=Database') }}"
77
78 FL_NOTIFIER_DEV_PSQL_HOST="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Dev/Notifier subkey=Host') }}"
79 FL_NOTIFIER_DEV_PSQL_PORT="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Dev/Notifier subkey=Port') }}"
80 FL_NOTIFIER_DEV_PSQL_USER="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Dev/Notifier subkey=User') }}"
81 FL_NOTIFIER_DEV_PSQL_PASSWORD="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Dev/Notifier') }}"
82 FL_NOTIFIER_DEV_PSQL_DB="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Dev/Notifier subkey=Database') }}"
83
84 FL_TOOLBOX_AGENT_MACAROON="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/ToolboxAgent') }}"
85
86 if [ -f "local.env.example" ]; then
87 source local.env.example
88 fi
89
90 if [ "$APP" != "app" ]; then
91 name="${APP//-/_}"
92 port_var="FL_${name^^}_PORT"
93 secret_var="FL_${name^^}_SECRET"
94 private_key_var="FL_${name^^}_PRIVATE_KEY"
95
96 if [ -n "${!secret_var}" ]; then
97 export MACAROON_SECRET="${!secret_var}"
98 fi
99 if [ -n "${!private_key_var}" ]; then
100 export MACAROON_PRIVATE_KEY="${!private_key_var}"
101 fi
102 export PORT="${!port_var}"
103 export PG_URI="postgres:///$name"
104
105 if [ -z "$FL_ENV" ]; then
106 export POSTGRESQL_ADDON_HOST="$FL_PSQL_HOST"
107 export POSTGRESQL_ADDON_PORT="$FL_PSQL_PORT"
108 export POSTGRESQL_ADDON_USER="$FL_PSQL_USER"
109 export POSTGRESQL_ADDON_PASSWORD="$FL_PSQL_PASSWORD"
110 export POSTGRESQL_ADDON_DB="$name"
111 else
112 postgresql_host="FL_${name^^}_${FL_ENV^^}_PSQL_HOST"
113 postgresql_port="FL_${name^^}_${FL_ENV^^}_PSQL_PORT"
114 postgresql_user="FL_${name^^}_${FL_ENV^^}_PSQL_USER"
115 postgresql_password="FL_${name^^}_${FL_ENV^^}_PSQL_PASSWORD"
116 postgresql_db="FL_${name^^}_${FL_ENV^^}_PSQL_DB"
117 export FRETLINK_ENV="$FL_ENV"
118 export POSTGRESQL_ADDON_HOST="${!postgresql_host}"
119 export POSTGRESQL_ADDON_PORT="${!postgresql_port}"
120 export POSTGRESQL_ADDON_USER="${!postgresql_user}"
121 export POSTGRESQL_ADDON_PASSWORD="${!postgresql_password}"
122 export POSTGRESQL_ADDON_DB="${!postgresql_db}"
123 fi
124 fi
125
126 if [ "$APP" = "app" ]; then
127 export FRETLINK_MONGO_URI="$FL_APP_MONGO_URI"
128 export FRETLINK_PORT="$FL_APP_PORT"
129 export FRETLINK_BASE_URL="$FL_APP_URL"
130
131 # Dummies mandatory but not defined by default
132 export FRETLINK_SMTP_PASSWORD="password"
133 export FRETLINK_AMAZON_PUBLIC_KEY="password"
134 export FRETLINK_AMAZON_PRIVATE_KEY="password"
135 export FRETLINK_GMAPS_API_KEY="password"
136
137 # secret
138 export FRETLINK_MACAROON_SECRET=$FL_APP_SECRET
139
140 # carrier directory
141 export CARRIER_DIRECTORY_URI="$FL_CARRIER_DIRECTORY_URL"
142 export FRETLINK_CARDIR_URL="$FL_CARRIER_DIRECTORY_URL"
143 export FRETLINK_CARDIR_ENABLED="true"
144
145 # notifier
146 export FRETLINK_NOTIFIER_API=$FL_NOTIFIER_URL
147 export FRETLINK_NOTIFIER_ACCESS_KEY="$(build_macaroon --old $FL_NOTIFIER_PRIVATE_KEY notifier notifier messaging)"
148 export FRETLINK_NOTIFIER_TRANSPOREON_ACCESS_KEY="$(build_macaroon --old $FL_NOTIFIER_PRIVATE_KEY notifier notifier external)"
149 export FRETLINK_NOTIFIER_TRANSPOREON_ENABLED="true"
150
151 # admin-root
152 export FRETLINK_ADMINROOT_URL=$FL_ADMIN_ROOT_URL
153 export FRETLINK_ADMINROOT_ACCESS_KEY="$(build_macaroon $FL_ADMIN_ROOT_PRIVATE_KEY admin-root admin-root admin-root::token-delivery)"
154
155 # geodata
156 export FRETLINK_GEODATA_API="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/GeodataDev subkey=Url') }}"
157 export FRETLINK_GEODATA_ACCESS_KEY="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/GeodataDev') }}"
158 fi
159
160 if [ "$APP" = "admin-root" ]; then
161 export BASE_URL=$FL_APPS_HOST
162 export API_ROOT="http://$BASE_URL:$PORT/api"
163 export UI_ROOT="http://$BASE_URL:$PORT/admin"
164 export TOK="$(build_macaroon $FL_ADMIN_ROOT_PRIVATE_KEY admin-root admin-root admin-root::provisioning)"
165
166 export CARDIR_MACAROON_SECRET=$FL_CARRIER_DIRECTORY_SECRET
167 export NOTIFIER_MACAROON_SECRET=$FL_NOTIFIER_SECRET
168 export BOOKKEEPING_MACAROON_SECRET=$FL_BOOKKEEPING_SECRET
169 fi
170
171 if [ "$APP" = "carrier-directory" ]; then
172 export ADMIN_BASE_URL=$FL_APP_URL
173 fi
174
175 if [ "$APP" = "notifier" ]; then
176 export MAILGUN_API_KEY="dummy"
177 export MAILGUN_DOMAIN="dummy"
178 export TEMPLATES_ASSETS_BASE_URL="http://dummy/"
179 export TRANSPOREON_USER="{{ lookup('passwordstore', 'Travail/Fretlink/Transporeon/ApiTest subkey=Login') }}"
180 export TRANSPOREON_PASSWORD="{{ lookup('passwordstore', 'Travail/Fretlink/Transporeon/ApiTest') }}"
181 export TRANSPOREON_CALLBACK_USER="{{ lookup('passwordstore', 'Travail/Fretlink/Transporeon/NotifierCallbackTest subkey=Login') }}"
182 export TRANSPOREON_CALLBACK_PASSWORD="{{ lookup('passwordstore', 'Travail/Fretlink/Transporeon/NotifierCallbackTest') }}"
183
184 # Used by curl
185 # v2
186 #export MACAROON="$(build_macaroon $FL_NOTIFIER_SECRET notifier notifier external)"
187 # v1
188 export MACAROON="$(build_macaroon --old $FL_NOTIFIER_PRIVATE_KEY notifier notifier external)"
189
190 # To push transporeon cargos to app
191 APP_TRANSPOREON_PUSH_MACAROON="$(build_macaroon $FL_APP_SECRET notifier app app::transporeon-cargos-write)"
192 fi
193
194 if [ "$APP" = "pricer" ]; then
195 export GOOGLE_AUTH_CLIENT_ID="dummy"
196 fi
197
198 if [ "$APP" = "toolbox" ]; then
199 export AGENT_HOST=$FL_APP_URL
200 export AGENT_PATH="/"
201 export AGENT_MACAROON=$FL_TOOLBOX_AGENT_MACAROON
202 fi