summaryrefslogtreecommitdiff
path: root/config/generate-config
blob: 07bf864938bd4ef3c3ca210e133c19460cf98c51 (plain)
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#!/usr/bin/env python3
import click
import sys
from collections import OrderedDict
import json
import os
import urllib.parse
import stat

sections = OrderedDict()

def cfg_put(section_name, key, value):
    s = sections[section_name] = sections.get(section_name, OrderedDict())
    s[key] = value

def cfg_write(file):
    for section_name, section in sections.items():
        file.write("[" + section_name + "]" + "\n")
        for key, value in section.items():
            file.write(key + " = " + value + "\n")
        file.write("\n")

def coin(currency,
        name,
        value,
        d_overlap="5 minutes",
        d_withdraw="3 years",
        d_spend="5 years",
        d_legal="10 years",
        f_withdraw="0.01",
        f_deposit="0.01",
        f_refresh="0.01",
        f_refund="0.01",
        rsa_keysize="2048"):
    sec = "coin_"+currency+"_"+name
    cfg_put(sec, "value", currency+":"+value)
    cfg_put(sec, "duration_overlap", d_overlap)
    cfg_put(sec, "duration_withdraw", d_withdraw)
    cfg_put(sec, "duration_spend", d_spend)
    cfg_put(sec, "duration_legal", d_legal)
    cfg_put(sec, "fee_withdraw", currency+":"+f_withdraw)
    cfg_put(sec, "fee_refresh", currency+":"+f_refresh)
    cfg_put(sec, "fee_refund", currency+":"+f_refund)
    cfg_put(sec, "fee_deposit", currency+":"+f_deposit)
    cfg_put(sec, "rsa_keysize", rsa_keysize)

