summaryrefslogtreecommitdiff
path: root/config/generate-config
blob: 5956602957c32ef6ad5262dc2fa9cc41543de242 (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
#!/usr/bin/env python3
import click
import sys
from collections import OrderedDict
import json
import os

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(name,
        currency,
        value,
        d_overlap="5 minutes",
        d_withdraw="32 years",
        d_spend="5 years",
        d_legal="10 years",
        f_withdraw="0.10",
        f_deposit="0.10",
        f_refresh="0.10",
        f_refund="0.10",
        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", f_withdraw)
    cfg_put(sec, "fee_refresh", f_refresh)
    cfg_put(sec, "fee_refund", f_refund)
    cfg_put(sec, "rsa_keysize", rsa_keysize)

def config(currency, envname, exchange_pub):
    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-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("blog", "uwsgi_serve", "unix")
    cfg_put("blog", "uwsgi_unixpath", "$HOME/sockets/donations.uwsgi")
    cfg_put("blog", "instance", "FSF")

    
    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("merchantdb-postgres", "CONFIG", "postgres:///taler")

    cfg_put("merchant-exchange-test", "URI", "https://exchange.{}.taler.net/".format(envname))
    cfg_put("merchant-exchange-test", "MASTER_KEY", exchange_pub)

    cfg_put("frontends", "BACKEND", "https://shop.{}.taler.net/backend/".format(envname))
    cfg_put("frontends", "FRACTION", "100000000")

    cfg_put("exchange", "serve", "unix")
    cfg_put("exchange", "unixpath", "$HOME/sockets/exchange.http")
    cfg_put("exchange", "master_public_key", exchange_pub)

    cfg_put("exchange", "wireformat", "test")
    cfg_put("exchange", "keydir", "${TALER_DEPLOYMENT_SHARED}/exchange/live-keys/")

    cfg_put("exchange-admin", "SERVE", "unix")
    cfg_put("exchange-admin", "unixpath", "$HOME/sockets/exchange-admin.http")

    cfg_put("exchangedb-postgres", "DB_CONN_STR", "postgres:///taler{}".format(envname))

    cfg_put("exchange-wire-outgoing-test", "bank_uri", "https://bank.{}.taler.net/".format(envname))
    cfg_put("exchange-wire-outgoing-test", "bank_account_number", "1")
    cfg_put("exchange-wire-outgoing-test", "exchange_account_number", "2")

    # 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")


    cfg_put("merchant-instance-FSF", "KEYFILE", "${TALER_DATA_HOME}/merchant/fsf.priv")
    cfg_put("merchant-instance-Tor", "KEYFILE", "${TALER_DATA_HOME}/merchant/tor.priv")
    cfg_put("merchant-instance-GNUnet", "KEYFILE", "${TALER_DATA_HOME}/merchant/gnunet.priv")
    cfg_put("merchant-instance-Taler", "KEYFILE", "${TALER_DATA_HOME}/merchant/taler.priv")
    cfg_put("merchant-instance-tutorial", "KEYFILE", "${TALER_DATA_HOME}/merchant/tutorial.priv")

    cfg_put("merchant-instance-wireformat-Tor", "TEST_RESPONSE_FILE", "${TALER_CONFIG_HOME}/merchant/wire/tor.json")
    cfg_put("merchant-instance-wireformat-GNUnet", "TEST_RESPONSE_FILE", "${TALER_CONFIG_HOME}/merchant/wire/gnunet.json")
    cfg_put("merchant-instance-wireformat-Taler", "TEST_RESPONSE_FILE", "${TALER_CONFIG_HOME}/merchant/wire/taler.json")
    cfg_put("merchant-instance-wireformat-FSF", "TEST_RESPONSE_FILE", "${TALER_CONFIG_HOME}/merchant/wire/fsf.json")
    cfg_put("merchant-instance-wireformat-tutorial", "TEST_RESPONSE_FILE", "${TALER_CONFIG_HOME}/merchant/wire/tutorial.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):
    data = OrderedDict(
      type="test",
      bank_uri="https://bank.{}.taler.net/".format(envname),
      sig="MERCHANTSIGNATURE",
      account_number=acct_no,
      salt="SALT"
    )

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

def exchange_wf(envname, wfname, acct_no, name):
    data = OrderedDict(
        name=name,
        type=wfname,
        bank_uri="https://bank.{}.taler.net/".format(envname),
        account_number=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("--exchange-pub", required=True)
def main(currency, envname, outdir, exchange_pub):

    config(currency, envname, exchange_pub)

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

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

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

        d = os.path.join(outdir, "taler", "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(outdir, "taler", "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
            f = open(os.path.join(d, name+".unsigned.json"), "w")
            f.write(data)
            f.close()
    else:
        cfg_write(sys.stdout)

if __name__ == "__main__":
    main()