#!/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", "base_url", urls["auditor"]) 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("exchange", "privacy_etag", "0") obj.cfg_put("exchange", "privacy_dir", "$HOME/local/share/taler-exchange/pp") 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", "apikey", f"Bearer {frontends_apitoken}") 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()