def config(currency, envname, exchange_pub, standalone):
    cfg_put("paths", "TALER_DEPLOYMENT_SHARED", "${HOME}/shared-data")
    cfg_put("taler", "CURRENCY", currency)

    cfg_put("bank", "uwsgi_serve", "unix")
    cfg_put("bank", "uwsgi_unixpath", "$HOME/sockets/bank.uwsgi")
    cfg_put("bank", "uwsgi_unixpath_mode", "660")
    cfg_put("bank", "database", "taler"+envname)
    cfg_put("bank", "max_debt", "%s:0.0" % currency)
    cfg_put("bank", "max_debt_bank", "%s:0.0" % currency)
    if standalone:
        cfg_put("bank", "database", "postgres:///taler?host={}/sockets".format(os.getenv("HOME")))
    else:
        cfg_put("bank", "database", "postgres:///taler{}".format(envname))

    if standalone:
        cfg_put("bank", "suggested_exchange", "https://env.taler.net/{}/exchange/".format(envname))
    else:
        cfg_put("bank", "suggested_exchange", "https://exchange.{}.taler.net/".format(envname))


    cfg_put("bank-admin", "uwsgi_serve", "unix")
    cfg_put("bank-admin", "uwsgi_unixpath", "$HOME/sockets/bank-admin.uwsgi")
    cfg_put("bank-admin", "uwsgi_unixpath_mode", "660")

    cfg_put("donations", "uwsgi_serve", "unix")
    cfg_put("donations", "uwsgi_unixpath", "$HOME/sockets/donations.uwsgi")
    cfg_put("donations", "uwsgi_unixpath_mode", "660")

    cfg_put("survey", "uwsgi_serve", "unix")
    cfg_put("survey", "uwsgi_unixpath", "$HOME/sockets/survey.uwsgi")
    cfg_put("survey", "uwsgi_unixpath_mode", "660")

    cfg_put("blog", "uwsgi_serve", "unix")
    cfg_put("blog", "uwsgi_unixpath", "$HOME/sockets/shop.uwsgi")
    cfg_put("blog", "uwsgi_unixpath_mode", "660")
    cfg_put("blog", "instance", "FSF")

    cfg_put("playground", "uwsgi_serve", "unix")
    cfg_put("playground", "uwsgi_unixpath", "$HOME/sockets/playground.uwsgi")
    cfg_put("playground", "uwsgi_unixpath_mode", "660")

    if standalone:
        cfg_put("backoffice-blog", "backend", "https://env.taler.net/{}/merchant-backend/".format(envname))
        cfg_put("backoffice-donations", "backend", "https://env.taler.net/{}/merchant-backend/".format(envname))
    else:
        cfg_put("backoffice-blog", "backend", "https://backend.{}.taler.net/".format(envname))
        cfg_put("backoffice-donations", "backend", "https://backend.{}.taler.net/".format(envname))

    cfg_put("merchant", "wireformat", "test")
    cfg_put("merchant", "serve", "unix")
    cfg_put("merchant", "unixpath", "$HOME/sockets/merchant.http")
    cfg_put("merchant", "wire_transfer_delay", "1 m")
    cfg_put("merchant", "default_max_wire_fee", currency + ":" + "0.01")
    cfg_put("merchant", "default_max_deposit_fee", currency + ":" + "0.05")

    if standalone:
        cfg_put("merchantdb-postgres", "config", "postgres:///taler?host={}/sockets".format(os.getenv("HOME")))
    else:
        cfg_put("merchantdb-postgres", "config", "postgres:///taler{}".format(envname))

    if standalone:
        cfg_put("merchant-exchange-test", "url", "https://env.taler.net/{}/exchange/".format(envname))
    else:
        cfg_put("merchant-exchange-test", "url", "https://exchange.{}.taler.net/".format(envname))

    cfg_put("merchant-exchange-test", "master_key", exchange_pub)

    cfg_put("frontends", "backend_apikey", "sandbox".format(envname))

    if standalone:
        cfg_put("frontends", "backend", "https://env.taler.net/{}/merchant-backend/".format(os.getenv("USER")))
    else:
        cfg_put("frontends", "backend", "https://backend.{}.taler.net/".format(envname))

    cfg_put("exchange-{}".format(currency), "master_key", exchange_pub)
    cfg_put("exchange-{}".format(currency), "currency", currency)
    if standalone:
        cfg_put("exchange-{}".format(currency), "base_url", "https://env.taler.net/{}/exchange".format(os.getenv("USER")))
    else:
        cfg_put("exchange-{}".format(currency), "base_url", "https://exchange.{}.taler.net/".format(envname))

    cfg_put("auditor", "auditor_priv_file", "${TALER_DEPLOYMENT_SHARED}/auditor/offline-keys/auditor.priv")

    cfg_put("exchange", "base_url", "https://exchange.{}.taler.net/".format(envname))
    cfg_put("exchange", "serve", "unix")
    cfg_put("exchange", "unixpath", "$HOME/sockets/exchange.http")
    cfg_put("exchange", "master_public_key", exchange_pub)

    cfg_put("exchange", "master_priv_file", "${TALER_DEPLOYMENT_SHARED}/exchange/offline-keys/master.priv")
    cfg_put("exchange", "keydir", "${TALER_DEPLOYMENT_SHARED}/exchange/live-keys/")

    cfg_put("exchangedb", "auditor_base_dir", "${TALER_DEPLOYMENT_SHARED}/exchange/auditors/")
    cfg_put("exchangedb", "wirefee_base_dir", "${TALER_DEPLOYMENT_SHARED}/exchange/wirefees/")

    if standalone:
        cfg_put("exchangedb-postgres", "db_conn_str", "postgres:///taler?host={}/sockets".format(os.getenv("HOME")))
        cfg_put("exchangedb-postgres", "config", "postgres:///taler?host={}/sockets".format(os.getenv("HOME")))
        cfg_put("auditordb-postgres", "db_conn_str", "postgres:///taler?host={}/sockets".format(os.getenv("HOME")))
        cfg_put("auditordb-postgres", "config", "postgres:///taler?host={}/sockets".format(os.getenv("HOME")))
    else:
        cfg_put("exchangedb-postgres", "db_conn_str", "postgres:///taler{}".format(envname))
        cfg_put("exchangedb-postgres", "config", "postgres:///taler{}".format(envname))
        cfg_put("auditordb-postgres", "db_conn_str", "postgres:///taler{}".format(envname))
        cfg_put("auditordb-postgres", "config", "postgres:///taler{}".format(envname))

    if standalone:
        cfg_put("account-1", "url", "payto://x-taler-bank/env.taler.net/{}/bank/2".format(envname))
    else:
        cfg_put("account-1", "url", "payto://x-taler-bank/bank.{}.taler.net/2".format(envname))

    cfg_put("account-1", "wire_response", "${TALER_DEPLOYMENT_SHARED}/exchange/wire/test.json")
    cfg_put("account-1", "plugin", "taler_bank")
    cfg_put("account-1", "taler_bank_auth_method", "basic")
    cfg_put("account-1", "username", "user")
    cfg_put("account-1", "password", "pass")
    cfg_put("account-1", "enable_debit", "yes")
    cfg_put("account-1", "enable_credit", "yes")

    cfg_put("fees-x-taler-bank", "wire-fee-2018", currency + ":" + "0.02")
    cfg_put("fees-x-taler-bank", "wire-fee-2019", currency + ":" + "0.03")
    cfg_put("fees-x-taler-bank", "wire-fee-2020", currency + ":" + "0.04")
    cfg_put("fees-x-taler-bank", "wire-fee-2021", currency + ":" + "0.04")
    cfg_put("fees-x-taler-bank", "wire-fee-2022", currency + ":" + "0.05")
    cfg_put("fees-x-taler-bank", "wire-fee-2023", currency + ":" + "0.06")
    cfg_put("fees-x-taler-bank", "wire-fee-2024", currency + ":" + "0.07")
    cfg_put("fees-x-taler-bank", "wire-fee-2025", currency + ":" + "0.08")

    cfg_put("fees-x-taler-bank", "closing-fee-2018", currency + ":" + "0.01")
    cfg_put("fees-x-taler-bank", "closing-fee-2019", currency + ":" + "0.01")
    cfg_put("fees-x-taler-bank", "closing-fee-2020", currency + ":" + "0.01")
    cfg_put("fees-x-taler-bank", "closing-fee-2021", currency + ":" + "0.01")
    cfg_put("fees-x-taler-bank", "closing-fee-2022", currency + ":" + "0.01")
    cfg_put("fees-x-taler-bank", "closing-fee-2023", currency + ":" + "0.01")
    cfg_put("fees-x-taler-bank", "closing-fee-2024", currency + ":" + "0.01")
    cfg_put("fees-x-taler-bank", "closing-fee-2025", currency + ":" + "0.01")

    # how long is one signkey valid?
    cfg_put("exchange_keys", "signkey_duration", "18 weeks")

    # how long are the signatures with the signkey valid?
    cfg_put("exchange_keys", "legal_duration", "2 years")

    # how long do we generate denomination and signing keys
    # ahead of time?
    cfg_put("exchange_keys", "lookahead_sign", "32 weeks 1 day")

    cfg_put("exchange_keys", "lookahead_provide", "4 weeks 1 day")

    # instance FSF
    cfg_put("merchant-instance-FSF", "keyfile", "${TALER_DEPLOYMENT_SHARED}/merchant/fsf.priv")
    cfg_put("merchant-instance-FSF", "name", "Free Software Foundation")
    cfg_put("merchant-location-FSF-address", "street", "51 Franklin Street, Fifth Floor.")
    cfg_put("merchant-location-FSF-address", "city", "Boston")
    cfg_put("merchant-location-FSF-address", "country", "USA")
    # instance Tor
    cfg_put("merchant-instance-Tor", "keyfile", "${TALER_DEPLOYMENT_SHARED}/merchant/tor.priv")
    cfg_put("merchant-instance-Tor", "name", "The Tor Project")
    # instance GNUnet
    cfg_put("merchant-instance-GNUnet", "keyfile", "${TALER_DEPLOYMENT_SHARED}/merchant/gnunet.priv")
    cfg_put("merchant-instance-GNUnet", "name", "GNUnet Project")
    # instance Taler
    cfg_put("merchant-instance-Taler", "keyfile", "${TALER_DEPLOYMENT_SHARED}/merchant/taler.priv")
    cfg_put("merchant-instance-Taler", "name", "Taler")
    # instance default
    cfg_put("merchant-instance-default", "keyfile", "${TALER_DEPLOYMENT_SHARED}/merchant/default.priv")
    cfg_put("merchant-instance-default", "name", "Kudos Inc.")
    cfg_put("merchant-location-default-address", "country", "Kudosland")
    cfg_put("merchant-instance-default", "tip_reserve_priv_filename", "${TALER_DEPLOYMENT_SHARED}/merchant/default-tip.priv")
    cfg_put("merchant-instance-default", "tip_exchange", "https://exchange.{}.taler.net/".format(envname))
    # instance tutorial
    cfg_put("merchant-instance-tutorial", "keyfile", "${TALER_DEPLOYMENT_SHARED}/merchant/tutorial.priv")
    cfg_put("merchant-instance-tutorial", "name", "Tutorial")

    cfg_put("merchant-instance-wireformat-Tor", "test_response_file", "${TALER_DEPLOYMENT_SHARED}/merchant/wire/tor.json")
    cfg_put("merchant-instance-wireformat-GNUnet", "test_response_file", "${TALER_DEPLOYMENT_SHARED}/merchant/wire/gnunet.json")
    cfg_put("merchant-instance-wireformat-Taler", "test_response_file", "${TALER_DEPLOYMENT_SHARED}/merchant/wire/taler.json")
    cfg_put("merchant-instance-wireformat-FSF", "test_response_file", "${TALER_DEPLOYMENT_SHARED}/merchant/wire/fsf.json")
    cfg_put("merchant-instance-wireformat-default", "test_response_file", "${TALER_DEPLOYMENT_SHARED}/merchant/wire/default.json")
    cfg_put("merchant-instance-wireformat-tutorial", "test_response_file", "${TALER_DEPLOYMENT_SHARED}/merchant/wire/default.json")

    coin(currency, "ct_10", "0.10")
    coin(currency, "1", "1")
    coin(currency, "2", "2")
    coin(currency, "5", "5")
    coin(currency, "10", "10")
    coin(currency, "1000", "1000")


