From 72ae759fa0e31766855dd30b6783f1f14c942e39 Mon Sep 17 00:00:00 2001 From: Marco Boss Date: Mon, 2 May 2022 00:27:59 +0200 Subject: include shard domain and remote users in taler config --- src/exchangedb/common-0001.sql | 10 +++-- src/exchangedb/plugin_exchangedb_postgres.c | 64 ++++++++++++++++++++++++++--- 2 files changed, 65 insertions(+), 9 deletions(-) (limited to 'src/exchangedb') diff --git a/src/exchangedb/common-0001.sql b/src/exchangedb/common-0001.sql index a96b91fa1..6d45c22ea 100644 --- a/src/exchangedb/common-0001.sql +++ b/src/exchangedb/common-0001.sql @@ -2627,7 +2627,9 @@ COMMENT ON FUNCTION create_shard_server CREATE OR REPLACE FUNCTION create_foreign_servers( amount INTEGER - ,domain VARCHAR DEFAULT 'perf.taler' + ,domain VARCHAR + ,remote_user VARCHAR DEFAULT 'taler' + ,remote_user_password VARCHAR DEFAULT 'taler' ) RETURNS VOID LANGUAGE plpgsql @@ -2642,14 +2644,16 @@ BEGIN ,amount ,i ,'shard-' || i::varchar || '.' || domain - ,'taler' - ,'taler' + ,remote_user + ,remote_user_password ,'taler-exchange' ,'5432' ,'taler-exchange-httpd' ); END LOOP; + PERFORM drop_default_partitions(); + END $$; diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index 8d29581dd..c5833d432 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -356,16 +356,61 @@ postgres_setup_foreign_servers (void *cls, struct PostgresClosure *pg = cls; struct GNUNET_PQ_Context *conn; enum GNUNET_GenericReturnValue ret = GNUNET_OK; + char *shard_domain = NULL; + char *remote_user = NULL; + char *remote_user_pw = NULL; + + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_string (pg->cfg, + "exchange", + "SHARD_DOMAIN", + &shard_domain)) + { + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + "exchange", + "SHARD_DOMAIN"); + return GNUNET_SYSERR; + } + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_string (pg->cfg, + "exchangedb-postgres", + "SHARD_REMOTE_USER", + &remote_user)) + { + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + "exchangedb-postgres", + "SHARD_REMOTE_USER"); + GNUNET_free (shard_domain); + return GNUNET_SYSERR; + } + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_string (pg->cfg, + "exchangedb-postgres", + "SHARD_REMOTE_USER_PW", + &remote_user_pw)) + { + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + "exchangedb-postgres", + "SHARD_REMOTE_USER_PW"); + GNUNET_free (shard_domain); + GNUNET_free (remote_user); + return GNUNET_SYSERR; + } + struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_uint32 (&num), + GNUNET_PQ_query_param_string (shard_domain), + GNUNET_PQ_query_param_string (remote_user), + GNUNET_PQ_query_param_string (remote_user_pw), GNUNET_PQ_query_param_end }; + struct GNUNET_PQ_PreparedStatement ps[] = { GNUNET_PQ_make_prepare ("create_foreign_servers", "SELECT" " create_foreign_servers" - " ($1);", - 1), + " ($1, $2, $3, $4);", + 4), GNUNET_PQ_PREPARED_STATEMENT_END }; @@ -375,11 +420,18 @@ postgres_setup_foreign_servers (void *cls, NULL, ps); if (NULL == conn) - return GNUNET_SYSERR; - if (0 > GNUNET_PQ_eval_prepared_non_select (conn, - "create_foreign_servers", - params)) + { ret = GNUNET_SYSERR; + } + else if (0 > GNUNET_PQ_eval_prepared_non_select (conn, + "create_foreign_servers", + params)) + { + ret = GNUNET_SYSERR; + } + GNUNET_free (shard_domain); + GNUNET_free (remote_user); + GNUNET_free (remote_user_pw); GNUNET_PQ_disconnect (conn); return ret; } -- cgit v1.2.3