Merge pull request #38 from CartoDB/review_internal_api

Fix some typos, remove _conf table and use cartodb.cdb_conf in client
This commit is contained in:
Rafa de la Torre 2015-11-17 14:37:30 +01:00
commit 3fbaaa29ac
20 changed files with 95 additions and 133 deletions

View File

@ -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

View File

@ -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)

View File

@ -1,18 +1,18 @@
-- Mock the server function
CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_admin0_polygons(user_id name, tx_id bigint, country_name text)
CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_admin0_polygon(user_id name, tx_id bigint, country_name text)
RETURNS Geometry AS $$
BEGIN
RAISE NOTICE 'cbd_geocoder_server.geocode_admin0_polygons invoked with params (%, %, %)', user_id, 'some_transaction_id', country_name;
RAISE NOTICE 'cdb_geocoder_server.geocode_admin0_polygon invoked with params (%, %, %)', user_id, 'some_transaction_id', country_name;
RETURN NULL;
END;
$$ LANGUAGE 'plpgsql';
-- Exercise the public and the proxied function
SELECT cdb_geocoder_client.geocode_admin0_polygons('Spain');
NOTICE: cdb_geocoder_client._geocode_admin0_polygons(3): [contrib_regression] REMOTE NOTICE: cbd_geocoder_server.geocode_admin0_polygons invoked with params (postgres, some_transaction_id, Spain)
CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_admin0_polygons(session_user, txid_current(), country_name)"
PL/pgSQL function cdb_geocoder_client.geocode_admin0_polygons(text) line 5 at SQL statement
geocode_admin0_polygons
-------------------------
SELECT cdb_geocoder_client.geocode_admin0_polygon('Spain');
NOTICE: cdb_geocoder_client._geocode_admin0_polygon(3): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.geocode_admin0_polygon invoked with params (postgres, some_transaction_id, Spain)
CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_admin0_polygon(session_user, txid_current(), country_name)"
PL/pgSQL function cdb_geocoder_client.geocode_admin0_polygon(text) line 5 at SQL statement
geocode_admin0_polygon
------------------------
(1 row)

View File

