]>
Commit | Line | Data |
---|---|---|
b7b8fe64 IB |
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 | ||
d4357f69 IB |
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 | ||
b7b8fe64 IB |
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 | ||
90b63575 | 39 | pushd "$HOME/workdir/haskell-commons" >/dev/null 2>/dev/null |
b7b8fe64 | 40 | MACAROON_PRIVATE_KEY="$secret" MACAROON_SECRET="$secret" stack exec macaroon-bakery -- $action --location "$target" --key-id "$src" $ttl "$realm" |
90b63575 | 41 | popd 2>/dev/null >/dev/null |
b7b8fe64 IB |
42 | } |
43 | ||
e7270a0e IB |
44 | function capitalize() { |
45 | echo "$1" | sed -e 's!\(^\|-\)\(.\)!\U\2!g' | |
46 | } | |
47 | ||
b7b8fe64 IB |
48 | APP=$(basename $(pwd)) |
49 | ||
50 | FL_APPS_HOST="localhost" | |
51 | FL_APPS_SCHEME="http" | |
52 | ||
53 | FL_ADMIN_ROOT_PORT=8079 | |
54 | FL_ADMIN_ROOT_PRIVATE_KEY="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/AdminRoot subkey=PrivateKey') }}" | |
55 | FL_ADMIN_ROOT_URL="$FL_APPS_SCHEME://$FL_APPS_HOST:$FL_ADMIN_ROOT_PORT/api/" | |
56 | ||
57 | FL_APP_PORT=8080 | |
58 | FL_APP_MONGO_URI="mongodb://localhost:27017/fretlink" | |
59 | FL_APP_SECRET="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/App subkey=Secret') }}" | |
60 | FL_APP_URL="$FL_APPS_SCHEME://$FL_APPS_HOST:$FL_APP_PORT" | |
61 | ||
62 | FL_CARRIER_DIRECTORY_PORT=8082 | |
63 | FL_CARRIER_DIRECTORY_SECRET="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/CarrierDirectory subkey=Secret') }}" | |
64 | FL_CARRIER_DIRECTORY_PRIVATE_KEY="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/CarrierDirectory subkey=PrivateKey') }}" | |
bf4da466 | 65 | FL_CARRIER_DIRECTORY_URL="$FL_APPS_SCHEME://$FL_APPS_HOST:$FL_CARRIER_DIRECTORY_PORT/api" |
b7b8fe64 IB |
66 | |
67 | FL_NOTIFIER_PORT=8081 | |
68 | FL_NOTIFIER_SECRET="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/Notifier subkey=Secret') }}" | |
69 | FL_NOTIFIER_PRIVATE_KEY="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/Notifier subkey=PrivateKey') }}" | |
70 | FL_NOTIFIER_URL="$FL_APPS_SCHEME://$FL_APPS_HOST:$FL_NOTIFIER_PORT/api" | |
71 | ||
72 | FL_PRICER_PORT=8083 | |
73 | FL_PRICER_PRIVATE_KEY="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/Pricer subkey=PrivateKey') }}" | |
74 | ||
75 | FL_FREIGHT_PORT=8084 | |
76 | FL_FREIGHT_SECRET="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/Freight subkey=Secret') }}" | |
77 | ||
78 | FL_BOOKKEEPING_SECRET="dummy" | |
39894a77 | 79 | FL_LANE_EXPLORER_SECRET="dummy" |
b7b8fe64 IB |
80 | |
81 | FL_PSQL_HOST="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Local subkey=Host') }}" | |
82 | FL_PSQL_PORT="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Local subkey=Port') }}" | |
83 | FL_PSQL_USER="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Local subkey=User') }}" | |
84 | FL_PSQL_PASSWORD="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Local') }}" | |
85 | ||
b7b8fe64 IB |
86 | FL_TOOLBOX_AGENT_MACAROON="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/ToolboxAgent') }}" |
87 | ||
e7270a0e IB |
88 | export FRETLINK_ENV="$APP ${FL_ENV:-local}" |
89 | ||
b7b8fe64 IB |
90 | if [ -f "local.env.example" ]; then |
91 | source local.env.example | |
92 | fi | |
93 | ||
94 | if [ "$APP" != "app" ]; then | |
95 | name="${APP//-/_}" | |
96 | port_var="FL_${name^^}_PORT" | |
97 | secret_var="FL_${name^^}_SECRET" | |
98 | private_key_var="FL_${name^^}_PRIVATE_KEY" | |
99 | ||
100 | if [ -n "${!secret_var}" ]; then | |
101 | export MACAROON_SECRET="${!secret_var}" | |
102 | fi | |
103 | if [ -n "${!private_key_var}" ]; then | |
104 | export MACAROON_PRIVATE_KEY="${!private_key_var}" | |
105 | fi | |
106 | export PORT="${!port_var}" | |
107 | export PG_URI="postgres:///$name" | |
108 | ||
109 | if [ -z "$FL_ENV" ]; then | |
110 | export POSTGRESQL_ADDON_HOST="$FL_PSQL_HOST" | |
111 | export POSTGRESQL_ADDON_PORT="$FL_PSQL_PORT" | |
112 | export POSTGRESQL_ADDON_USER="$FL_PSQL_USER" | |
113 | export POSTGRESQL_ADDON_PASSWORD="$FL_PSQL_PASSWORD" | |
114 | export POSTGRESQL_ADDON_DB="$name" | |
115 | else | |
e7270a0e IB |
116 | key=Psql/$(capitalize $FL_ENV)/$(capitalize $APP) |
117 | export POSTGRESQL_ADDON_HOST=$(p $key Host) | |
118 | export POSTGRESQL_ADDON_PORT=$(p $key Port) | |
119 | export POSTGRESQL_ADDON_USER=$(p $key User) | |
120 | export POSTGRESQL_ADDON_PASSWORD=$(p $key) | |
121 | export POSTGRESQL_ADDON_DB=$(p $key Database) | |
b7b8fe64 IB |
122 | fi |
123 | fi | |
124 | ||
125 | if [ "$APP" = "app" ]; then | |
126 | export FRETLINK_MONGO_URI="$FL_APP_MONGO_URI" | |
127 | export FRETLINK_PORT="$FL_APP_PORT" | |
128 | export FRETLINK_BASE_URL="$FL_APP_URL" | |
129 | ||
130 | # Dummies mandatory but not defined by default | |
131 | export FRETLINK_SMTP_PASSWORD="password" | |
132 | export FRETLINK_AMAZON_PUBLIC_KEY="password" | |
133 | export FRETLINK_AMAZON_PRIVATE_KEY="password" | |
134 | export FRETLINK_GMAPS_API_KEY="password" | |
bf4da466 | 135 | export FRETLINK_PASSWORD_REQUEST_SECRET="password" |
b7b8fe64 IB |
136 | |
137 | # secret | |
138 | export FRETLINK_MACAROON_SECRET=$FL_APP_SECRET | |
139 | ||
140 | # carrier directory | |
bf4da466 | 141 | export CARRIER_DIRECTORY_URI="$FL_CARRIER_DIRECTORY_URL/" |
b7b8fe64 IB |
142 | export FRETLINK_CARDIR_URL="$FL_CARRIER_DIRECTORY_URL" |
143 | export FRETLINK_CARDIR_ENABLED="true" | |
bf4da466 | 144 | export FRETLINK_CARDIRV3_ACCESS_KEY="$(build_macaroon $FL_CARRIER_DIRECTORY_SECRET carrier-directory carrier-directory carrier-directory::read)" |
b7b8fe64 IB |
145 | |
146 | # notifier | |
147 | export FRETLINK_NOTIFIER_API=$FL_NOTIFIER_URL | |
39894a77 | 148 | export FRETLINK_NOTIFIER_ACCESS_KEY="$(build_macaroon $FL_NOTIFIER_SECRET notifier notifier messaging)" |
b7b8fe64 IB |
149 | export FRETLINK_NOTIFIER_TRANSPOREON_ACCESS_KEY="$(build_macaroon --old $FL_NOTIFIER_PRIVATE_KEY notifier notifier external)" |
150 | export FRETLINK_NOTIFIER_TRANSPOREON_ENABLED="true" | |
151 | ||
39894a77 IB |
152 | export FRETLINK_NOTIFIER_ENABLED="true" |
153 | export FRETLINK_NOTIFIER_AMQP_ENABLED="true" | |
154 | export FRETLINK_NOTIFIER_AMQP_TLS="{{ lookup('passwordstore', 'Travail/Fretlink/Rabbitmq/Local/Notifier subkey=TLS') }}" | |
155 | export FRETLINK_NOTIFIER_AMQP_USER="{{ lookup('passwordstore', 'Travail/Fretlink/Rabbitmq/Local/Notifier subkey=User') }}" | |
156 | export FRETLINK_NOTIFIER_AMQP_PASSWORD="{{ lookup('passwordstore', 'Travail/Fretlink/Rabbitmq/Local/Notifier') }}" | |
157 | export FRETLINK_NOTIFIER_AMQP_HOSTS="{{ lookup('passwordstore', 'Travail/Fretlink/Rabbitmq/Local/Notifier subkey=Hosts') }}" | |
158 | export FRETLINK_NOTIFIER_AMQP_QUEUE="{{ lookup('passwordstore', 'Travail/Fretlink/Rabbitmq/Local/Notifier subkey=Queue') }}" | |
159 | export FRETLINK_NOTIFIER_AMQP_EXCHANGE="{{ lookup('passwordstore', 'Travail/Fretlink/Rabbitmq/Local/Notifier subkey=Exchange') }}" | |
160 | export FRETLINK_NOTIFIER_AMQP_PORT="{{ lookup('passwordstore', 'Travail/Fretlink/Rabbitmq/Local/Notifier subkey=Port') }}" | |
161 | export FRETLINK_NOTIFIER_AMQP_VHOST="{{ lookup('passwordstore', 'Travail/Fretlink/Rabbitmq/Local/Notifier subkey=Vhost') }}" | |
162 | ||
163 | ||
b7b8fe64 IB |
164 | # admin-root |
165 | export FRETLINK_ADMINROOT_URL=$FL_ADMIN_ROOT_URL | |
166 | export FRETLINK_ADMINROOT_ACCESS_KEY="$(build_macaroon $FL_ADMIN_ROOT_PRIVATE_KEY admin-root admin-root admin-root::token-delivery)" | |
167 | ||
168 | # geodata | |
169 | export FRETLINK_GEODATA_API="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/GeodataDev subkey=Url') }}" | |
170 | export FRETLINK_GEODATA_ACCESS_KEY="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/GeodataDev') }}" | |
bf4da466 | 171 | export GEODATA_URI="$FRETLINK_GEODATA_API" |
b7b8fe64 IB |
172 | fi |
173 | ||
174 | if [ "$APP" = "admin-root" ]; then | |
175 | export BASE_URL=$FL_APPS_HOST | |
176 | export API_ROOT="http://$BASE_URL:$PORT/api" | |
177 | export UI_ROOT="http://$BASE_URL:$PORT/admin" | |
178 | export TOK="$(build_macaroon $FL_ADMIN_ROOT_PRIVATE_KEY admin-root admin-root admin-root::provisioning)" | |
179 | ||
180 | export CARDIR_MACAROON_SECRET=$FL_CARRIER_DIRECTORY_SECRET | |
181 | export NOTIFIER_MACAROON_SECRET=$FL_NOTIFIER_SECRET | |
182 | export BOOKKEEPING_MACAROON_SECRET=$FL_BOOKKEEPING_SECRET | |
39894a77 | 183 | export LANE_EXPLORER_MACAROON_SECRET=$FL_LANE_EXPLORER_SECRET |
b7b8fe64 IB |
184 | fi |
185 | ||
186 | if [ "$APP" = "carrier-directory" ]; then | |
187 | export ADMIN_BASE_URL=$FL_APP_URL | |
bf4da466 | 188 | export ACCESS_KEY="$(build_macaroon $FL_CARRIER_DIRECTORY_SECRET carrier-directory carrier-directory carrier-directory::read)" |
b7b8fe64 IB |
189 | fi |
190 | ||
191 | if [ "$APP" = "notifier" ]; then | |
192 | export MAILGUN_API_KEY="dummy" | |
193 | export MAILGUN_DOMAIN="dummy" | |
194 | export TEMPLATES_ASSETS_BASE_URL="http://dummy/" | |
195 | export TRANSPOREON_USER="{{ lookup('passwordstore', 'Travail/Fretlink/Transporeon/ApiTest subkey=Login') }}" | |
196 | export TRANSPOREON_PASSWORD="{{ lookup('passwordstore', 'Travail/Fretlink/Transporeon/ApiTest') }}" | |
d4357f69 | 197 | export TRANSPOREON_HOST="api.test.transporeon.com" |
b7b8fe64 IB |
198 | export TRANSPOREON_CALLBACK_USER="{{ lookup('passwordstore', 'Travail/Fretlink/Transporeon/NotifierCallbackTest subkey=Login') }}" |
199 | export TRANSPOREON_CALLBACK_PASSWORD="{{ lookup('passwordstore', 'Travail/Fretlink/Transporeon/NotifierCallbackTest') }}" | |
200 | ||
201 | # Used by curl | |
202 | # v2 | |
203 | #export MACAROON="$(build_macaroon $FL_NOTIFIER_SECRET notifier notifier external)" | |
204 | # v1 | |
205 | export MACAROON="$(build_macaroon --old $FL_NOTIFIER_PRIVATE_KEY notifier notifier external)" | |
206 | ||
207 | # To push transporeon cargos to app | |
90b63575 IB |
208 | export TRANSPOREON_APP_PUSH_URL="http://localhost:8080/api/transporeon/cargo" |
209 | export TRANSPOREON_APP_PUSH_MACAROON="$(build_macaroon $FL_APP_SECRET notifier app app::transporeon-cargos-write)" | |
39894a77 IB |
210 | |
211 | # AMQP | |
212 | export AMQP_VHOST="notifier" | |
213 | export AMQP_USER="notifier" | |
214 | export AMQP_PASSWORD="notifier" | |
215 | export AMQP_QUEUE="notifier" | |
216 | export AMQP_SERVER="localhost" | |
217 | export AMQP_TLS="false" | |
b7b8fe64 IB |
218 | fi |
219 | ||
220 | if [ "$APP" = "pricer" ]; then | |
221 | export GOOGLE_AUTH_CLIENT_ID="dummy" | |
222 | fi | |
223 | ||
224 | if [ "$APP" = "toolbox" ]; then | |
225 | export AGENT_HOST=$FL_APP_URL | |
226 | export AGENT_PATH="/" | |
227 | export AGENT_MACAROON=$FL_TOOLBOX_AGENT_MACAROON | |
228 | fi |