def merchant_wf(envname, instance_name, acct_no, standalone):
    if standalone:
        bank_url = "https://env.taler.net/{}/bank/".format(envname)
    else:
        bank_url = "https://bank.{}.taler.net/".format(envname)
    data = OrderedDict(
        type="test",
        bank_url=bank_url,
        sig="MERCHANTSIGNATURE",
        account_number=acct_no,
        salt="SALT"
    )

    return (instance_name, json.dumps(data, indent=2))

def exchange_wf(envname, wfname, acct_no, name, standalone):
    if standalone:
        bank_url = "https://env.taler.net/{}/bank/".format(envname)
    else:
        bank_url = "https://bank.{}.taler.net/".format(envname)

    bank_host = urllib.parse.urlparse(bank_url).netloc
    data = OrderedDict(
        name=name,
        type=wfname,
        bank_url=bank_url,
        account_number=acct_no,
        account_url="payto://x-taler-bank/{}/{}".format(bank_host, acct_no)
    )
    return (wfname, json.dumps(data, indent=2))

@click.command()
@click.option("--currency", default="KUDOS")
@click.option("--envname", default="demo")
@click.option("--outdir", default=None)
@click.option("--shared-outdir", default=None)
@click.option("--standalone", default=None, help="Enable a standalone/env deployment instead of test/demo")
@click.option("--exchange-pub", required=True)
def main(currency, envname, outdir, shared_outdir, exchange_pub, standalone):

    if not standalone:
        if envname not in ("demo", "test"):
            print("envname {} not supported unless in standalone mode".format(envname))
            return

    # We have the --standalone option as 0/1 instead of as a flag,
    # since this way it's easier to read it from an environment variable
    # in shell scripts.
    if standalone == "1":
        standalone = True
    else:
        standalone = False

    config(currency, envname, exchange_pub, standalone)

    merchant_wireformats = [
        merchant_wf(envname, "gnunet", 4, standalone),
        merchant_wf(envname, "taler", 5, standalone),
        merchant_wf(envname, "tor", 3, standalone),
        merchant_wf(envname, "fsf", 6, standalone),
        merchant_wf(envname, "default", 7, standalone),
    ]

    exchange_wireformats = [
        exchange_wf(envname, "test", 2, "The exchange", standalone)
    ]

    if outdir:
        os.makedirs(outdir, exist_ok=True)
        tc = os.path.join(outdir, "taler.conf")
        cfg_write(open(tc, "w"))

    else:
        cfg_write(sys.stdout)

    if shared_outdir:
        d = os.path.join(shared_outdir, "merchant", "wire")
        os.makedirs(d, exist_ok=True)
        for name, data in merchant_wireformats:
            f = open(os.path.join(d, name+".json"), "w")
            f.write(data)
            f.close()

        d = os.path.join(shared_outdir, "exchange", "wire")
        os.makedirs(d, exist_ok=True)
        for name, data in exchange_wireformats:
            # These files must be signed by the exchange in
            # a later step
            filename = os.path.join(d, name+".json")
            f = open(filename, "w")
            f.write(data)
            f.close()
    else:
        cfg_write(sys.stdout)

if __name__ == "__main__":
    main()