From b977277052c9bf387b2f28a4720a071a08e8e821 Mon Sep 17 00:00:00 2001 From: Rafa de la Torre Date: Tue, 17 Nov 2015 12:01:18 +0100 Subject: [PATCH] cartodb as dependency and use its config table #37 in the client. --- client/cdb_geocoder_client.control | 2 +- client/expected/00_installation_test.out | 9 +++-- client/expected/90_permissions_test.out | 5 +-- client/sql/0.0.1/05_geocoder_server_conf.sql | 38 -------------------- client/sql/0.0.1/06_geocoder_server_conn.sql | 4 +-- client/sql/00_installation_test.sql | 5 ++- client/sql/90_permissions_test.sql | 3 -- 7 files changed, 14 insertions(+), 52 deletions(-) delete mode 100644 client/sql/0.0.1/05_geocoder_server_conf.sql diff --git a/client/cdb_geocoder_client.control b/client/cdb_geocoder_client.control index b439b22..c903511 100644 --- a/client/cdb_geocoder_client.control +++ b/client/cdb_geocoder_client.control @@ -1,6 +1,6 @@ # CartoDB geocoder client API extension comment = 'CartoDB geocoder client API extension' default_version = '0.0.1' -requires = 'plproxy' +requires = 'plproxy, cartodb' superuser = true schema = cdb_geocoder_client diff --git a/client/expected/00_installation_test.out b/client/expected/00_installation_test.out index 621ce99..6ff9e30 100644 --- a/client/expected/00_installation_test.out +++ b/client/expected/00_installation_test.out @@ -1,12 +1,15 @@ -- Install dependencies CREATE EXTENSION postgis; +CREATE EXTENSION schema_triggers; +CREATE EXTENSION plpythonu; +CREATE EXTENSION cartodb; CREATE EXTENSION plproxy; -- Install the extension CREATE EXTENSION cdb_geocoder_client; -- Mock the server connection to point to this very test db -SELECT cdb_geocoder_client._config_set('db_server_config', '{"connection_str": "dbname=contrib_regression host=127.0.0.1 user=postgres"}'); - _config_set -------------- +SELECT cartodb.cdb_conf_setconf('geocoder_server_config', '{"connection_str": "dbname=contrib_regression host=127.0.0.1 user=postgres"}'); + cdb_conf_setconf +------------------ (1 row) diff --git a/client/expected/90_permissions_test.out b/client/expected/90_permissions_test.out index 3077bd4..a334cc8 100644 --- a/client/expected/90_permissions_test.out +++ b/client/expected/90_permissions_test.out @@ -75,7 +75,7 @@ PL/pgSQL function cdb_geocoder_client.geocode_postalcode_point(text,text) line 5 (1 row) SELECT cdb_geocoder_client.geocode_ip('8.8.8.8'); -NOTICE: cdb_geocoder_client._geocode_ip(3): [contrib_regression] REMOTE NOTICE: cbd_geocoder_server.geocode_namedplace_point invoked with params (postgres, some_transaction_id, 8.8.8.8) +NOTICE: cdb_geocoder_client._geocode_ip(3): [contrib_regression] REMOTE NOTICE: cbd_geocoder_server.geocode_ip invoked with params (postgres, some_transaction_id, 8.8.8.8) CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_ip(session_user, txid_current(), ip_address)" PL/pgSQL function cdb_geocoder_client.geocode_ip(text) line 5 at SQL statement geocode_ip @@ -102,6 +102,3 @@ SELECT cdb_geocoder_client._geocode_postalcode_point('evil_user', 666, '66666', ERROR: permission denied for function _geocode_postalcode_point SELECT cdb_geocoder_client._geocode_ip('evil_user', 666, '8.8.8.8'); ERROR: permission denied for function _geocode_ip --- Check the regular user cannot look into config table -SELECT * from cdb_geocoder_client._config; -ERROR: permission denied for relation _config diff --git a/client/sql/0.0.1/05_geocoder_server_conf.sql b/client/sql/0.0.1/05_geocoder_server_conf.sql deleted file mode 100644 index 914e39f..0000000 --- a/client/sql/0.0.1/05_geocoder_server_conf.sql +++ /dev/null @@ -1,38 +0,0 @@ --- --- This extension has its own table for configurations. --- --- The table and the function are considered to be private and therefore --- no permissions are granted for any other user but the creator. - -CREATE TABLE IF NOT EXISTS cdb_geocoder_client._config ( KEY TEXT PRIMARY KEY, VALUE JSON NOT NULL ); - --- Needed to dump config in backups --- This can only be called from an SQL script executed by CREATE EXTENSION -SELECT pg_catalog.pg_extension_config_dump('cdb_geocoder_client._config', ''); - - -CREATE OR REPLACE FUNCTION cdb_geocoder_client._config_set(key text, value JSON) -RETURNS VOID AS $$ -BEGIN - PERFORM cdb_geocoder_client._config_remove(key); - EXECUTE 'INSERT INTO cdb_geocoder_client._config (KEY, VALUE) VALUES ($1, $2);' USING key, value; -END -$$ LANGUAGE PLPGSQL VOLATILE; - - -CREATE OR REPLACE FUNCTION cdb_geocoder_client._config_remove(key text) -RETURNS VOID AS $$ -BEGIN - EXECUTE 'DELETE FROM cdb_geocoder_client._config WHERE KEY = $1;' USING key; -END -$$ LANGUAGE PLPGSQL VOLATILE; - -CREATE OR REPLACE FUNCTION cdb_geocoder_client._config_get(key text) - RETURNS JSON AS $$ -DECLARE - value JSON; -BEGIN - EXECUTE 'SELECT VALUE FROM cdb_geocoder_client._config WHERE KEY = $1;' INTO value USING key; - RETURN value; -END -$$ LANGUAGE PLPGSQL STABLE; \ No newline at end of file diff --git a/client/sql/0.0.1/06_geocoder_server_conn.sql b/client/sql/0.0.1/06_geocoder_server_conn.sql index dd53dc3..387971f 100644 --- a/client/sql/0.0.1/06_geocoder_server_conn.sql +++ b/client/sql/0.0.1/06_geocoder_server_conn.sql @@ -9,8 +9,8 @@ RETURNS text AS $$ DECLARE db_connection_str text; BEGIN - SELECT cdb_geocoder_client._config_get('db_server_config')->'connection_str' INTO db_connection_str; + SELECT cartodb.cdb_conf_getconf('geocoder_server_config')->'connection_str' INTO db_connection_str; SELECT trim(both '"' FROM db_connection_str) INTO db_connection_str; RETURN db_connection_str; END; -$$ LANGUAGE 'plpgsql'; \ No newline at end of file +$$ LANGUAGE 'plpgsql'; diff --git a/client/sql/00_installation_test.sql b/client/sql/00_installation_test.sql index 4446f18..e03cafd 100644 --- a/client/sql/00_installation_test.sql +++ b/client/sql/00_installation_test.sql @@ -1,12 +1,15 @@ -- Install dependencies CREATE EXTENSION postgis; +CREATE EXTENSION schema_triggers; +CREATE EXTENSION plpythonu; +CREATE EXTENSION cartodb; CREATE EXTENSION plproxy; -- Install the extension CREATE EXTENSION cdb_geocoder_client; -- Mock the server connection to point to this very test db -SELECT cdb_geocoder_client._config_set('db_server_config', '{"connection_str": "dbname=contrib_regression host=127.0.0.1 user=postgres"}'); +SELECT cartodb.cdb_conf_setconf('geocoder_server_config', '{"connection_str": "dbname=contrib_regression host=127.0.0.1 user=postgres"}'); -- Mock the server schema CREATE SCHEMA cdb_geocoder_server; diff --git a/client/sql/90_permissions_test.sql b/client/sql/90_permissions_test.sql index 6f160fa..beb6ae2 100644 --- a/client/sql/90_permissions_test.sql +++ b/client/sql/90_permissions_test.sql @@ -23,6 +23,3 @@ SELECT cdb_geocoder_client._geocode_namedplace_point('evil_user', 666, 'Sheol', SELECT cdb_geocoder_client._geocode_postalcode_polygon('evil_user', 666, '66666', 'Hell'); SELECT cdb_geocoder_client._geocode_postalcode_point('evil_user', 666, '66666', 'Hell'); SELECT cdb_geocoder_client._geocode_ip('evil_user', 666, '8.8.8.8'); - --- Check the regular user cannot look into config table -SELECT * from cdb_geocoder_client._config;