summaryrefslogtreecommitdiff
path: root/bin/taler-deployment-config-generate
blob: 36e8608a602187b9a074667d76b775448a094b34 (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
#!/usr/bin/env python3
import click
import sys
from collections import OrderedDict
import json
import os
import urllib.parse
import stat
from taler_urls import get_urls, get_port


class ConfigFile:
    def __init__(self, envname, currency, exchange_pub, filename):
        self.sections = OrderedDict()
        self.envname = envname
        self.filename = filename
        self.currency = currency
        self.exchange_pub = exchange_pub

    def destroy(self):
        del self.sections
        self.sections = OrderedDict()

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

    def cfg_write(self, outdir):

        if outdir:
            fstream = open(os.path.join(outdir, self.filename), "w")
        else:
            fstream = open(sys.stdout)

        for section_name, section in self.sections.items():
            fstream.write("[" + section_name + "]" + "\n")
            for key, value in section.items():
                fstream.write(key + " = " + value + "\n")
            fstream.write("\n")
        fstream.close()


def coin(
    obj,
    name,
    value,
    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_" + obj.currency + "_" + name
    obj.cfg_put(sec, "value", obj.currency + ":" + value)
    obj.cfg_put(sec, "duration_withdraw", d_withdraw)
    obj.cfg_put(sec, "duration_spend", d_spend)
    obj.cfg_put(sec, "duration_legal", d_legal)
    obj.cfg_put(sec, "fee_withdraw", obj.currency + ":" + f_withdraw)
    obj.cfg_put(sec, "fee_refresh", obj.currency + ":" + f_refresh)
    obj.cfg_put(sec, "fee_refund", obj.currency + ":" + f_refund)
    obj.cfg_put(sec, "fee_deposit", obj.currency + ":" + f_deposit)
    obj.cfg_put(sec, "rsa_keysize", rsa_keysize)


def config(obj):
    urls = get_urls(obj.envname)
    obj.cfg_put("paths", "TALER_DATA_HOME", "${HOME}/taler-data")
    obj.cfg_put("paths", "TALER_RUNTIME_DIR", "${HOME}/taler-runtime")
    obj.cfg_put("taler", "CURRENCY", obj.currency)
    obj.cfg_put("taler", "CURRENCY_ROUND_UNIT", f"{obj.currency}:0.01")
    if obj.envname != "local":
        obj.cfg_put("bank", "serve", "uwsgi")
        obj.cfg_put("bank", "uwsgi_serve", "unix")
        obj.cfg_put("bank", "uwsgi_unixpath", "$HOME/sockets/bank.uwsgi")
        obj.cfg_put("bank", "uwsgi_unixpath_mode", "660")
    else:
        obj.cfg_put("bank", "serve", "http")
        obj.cfg_put("bank", "http_port", get_port(urls["bank"]))

    obj.cfg_put("bank", "database", "taler" + obj.envname)
    obj.cfg_put("bank", "max_debt", "%s:500.0" % obj.currency)
    obj.cfg_put("bank", "max_debt_bank", "%s:1000000000.0" % obj.currency)
    obj.cfg_put("bank", "allow_registrations", "YES")
    obj.cfg_put("bank", "base_url", urls["bank"])
    obj.cfg_put("bank", "database", "postgres:///taler{}".format(obj.envname))
    obj.cfg_put("bank", "suggested_exchange", urls["exchange"])

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

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

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

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

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

    obj.cfg_put("backoffice-all", "backend", urls["merchant_backend"])

    # Keep only one back-office service for all instances, for simplicity.
    obj.cfg_put("backoffice-all", "uwsgi_serve", "unix")
    obj.cfg_put("backoffice-all", "uwsgi_unixpath_mode", "660")
    obj.cfg_put("backoffice-all", "uwsgi_unixpath", "$HOME/sockets/backoffice.uwsgi")
    obj.cfg_put("backoffice-all", "instances", "FSF default Tor")

    if obj.envname != "local":
        obj.cfg_put("merchant", "serve", "unix")
        obj.cfg_put("merchant", "unixpath", "$HOME/sockets/merchant.http")
    else:
        obj.cfg_put("merchant", "serve", "tcp")
        obj.cfg_put("merchant", "port", get_port(urls["merchant_backend"]))

    obj.cfg_put("merchant", "wire_transfer_delay", "0 s")
    obj.cfg_put("merchant", "default_max_wire_fee", obj.currency + ":" + "0.01")
    obj.cfg_put("merchant", "default_max_deposit_fee", obj.currency + ":" + "0.05")
    obj.cfg_put(
        "merchantdb-postgres", "config", "postgres:///taler{}".format(obj.envname)
    )

    obj.cfg_put("frontends", "backend", urls["merchant_backend"])

    obj.cfg_put(
        "merchant-exchange-{}".format(obj.currency), "master_key", obj.exchange_pub
    )
    obj.cfg_put("merchant-exchange-{}".format(obj.currency), "currency", obj.currency)

    obj.cfg_put(
        "merchant-exchange-{}".format(obj.currency),
        "exchange_base_url",
        urls["exchange"],
    )
    obj.cfg_put("auditor", "serve", "unix")
    obj.cfg_put("auditor", "auditor_url", urls["auditor"])
    obj.cfg_put("auditor", "unixpath", "$HOME/sockets/auditor.http")
    obj.cfg_put("auditor", "tiny_amount", obj.currency + ":0.01")

    obj.cfg_put("taler-exchange-secmod-eddsa", "unixpath", "$HOME/sockets/taler-exchange-secmod-eddsa.sock")
    obj.cfg_put("taler-exchange-secmod-rsa", "unixpath", "$HOME/sockets/taler-exchange-secmod-rsa.sock")

    obj.cfg_put("exchange", "base_url", urls["exchange"])

    if obj.envname != "local":
        obj.cfg_put("exchange", "serve", "unix")
        obj.cfg_put("exchange", "unixpath", "$HOME/sockets/exchange.http")
    else:
        obj.cfg_put("exchange", "serve", "tcp")
        obj.cfg_put("exchange", "port", get_port(urls["exchange"]))

    obj.cfg_put("exchange", "master_public_key", obj.exchange_pub)
    obj.cfg_put("exchange", "terms_etag", "0")
    obj.cfg_put("exchange", "terms_dir", "$HOME/local/share/taler-exchange/tos")

    obj.cfg_put(
        "exchangedb-postgres", "db_conn_str", "postgres:///taler{}".format(obj.envname)
    )
    obj.cfg_put(
        "exchangedb-postgres", "config", "postgres:///taler{}".format(obj.envname)
    )
    obj.cfg_put(
        "auditordb-postgres", "db_conn_str", "postgres:///taler{}".format(obj.envname)
    )
    obj.cfg_put(
        "auditordb-postgres", "config", "postgres:///taler{}".format(obj.envname)
    )

    bank_acct_url = "{}taler-wire-gateway/Exchange/".format(urls["bank"])

    obj.cfg_put(
        "exchange-account-1", "payto_uri", "{}Exchange".format(urls["talerbank_payto"])
    )
    obj.cfg_put("exchange-account-1", "wire_gateway_auth_method", "basic")
    obj.cfg_put("exchange-account-1", "wire_gateway_url", bank_acct_url)
    obj.cfg_put("exchange-account-1", "username", "Exchange")
    obj.cfg_put("exchange-account-1", "password", "x")
    obj.cfg_put("exchange-account-1", "enable_debit", "yes")
    obj.cfg_put("exchange-account-1", "enable_credit", "yes")

    obj.cfg_put(
        "merchant-account-merchant",
        "payto_uri",
        "{}Tutorial".format(urls["talerbank_payto"]),
    )
    obj.cfg_put(
        "merchant-account-merchant",
        "wire_response",
        "${TALER_DATA_HOME}/merchant/wire/merchant.json",
    )
    obj.cfg_put("merchant-account-merchant", "wire_file_mode", "770")

    # The following block should be obsoleted by the new API to configure instances.
    merchant_instance_names = ("default", "Tor", "GNUnet", "Taler", "FSF", "Tutorial")
    for mi in merchant_instance_names:
        obj.cfg_put("merchant-account-merchant", f"HONOR_{mi}", "YES")
        obj.cfg_put("merchant-account-merchant", f"ACTIVE_{mi}", "YES")

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


@click.command()
@click.option("--currency", default="KUDOS")
@click.option("--envname", default="demo")
@click.option("--outdir", required=True)
@click.option("--exchange-pub", required=True)
# Expected to contain already the 'secret-token:' scheme.
@click.option("--frontends-apitoken", required=True)
def main(currency, envname, outdir, exchange_pub, frontends_apitoken):

    if envname not in ("tanker", "demo", "test", "int", "euro", "chf", "local"):
        print("envname (%s) not demo/test/int, aborting config generation" % envname)
        return

    config_files = []

    mc = ConfigFile(envname, currency, exchange_pub, "taler.conf")
    mc.cfg_put("frontends", "backend_apikey", f"{frontends_apitoken}")
    config(mc)
    config_files.append(mc)

    urls = get_urls(envname)
    sc = ConfigFile(envname, currency, exchange_pub, "sync.conf")
    sc.cfg_put("taler", "currency", sc.currency)
    sc.cfg_put("sync", "serve", "unix")
    sc.cfg_put("sync", "unixpath", "$HOME/sockets/sync.http")
    sc.cfg_put("sync", "annual_fee", sc.currency + ":0.1")
    sc.cfg_put("sync", "fulfillment_url", "taler://fulfillment-success/")
    sc.cfg_put("sync", "payment_backend_url", urls["merchant_backend"] + "instances/Taler/")
    sc.cfg_put("syncdb-postgres", "config", "postgres:///taler%s" % envname)
    config_files.append(sc)

    assert 0 < len(config_files)
    for obj in config_files:
        obj.cfg_write(outdir)


if __name__ == "__main__":
    main()