4 # URI: postgres:///db_name
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"
12 if [ "$1" = "--old" ]; then
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
28 target="uri://fretlink/$3"
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"
35 APP=$(basename $(pwd))
37 FL_APPS_HOST="localhost"
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/"
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"
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/"
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"
60 FL_PRICER_PRIVATE_KEY="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/Pricer subkey=PrivateKey') }}"
63 FL_FREIGHT_SECRET="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/Freight subkey=Secret') }}"
65 FL_BOOKKEEPING_SECRET="dummy"
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') }}"
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') }}"
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') }}"
84 FL_TOOLBOX_AGENT_MACAROON="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/ToolboxAgent') }}"
86 if [ -f "local.env.example" ]; then
87 source local.env.example
90 if [ "$APP" != "app" ]; then
92 port_var="FL_${name^^}_PORT"
93 secret_var="FL_${name^^}_SECRET"
94 private_key_var="FL_${name^^}_PRIVATE_KEY"
96 if [ -n "${!secret_var}" ]; then
97 export MACAROON_SECRET="${!secret_var}"
99 if [ -n "${!private_key_var}" ]; then
100 export MACAROON_PRIVATE_KEY="${!private_key_var}"
102 export PORT="${!port_var}"
103 export PG_URI="postgres:///$name"
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"
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}"
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"
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"
138 export FRETLINK_MACAROON_SECRET=$FL_APP_SECRET
141 export CARRIER_DIRECTORY_URI="$FL_CARRIER_DIRECTORY_URL"
142 export FRETLINK_CARDIR_URL="$FL_CARRIER_DIRECTORY_URL"
143 export FRETLINK_CARDIR_ENABLED="true"
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"
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)"
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') }}"
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)"
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
171 if [ "$APP" = "carrier-directory" ]; then
172 export ADMIN_BASE_URL=$FL_APP_URL
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') }}"
186 #export MACAROON="$(build_macaroon $FL_NOTIFIER_SECRET notifier notifier external)"
188 export MACAROON="$(build_macaroon --old $FL_NOTIFIER_PRIVATE_KEY notifier notifier external)"
190 # To push transporeon cargos to app
191 APP_TRANSPOREON_PUSH_MACAROON="$(build_macaroon $FL_APP_SECRET notifier app app::transporeon-cargos-write)"
194 if [ "$APP" = "pricer" ]; then
195 export GOOGLE_AUTH_CLIENT_ID="dummy"
198 if [ "$APP" = "toolbox" ]; then
199 export AGENT_HOST=$FL_APP_URL
200 export AGENT_PATH="/"
201 export AGENT_MACAROON=$FL_TOOLBOX_AGENT_MACAROON