#!/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(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" % currency) cfg_put("bank", "max_debt_bank", "%s: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("blog", "uwsgi_serve", "unix") cfg_put("blog", "uwsgi_unixpath", "$HOME/sockets/shop.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") 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", "URI", "https://env.taler.net/{}/exchange/".format(envname)) else: cfg_put("merchant-exchange-test", "URI", "https://exchange.{}.taler.net/".format(envname)) cfg_put("merchant-exchange-test", "MASTER_KEY", exchange_pub) if standalone: cfg_put("frontends", "BACKEND", "https://env.taler.net/{}/merchant-backend/".format(envname)) else: cfg_put("frontends", "BACKEND", "https://shop.{}.taler.net/backend/".format(envname)) cfg_put("frontends", "FRACTION", "100000000") 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("exchange-admin", "SERVE", "unix") cfg_put("exchange-admin", "unixpath", "$HOME/sockets/exchange-admin.http") 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("auditordb-postgres", "db_conn_str", "postgres:///taler?host={}/sockets".format(os.getenv("HOME"))) else: cfg_put("exchangedb-postgres", "db_conn_str", "postgres:///taler{}".format(envname)) cfg_put("auditordb-postgres", "db_conn_str", "postgres:///taler{}".format(envname)) if standalone: cfg_put("exchange-wire-test", "bank_uri", "https://env.taler.net/{}/bank/".format(envname)) else: cfg_put("exchange-wire-test", "bank_uri", "https://bank.{}.taler.net/".format(envname)) cfg_put("exchange-wire-test", "bank_account_number", "1") cfg_put("exchange-wire-test", "exchange_account_number", "2") cfg_put("exchange-wire-test", "enable", "yes") cfg_put("exchange-wire-test", "test_response_file", "${TALER_DEPLOYMENT_SHARED}/exchange/wire/test.json") cfg_put("exchange-wire-test", "wire-fee-2017", currency + ":" + "0.01") cfg_put("exchange-wire-test", "wire-fee-2018", currency + ":" + "0.02") cfg_put("exchange-wire-test", "wire-fee-2019", currency + ":" + "0.03") cfg_put("exchange-wire-test", "wire-fee-2020", currency + ":" + "0.04") cfg_put("exchange-wire-test", "wire-fee-2021", currency + ":" + "0.04") cfg_put("exchange-wire-test", "wire-fee-2022", currency + ":" + "0.05") cfg_put("exchange-wire-test", "wire-fee-2023", currency + ":" + "0.06") cfg_put("exchange-wire-test", "wire-fee-2024", currency + ":" + "0.07") cfg_put("exchange-wire-test", "wire-fee-2025", currency + ":" + "0.08") cfg_put("exchange-wire-test", "closing-fee-2017", currency + ":" + "0.01") cfg_put("exchange-wire-test", "closing-fee-2018", currency + ":" + "0.02") cfg_put("exchange-wire-test", "closing-fee-2019", currency + ":" + "0.03") cfg_put("exchange-wire-test", "closing-fee-2020", currency + ":" + "0.04") cfg_put("exchange-wire-test", "closing-fee-2021", currency + ":" + "0.04") cfg_put("exchange-wire-test", "closing-fee-2022", currency + ":" + "0.05") cfg_put("exchange-wire-test", "closing-fee-2023", currency + ":" + "0.06") cfg_put("exchange-wire-test", "closing-fee-2024", currency + ":" + "0.07") cfg_put("exchange-wire-test", "closing-fee-2025", currency + ":" + "0.08") cfg_put("exchange-wire-test", "username", "Exchange") cfg_put("exchange-wire-test", "password", "x") # 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_DEPLOYMENT_SHARED}/merchant/fsf.priv") cfg_put("merchant-instance-Tor", "KEYFILE", "${TALER_DEPLOYMENT_SHARED}/merchant/tor.priv") cfg_put("merchant-instance-GNUnet", "KEYFILE", "${TALER_DEPLOYMENT_SHARED}/merchant/gnunet.priv") cfg_put("merchant-instance-Taler", "KEYFILE", "${TALER_DEPLOYMENT_SHARED}/merchant/taler.priv") cfg_put("merchant-instance-default", "KEYFILE", "${TALER_DEPLOYMENT_SHARED}/merchant/default.priv") cfg_put("merchant-instance-tutorial", "KEYFILE", "${TALER_DEPLOYMENT_SHARED}/merchant/default.priv") 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_uri = "https://env.taler.net/{}/bank/".format(envname) else: bank_uri = "https://bank.{}.taler.net/".format(envname) data = OrderedDict( type="test", bank_uri=bank_uri, 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_uri = "https://env.taler.net/{}/bank/".format(envname) else: bank_uri = "https://bank.{}.taler.net/".format(envname) data = OrderedDict( name=name, type=wfname, bank_uri=bank_uri, 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("--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 f = open(os.path.join(d, name+".unsigned.json"), "w") f.write(data) f.close() else: cfg_write(sys.stdout) if __name__ == "__main__": main()