@ -2,20 +2,20 @@
CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_admin1_polygon(user_id name, tx_id bigint, admin1_name text)
RETURNS Geometry AS $$
BEGIN
RAISE NOTICE 'cbd_geocoder_server.geocode_admin1_polygon invoked with params (%, %, %)', user_id, 'some_transaction_id', admin1_name;
RAISE NOTICE 'cdb_geocoder_server.geocode_admin1_polygon invoked with params (%, %, %)', user_id, 'some_transaction_id', admin1_name;
RETURN NULL;
END;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_admin1_polygon(user_id name, tx_id bigint, admin1_name text, country_name text)
RETURNS Geometry AS $$
BEGIN
RAISE NOTICE 'cbd_geocoder_server.geocode_admin1_polygon invoked with params (%, %, %, %)', user_id, 'some_transaction_id', admin1_name, country_name;
RAISE NOTICE 'cdb_geocoder_server.geocode_admin1_polygon invoked with params (%, %, %, %)', user_id, 'some_transaction_id', admin1_name, country_name;
RETURN NULL;
END;
$$ LANGUAGE 'plpgsql';
-- Exercise the public and the proxied function
SELECT cdb_geocoder_client.geocode_admin1_polygon('California');
NOTICE: cdb_geocoder_client._geocode_admin1_polygon(3): [contrib_regression] REMOTE NOTICE: cbd_geocoder_server.geocode_admin1_polygon invoked with params (postgres, some_transaction_id, California)
NOTICE: cdb_geocoder_client._geocode_admin1_polygon(3): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.geocode_admin1_polygon invoked with params (postgres, some_transaction_id, California)
CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_admin1_polygon(session_user, txid_current(), admin1_name)"
PL/pgSQL function cdb_geocoder_client.geocode_admin1_polygon(text) line 5 at SQL statement
geocode_admin1_polygon
@ -24,7 +24,7 @@ PL/pgSQL function cdb_geocoder_client.geocode_admin1_polygon(text) line 5 at SQL
(1 row)
SELECT cdb_geocoder_client.geocode_admin1_polygon('California', 'United States');
NOTICE: cdb_geocoder_client._geocode_admin1_polygon(4): [contrib_regression] REMOTE NOTICE: cbd_geocoder_server.geocode_admin1_polygon invoked with params (postgres, some_transaction_id, California, United States)
NOTICE: cdb_geocoder_client._geocode_admin1_polygon(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.geocode_admin1_polygon invoked with params (postgres, some_transaction_id, California, United States)
CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_admin1_polygon(session_user, txid_current(), admin1_name, country_name)"
PL/pgSQL function cdb_geocoder_client.geocode_admin1_polygon(text,text) line 5 at SQL statement
geocode_admin1_polygon

View File

@ -2,27 +2,27 @@
CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_namedplace_point(user_id name, tx_id bigint, city_name text)
RETURNS Geometry AS $$
BEGIN
RAISE NOTICE 'cbd_geocoder_server.geocode_namedplace_point invoked with params (%, %, %)', user_id, 'some_transaction_id', city_name;
RAISE NOTICE 'cdb_geocoder_server.geocode_namedplace_point invoked with params (%, %, %)', user_id, 'some_transaction_id', city_name;
RETURN NULL;
END;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_namedplace_point(user_id name, tx_id bigint, city_name text, country_name text)
RETURNS Geometry AS $$
BEGIN
RAISE NOTICE 'cbd_geocoder_server.geocode_namedplace_point invoked with params (%, %, %, %)', user_id, 'some_transaction_id', city_name, country_name;
RAISE NOTICE 'cdb_geocoder_server.geocode_namedplace_point invoked with params (%, %, %, %)', user_id, 'some_transaction_id', city_name, country_name;
RETURN NULL;
END;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_namedplace_point(user_id name, tx_id bigint, city_name text, admin1_name text, country_name text)
RETURNS Geometry AS $$
BEGIN
RAISE NOTICE 'cbd_geocoder_server.geocode_namedplace_point invoked with params (%, %, %, %, %)', user_id, 'some_transaction_id', city_name, admin1_name, country_name;
RAISE NOTICE 'cdb_geocoder_server.geocode_namedplace_point invoked with params (%, %, %, %, %)', user_id, 'some_transaction_id', city_name, admin1_name, country_name;
RETURN NULL;
END;
$$ LANGUAGE 'plpgsql';
-- Exercise the public and the proxied function
SELECT cdb_geocoder_client.geocode_namedplace_point('Elx');
NOTICE: cdb_geocoder_client._geocode_namedplace_point(3): [contrib_regression] REMOTE NOTICE: cbd_geocoder_server.geocode_namedplace_point invoked with params (postgres, some_transaction_id, Elx)
NOTICE: cdb_geocoder_client._geocode_namedplace_point(3): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.geocode_namedplace_point invoked with params (postgres, some_transaction_id, Elx)
CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_namedplace_point(session_user, txid_current(), city_name)"
PL/pgSQL function cdb_geocoder_client.geocode_namedplace_point(text) line 5 at SQL statement
geocode_namedplace_point
@ -31,7 +31,7 @@ PL/pgSQL function cdb_geocoder_client.geocode_namedplace_point(text) line 5 at S
(1 row)
SELECT cdb_geocoder_client.geocode_namedplace_point('Elx', 'Spain');
NOTICE: cdb_geocoder_client._geocode_namedplace_point(4): [contrib_regression] REMOTE NOTICE: cbd_geocoder_server.geocode_namedplace_point invoked with params (postgres, some_transaction_id, Elx, Spain)
NOTICE: cdb_geocoder_client._geocode_namedplace_point(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.geocode_namedplace_point invoked with params (postgres, some_transaction_id, Elx, Spain)
CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_namedplace_point(session_user, txid_current(), city_name, country_name)"
PL/pgSQL function cdb_geocoder_client.geocode_namedplace_point(text,text) line 5 at SQL statement
geocode_namedplace_point
@ -40,7 +40,7 @@ PL/pgSQL function cdb_geocoder_client.geocode_namedplace_point(text,text) line 5
(1 row)
SELECT cdb_geocoder_client.geocode_namedplace_point('Elx', 'Valencia', 'Spain');
NOTICE: cdb_geocoder_client._geocode_namedplace_point(5): [contrib_regression] REMOTE NOTICE: cbd_geocoder_server.geocode_namedplace_point invoked with params (postgres, some_transaction_id, Elx, Valencia, Spain)
NOTICE: cdb_geocoder_client._geocode_namedplace_point(5): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.geocode_namedplace_point invoked with params (postgres, some_transaction_id, Elx, Valencia, Spain)
CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_namedplace_point(session_user, txid_current(), city_name, admin1_name, country_name)"
PL/pgSQL function cdb_geocoder_client.geocode_namedplace_point(text,text,text) line 5 at SQL statement
geocode_namedplace_point

View File

@ -2,20 +2,20 @@
CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_postalcode_polygon(user_id name, tx_id bigint, postal_code text, country_name text)
RETURNS Geometry AS $$
BEGIN
RAISE NOTICE 'cbd_geocoder_server.geocode_postalcode_polygon invoked with params (%, %, %, %)', user_id, 'some_transaction_id', postal_code, country_name;
RAISE NOTICE 'cdb_geocoder_server.geocode_postalcode_polygon invoked with params (%, %, %, %)', user_id, 'some_transaction_id', postal_code, country_name;
RETURN NULL;
END;
$$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_postalcode_point(user_id name, tx_id bigint, postal_code text, country_name text)
RETURNS Geometry AS $$
BEGIN
RAISE NOTICE 'cbd_geocoder_server.geocode_postalcode_point invoked with params (%, %, %, %)', user_id, 'some_transaction_id', postal_code, country_name;
RAISE NOTICE 'cdb_geocoder_server.geocode_postalcode_point invoked with params (%, %, %, %)', user_id, 'some_transaction_id', postal_code, country_name;
RETURN NULL;
END;
$$ LANGUAGE 'plpgsql';
-- Exercise the public and the proxied function
SELECT cdb_geocoder_client.geocode_postalcode_polygon('03204', 'Spain');
NOTICE: cdb_geocoder_client._geocode_postalcode_polygon(4): [contrib_regression] REMOTE NOTICE: cbd_geocoder_server.geocode_postalcode_polygon invoked with params (postgres, some_transaction_id, 03204, Spain)
NOTICE: cdb_geocoder_client._geocode_postalcode_polygon(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.geocode_postalcode_polygon invoked with params (postgres, some_transaction_id, 03204, Spain)
CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_postalcode_polygon(session_user, txid_current(), postal_code, country_name)"
PL/pgSQL function cdb_geocoder_client.geocode_postalcode_polygon(text,text) line 5 at SQL statement
geocode_postalcode_polygon
@ -24,7 +24,7 @@ PL/pgSQL function cdb_geocoder_client.geocode_postalcode_polygon(text,text) line
(1 row)
SELECT cdb_geocoder_client.geocode_postalcode_point('03204', 'Spain');
NOTICE: cdb_geocoder_client._geocode_postalcode_point(4): [contrib_regression] REMOTE NOTICE: cbd_geocoder_server.geocode_postalcode_polygon invoked with params (postgres, some_transaction_id, 03204, Spain)
NOTICE: cdb_geocoder_client._geocode_postalcode_point(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.geocode_postalcode_polygon invoked with params (postgres, some_transaction_id, 03204, Spain)
CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_postalcode_point(session_user, txid_current(), postal_code, country_name)"
PL/pgSQL function cdb_geocoder_client.geocode_postalcode_point(text,text) line 5 at SQL statement
geocode_postalcode_point

View File

@ -1,18 +1,18 @@
-- Mock the server functions
CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_ip(user_id name, tx_id bigint, ip_address text)
CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_ipaddress_point(user_id name, tx_id bigint, ip_address text)
RETURNS Geometry AS $$
BEGIN
RAISE NOTICE 'cbd_geocoder_server.geocode_namedplace_point invoked with params (%, %, %)', user_id, 'some_transaction_id', ip_address;
RAISE NOTICE 'cdb_geocoder_server.geocode_ipaddress_point invoked with params (%, %, %)', user_id, 'some_transaction_id', ip_address;
RETURN NULL;
END;
$$ LANGUAGE 'plpgsql';
-- Exercise the public and the proxied function
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)
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
------------
SELECT cdb_geocoder_client.geocode_ipaddress_point('8.8.8.8');
NOTICE: cdb_geocoder_client._geocode_ipaddress_point(3): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.geocode_ipaddress_point invoked with params (postgres, some_transaction_id, 8.8.8.8)
CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_ipaddress_point(session_user, txid_current(), ip_address)"
PL/pgSQL function cdb_geocoder_client.geocode_ipaddress_point(text) line 5 at SQL statement
geocode_ipaddress_point
-------------------------
(1 row)

View File

@ -2,17 +2,17 @@
SET ROLE test_regular_user;
-- Exercise the public function
-- it is public, it shall work
SELECT cdb_geocoder_client.geocode_admin0_polygons('Spain');
NOTICE: cdb_geocoder_client._geocode_admin0_polygons(3): [contrib_regression] REMOTE NOTICE: cbd_geocoder_server.geocode_admin0_polygons invoked with params (postgres, some_transaction_id, Spain)
CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_admin0_polygons(session_user, txid_current(), country_name)"
PL/pgSQL function cdb_geocoder_client.geocode_admin0_polygons(text) line 5 at SQL statement
geocode_admin0_polygons
-------------------------
SELECT cdb_geocoder_client.geocode_admin0_polygon('Spain');
NOTICE: cdb_geocoder_client._geocode_admin0_polygon(3): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.geocode_admin0_polygon invoked with params (postgres, some_transaction_id, Spain)
CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_admin0_polygon(session_user, txid_current(), country_name)"
PL/pgSQL function cdb_geocoder_client.geocode_admin0_polygon(text) line 5 at SQL statement
geocode_admin0_polygon
------------------------
(1 row)
SELECT cdb_geocoder_client.geocode_admin1_polygon('California');
NOTICE: cdb_geocoder_client._geocode_admin1_polygon(3): [contrib_regression] REMOTE NOTICE: cbd_geocoder_server.geocode_admin1_polygon invoked with params (postgres, some_transaction_id, California)
NOTICE: cdb_geocoder_client._geocode_admin1_polygon(3): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.geocode_admin1_polygon invoked with params (postgres, some_transaction_id, California)
CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_admin1_polygon(session_user, txid_current(), admin1_name)"
PL/pgSQL function cdb_geocoder_client.geocode_admin1_polygon(text) line 5 at SQL statement
geocode_admin1_polygon
@ -21,7 +21,7 @@ PL/pgSQL function cdb_geocoder_client.geocode_admin1_polygon(text) line 5 at SQL
(1 row)
SELECT cdb_geocoder_client.geocode_admin1_polygon('California', 'United States');
NOTICE: cdb_geocoder_client._geocode_admin1_polygon(4): [contrib_regression] REMOTE NOTICE: cbd_geocoder_server.geocode_admin1_polygon invoked with params (postgres, some_transaction_id, California, United States)
NOTICE: cdb_geocoder_client._geocode_admin1_polygon(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.geocode_admin1_polygon invoked with params (postgres, some_transaction_id, California, United States)
CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_admin1_polygon(session_user, txid_current(), admin1_name, country_name)"
PL/pgSQL function cdb_geocoder_client.geocode_admin1_polygon(text,text) line 5 at SQL statement
geocode_admin1_polygon
@ -30,7 +30,7 @@ PL/pgSQL function cdb_geocoder_client.geocode_admin1_polygon(text,text) line 5 a
(1 row)
SELECT cdb_geocoder_client.geocode_namedplace_point('Elx');
NOTICE: cdb_geocoder_client._geocode_namedplace_point(3): [contrib_regression] REMOTE NOTICE: cbd_geocoder_server.geocode_namedplace_point invoked with params (postgres, some_transaction_id, Elx)
NOTICE: cdb_geocoder_client._geocode_namedplace_point(3): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.geocode_namedplace_point invoked with params (postgres, some_transaction_id, Elx)
CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_namedplace_point(session_user, txid_current(), city_name)"
PL/pgSQL function cdb_geocoder_client.geocode_namedplace_point(text) line 5 at SQL statement
geocode_namedplace_point
@ -39,7 +39,7 @@ PL/pgSQL function cdb_geocoder_client.geocode_namedplace_point(text) line 5 at S
(1 row)
SELECT cdb_geocoder_client.geocode_namedplace_point('Elx', 'Valencia');
NOTICE: cdb_geocoder_client._geocode_namedplace_point(4): [contrib_regression] REMOTE NOTICE: cbd_geocoder_server.geocode_namedplace_point invoked with params (postgres, some_transaction_id, Elx, Valencia)
NOTICE: cdb_geocoder_client._geocode_namedplace_point(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.geocode_namedplace_point invoked with params (postgres, some_transaction_id, Elx, Valencia)
CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_namedplace_point(session_user, txid_current(), city_name, country_name)"
PL/pgSQL function cdb_geocoder_client.geocode_namedplace_point(text,text) line 5 at SQL statement
geocode_namedplace_point
@ -48,7 +48,7 @@ PL/pgSQL function cdb_geocoder_client.geocode_namedplace_point(text,text) line 5
(1 row)
SELECT cdb_geocoder_client.geocode_namedplace_point('Elx', 'Valencia', 'Spain');
NOTICE: cdb_geocoder_client._geocode_namedplace_point(5): [contrib_regression] REMOTE NOTICE: cbd_geocoder_server.geocode_namedplace_point invoked with params (postgres, some_transaction_id, Elx, Valencia, Spain)
NOTICE: cdb_geocoder_client._geocode_namedplace_point(5): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.geocode_namedplace_point invoked with params (postgres, some_transaction_id, Elx, Valencia, Spain)
CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_namedplace_point(session_user, txid_current(), city_name, admin1_name, country_name)"
PL/pgSQL function cdb_geocoder_client.geocode_namedplace_point(text,text,text) line 5 at SQL statement
geocode_namedplace_point
@ -57,7 +57,7 @@ PL/pgSQL function cdb_geocoder_client.geocode_namedplace_point(text,text,text) l
(1 row)
SELECT cdb_geocoder_client.geocode_postalcode_polygon('03204', 'Spain');
NOTICE: cdb_geocoder_client._geocode_postalcode_polygon(4): [contrib_regression] REMOTE NOTICE: cbd_geocoder_server.geocode_postalcode_polygon invoked with params (postgres, some_transaction_id, 03204, Spain)
NOTICE: cdb_geocoder_client._geocode_postalcode_polygon(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.geocode_postalcode_polygon invoked with params (postgres, some_transaction_id, 03204, Spain)
CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_postalcode_polygon(session_user, txid_current(), postal_code, country_name)"
PL/pgSQL function cdb_geocoder_client.geocode_postalcode_polygon(text,text) line 5 at SQL statement
geocode_postalcode_polygon
@ -66,7 +66,7 @@ PL/pgSQL function cdb_geocoder_client.geocode_postalcode_polygon(text,text) line
(1 row)
SELECT cdb_geocoder_client.geocode_postalcode_point('03204', 'Spain');
NOTICE: cdb_geocoder_client._geocode_postalcode_point(4): [contrib_regression] REMOTE NOTICE: cbd_geocoder_server.geocode_postalcode_polygon invoked with params (postgres, some_transaction_id, 03204, Spain)
NOTICE: cdb_geocoder_client._geocode_postalcode_point(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.geocode_postalcode_polygon invoked with params (postgres, some_transaction_id, 03204, Spain)
CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_postalcode_point(session_user, txid_current(), postal_code, country_name)"
PL/pgSQL function cdb_geocoder_client.geocode_postalcode_point(text,text) line 5 at SQL statement
geocode_postalcode_point
@ -74,18 +74,18 @@ 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)
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
------------
SELECT cdb_geocoder_client.geocode_ipaddress_point('8.8.8.8');
NOTICE: cdb_geocoder_client._geocode_ipaddress_point(3): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.geocode_ipaddress_point invoked with params (postgres, some_transaction_id, 8.8.8.8)
CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_ipaddress_point(session_user, txid_current(), ip_address)"
PL/pgSQL function cdb_geocoder_client.geocode_ipaddress_point(text) line 5 at SQL statement
geocode_ipaddress_point
-------------------------
(1 row)
-- Check the regular user has no permissions on private functions
SELECT cdb_geocoder_client._geocode_admin0_polygons('evil_user', 666, 'Hell');
ERROR: permission denied for function _geocode_admin0_polygons
SELECT cdb_geocoder_client._geocode_admin0_polygon('evil_user', 666, 'Hell');
ERROR: permission denied for function _geocode_admin0_polygon
SELECT cdb_geocoder_client._geocode_admin1_polygon('evil_user', 666, 'Hell');
ERROR: permission denied for function _geocode_admin1_polygon
SELECT cdb_geocoder_client._geocode_admin1_polygon('evil_user', 666, 'Sheol', 'Hell');
@ -100,8 +100,5 @@ SELECT cdb_geocoder_client._geocode_postalcode_polygon('evil_user', 666, '66666'
ERROR: permission denied for function _geocode_postalcode_polygon
SELECT cdb_geocoder_client._geocode_postalcode_point('evil_user', 666, '66666', 'Hell');
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
SELECT cdb_geocoder_client._geocode_ipaddress_point('evil_user', 666, '8.8.8.8');
ERROR: permission denied for function _geocode_ipaddress_point

View File

@ -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;

View File

@ -9,7 +9,7 @@ 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;

View File

@ -4,12 +4,12 @@
-- These are the only ones with permissions to publicuser role
-- and should also be the only ones with SECURITY DEFINER
CREATE OR REPLACE FUNCTION cdb_geocoder_client.geocode_admin0_polygons(country_name text)
CREATE OR REPLACE FUNCTION cdb_geocoder_client.geocode_admin0_polygon(country_name text)
RETURNS Geometry AS $$
DECLARE
ret Geometry;
BEGIN
SELECT cdb_geocoder_client._geocode_admin0_polygons(session_user, txid_current(), country_name) INTO ret;
SELECT cdb_geocoder_client._geocode_admin0_polygon(session_user, txid_current(), country_name) INTO ret;
RETURN ret;
END;
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
@ -19,8 +19,8 @@ $$ LANGUAGE 'plpgsql' SECURITY DEFINER;
--------------------------------------------------------------------------------
CREATE OR REPLACE FUNCTION cdb_geocoder_client._geocode_admin0_polygons(user_id name, tx_id bigint, country_name text)
CREATE OR REPLACE FUNCTION cdb_geocoder_client._geocode_admin0_polygon(user_id name, tx_id bigint, country_name text)
RETURNS Geometry AS $$
CONNECT cdb_geocoder_client._server_conn_str();
SELECT cdb_geocoder_server.geocode_admin0_polygons(user_id, tx_id, country_name);
SELECT cdb_geocoder_server.geocode_admin0_polygon(user_id, tx_id, country_name);
$$ LANGUAGE plproxy;

View File

@ -4,13 +4,13 @@
-- These are the only ones with permissions to publicuser role
-- and should also be the only ones with SECURITY DEFINER
---- geocode_ip(city_name text)
CREATE OR REPLACE FUNCTION cdb_geocoder_client.geocode_ip(ip_address text)
---- geocode_ipaddress_point(city_name text)
CREATE OR REPLACE FUNCTION cdb_geocoder_client.geocode_ipaddress_point(ip_address text)
RETURNS Geometry AS $$
DECLARE
ret Geometry;
BEGIN
SELECT cdb_geocoder_client._geocode_ip(session_user, txid_current(), ip_address) INTO ret;
SELECT cdb_geocoder_client._geocode_ipaddress_point(session_user, txid_current(), ip_address) INTO ret;
RETURN ret;
END;
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
@ -19,9 +19,9 @@ $$ LANGUAGE 'plpgsql' SECURITY DEFINER;
--------------------------------------------------------------------------------
---- geocode_ip(ip_address text)
CREATE OR REPLACE FUNCTION cdb_geocoder_client._geocode_ip(user_id name, tx_id bigint, ip_address text)
---- geocode_ipaddress_point(ip_address text)
CREATE OR REPLACE FUNCTION cdb_geocoder_client._geocode_ipaddress_point(user_id name, tx_id bigint, ip_address text)
RETURNS Geometry AS $$
CONNECT cdb_geocoder_client._server_conn_str();
SELECT cdb_geocoder_server.geocode_ip(user_id, tx_id, ip_address);
SELECT cdb_geocoder_server.geocode_ipaddress_point(user_id, tx_id, ip_address);
$$ LANGUAGE plproxy;

View File

@ -12,7 +12,7 @@ REVOKE EXECUTE ON ALL FUNCTIONS IN SCHEMA cdb_geocoder_client FROM PUBLIC, publi
-- Explicitly grant permissions to public functions
-- NOTE: All public functions must be listed below, grating permissions to publicuser
GRANT EXECUTE ON FUNCTION cdb_geocoder_client.geocode_admin0_polygons(country_name text) TO publicuser;
GRANT EXECUTE ON FUNCTION cdb_geocoder_client.geocode_admin0_polygon(country_name text) TO publicuser;
GRANT EXECUTE ON FUNCTION cdb_geocoder_client.geocode_admin1_polygon(admin1_name text) TO publicuser;
GRANT EXECUTE ON FUNCTION cdb_geocoder_client.geocode_admin1_polygon(admin1_name text, country_name text) TO publicuser;
GRANT EXECUTE ON FUNCTION cdb_geocoder_client.geocode_namedplace_point(city_name text) TO publicuser;
@ -20,4 +20,4 @@ GRANT EXECUTE ON FUNCTION cdb_geocoder_client.geocode_namedplace_point(city_name
GRANT EXECUTE ON FUNCTION cdb_geocoder_client.geocode_namedplace_point(city_name text, admin1_name text, country_name text) TO publicuser;
GRANT EXECUTE ON FUNCTION cdb_geocoder_client.geocode_postalcode_polygon(postal_code text, country_name text) TO publicuser;
GRANT EXECUTE ON FUNCTION cdb_geocoder_client.geocode_postalcode_point(postal_code text, country_name text) TO publicuser;
GRANT EXECUTE ON FUNCTION cdb_geocoder_client.geocode_ip(ip_address text) TO publicuser;
GRANT EXECUTE ON FUNCTION cdb_geocoder_client.geocode_ipaddress_point(ip_address text) TO publicuser;

View File

@ -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;

View File

@ -1,12 +1,12 @@
-- Mock the server function
CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_admin0_polygons(user_id name, tx_id bigint, country_name text)
CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_admin0_polygon(user_id name, tx_id bigint, country_name text)
RETURNS Geometry AS $$
BEGIN
RAISE NOTICE 'cbd_geocoder_server.geocode_admin0_polygons invoked with params (%, %, %)', user_id, 'some_transaction_id', country_name;
RAISE NOTICE 'cdb_geocoder_server.geocode_admin0_polygon invoked with params (%, %, %)', user_id, 'some_transaction_id', country_name;
RETURN NULL;
END;
$$ LANGUAGE 'plpgsql';
-- Exercise the public and the proxied function
SELECT cdb_geocoder_client.geocode_admin0_polygons('Spain');
SELECT cdb_geocoder_client.geocode_admin0_polygon('Spain');

View File

@ -2,7 +2,7 @@
CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_admin1_polygon(user_id name, tx_id bigint, admin1_name text)
RETURNS Geometry AS $$
BEGIN
RAISE NOTICE 'cbd_geocoder_server.geocode_admin1_polygon invoked with params (%, %, %)', user_id, 'some_transaction_id', admin1_name;
RAISE NOTICE 'cdb_geocoder_server.geocode_admin1_polygon invoked with params (%, %, %)', user_id, 'some_transaction_id', admin1_name;
RETURN NULL;
END;
$$ LANGUAGE 'plpgsql';
@ -10,7 +10,7 @@ $$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_admin1_polygon(user_id name, tx_id bigint, admin1_name text, country_name text)
RETURNS Geometry AS $$
BEGIN
RAISE NOTICE 'cbd_geocoder_server.geocode_admin1_polygon invoked with params (%, %, %, %)', user_id, 'some_transaction_id', admin1_name, country_name;
RAISE NOTICE 'cdb_geocoder_server.geocode_admin1_polygon invoked with params (%, %, %, %)', user_id, 'some_transaction_id', admin1_name, country_name;
RETURN NULL;
END;
$$ LANGUAGE 'plpgsql';

View File

@ -2,7 +2,7 @@
CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_namedplace_point(user_id name, tx_id bigint, city_name text)
RETURNS Geometry AS $$
BEGIN
RAISE NOTICE 'cbd_geocoder_server.geocode_namedplace_point invoked with params (%, %, %)', user_id, 'some_transaction_id', city_name;
RAISE NOTICE 'cdb_geocoder_server.geocode_namedplace_point invoked with params (%, %, %)', user_id, 'some_transaction_id', city_name;
RETURN NULL;
END;
$$ LANGUAGE 'plpgsql';
@ -10,7 +10,7 @@ $$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_namedplace_point(user_id name, tx_id bigint, city_name text, country_name text)
RETURNS Geometry AS $$
BEGIN
RAISE NOTICE 'cbd_geocoder_server.geocode_namedplace_point invoked with params (%, %, %, %)', user_id, 'some_transaction_id', city_name, country_name;
RAISE NOTICE 'cdb_geocoder_server.geocode_namedplace_point invoked with params (%, %, %, %)', user_id, 'some_transaction_id', city_name, country_name;
RETURN NULL;
END;
$$ LANGUAGE 'plpgsql';
@ -18,7 +18,7 @@ $$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_namedplace_point(user_id name, tx_id bigint, city_name text, admin1_name text, country_name text)
RETURNS Geometry AS $$
BEGIN
RAISE NOTICE 'cbd_geocoder_server.geocode_namedplace_point invoked with params (%, %, %, %, %)', user_id, 'some_transaction_id', city_name, admin1_name, country_name;
RAISE NOTICE 'cdb_geocoder_server.geocode_namedplace_point invoked with params (%, %, %, %, %)', user_id, 'some_transaction_id', city_name, admin1_name, country_name;
RETURN NULL;
END;
$$ LANGUAGE 'plpgsql';

View File

@ -2,7 +2,7 @@
CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_postalcode_polygon(user_id name, tx_id bigint, postal_code text, country_name text)
RETURNS Geometry AS $$
BEGIN
RAISE NOTICE 'cbd_geocoder_server.geocode_postalcode_polygon invoked with params (%, %, %, %)', user_id, 'some_transaction_id', postal_code, country_name;
RAISE NOTICE 'cdb_geocoder_server.geocode_postalcode_polygon invoked with params (%, %, %, %)', user_id, 'some_transaction_id', postal_code, country_name;
RETURN NULL;
END;
$$ LANGUAGE 'plpgsql';
@ -10,7 +10,7 @@ $$ LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_postalcode_point(user_id name, tx_id bigint, postal_code text, country_name text)
RETURNS Geometry AS $$
BEGIN
RAISE NOTICE 'cbd_geocoder_server.geocode_postalcode_point invoked with params (%, %, %, %)', user_id, 'some_transaction_id', postal_code, country_name;
RAISE NOTICE 'cdb_geocoder_server.geocode_postalcode_point invoked with params (%, %, %, %)', user_id, 'some_transaction_id', postal_code, country_name;
RETURN NULL;
END;
$$ LANGUAGE 'plpgsql';

View File

@ -1,12 +1,12 @@
-- Mock the server functions
CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_ip(user_id name, tx_id bigint, ip_address text)
CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_ipaddress_point(user_id name, tx_id bigint, ip_address text)
RETURNS Geometry AS $$
BEGIN
RAISE NOTICE 'cbd_geocoder_server.geocode_namedplace_point invoked with params (%, %, %)', user_id, 'some_transaction_id', ip_address;
RAISE NOTICE 'cdb_geocoder_server.geocode_ipaddress_point invoked with params (%, %, %)', user_id, 'some_transaction_id', ip_address;
RETURN NULL;
END;
$$ LANGUAGE 'plpgsql';
-- Exercise the public and the proxied function
SELECT cdb_geocoder_client.geocode_ip('8.8.8.8');
SELECT cdb_geocoder_client.geocode_ipaddress_point('8.8.8.8');

View File

@ -3,7 +3,7 @@ SET ROLE test_regular_user;
-- Exercise the public function
-- it is public, it shall work
SELECT cdb_geocoder_client.geocode_admin0_polygons('Spain');
SELECT cdb_geocoder_client.geocode_admin0_polygon('Spain');
SELECT cdb_geocoder_client.geocode_admin1_polygon('California');
SELECT cdb_geocoder_client.geocode_admin1_polygon('California', 'United States');
SELECT cdb_geocoder_client.geocode_namedplace_point('Elx');
@ -11,10 +11,10 @@ SELECT cdb_geocoder_client.geocode_namedplace_point('Elx', 'Valencia');
SELECT cdb_geocoder_client.geocode_namedplace_point('Elx', 'Valencia', 'Spain');
SELECT cdb_geocoder_client.geocode_postalcode_polygon('03204', 'Spain');
SELECT cdb_geocoder_client.geocode_postalcode_point('03204', 'Spain');
SELECT cdb_geocoder_client.geocode_ip('8.8.8.8');
SELECT cdb_geocoder_client.geocode_ipaddress_point('8.8.8.8');
-- Check the regular user has no permissions on private functions
SELECT cdb_geocoder_client._geocode_admin0_polygons('evil_user', 666, 'Hell');
SELECT cdb_geocoder_client._geocode_admin0_polygon('evil_user', 666, 'Hell');
SELECT cdb_geocoder_client._geocode_admin1_polygon('evil_user', 666, 'Hell');
SELECT cdb_geocoder_client._geocode_admin1_polygon('evil_user', 666, 'Sheol', 'Hell');
SELECT cdb_geocoder_client._geocode_namedplace_point('evil_user', 666, 'Sheol');
@ -22,7 +22,4 @@ SELECT cdb_geocoder_client._geocode_namedplace_point('evil_user', 666, 'Sheol',
SELECT cdb_geocoder_client._geocode_namedplace_point('evil_user', 666, 'Sheol', 'Hell', 'Ugly world');
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;
SELECT cdb_geocoder_client._geocode_ipaddress_point('evil_user', 666, '8.8.8.8');