diff --git a/.gitignore b/.gitignore index 0d20b64..04f1898 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ +*.DS_Store *.pyc diff --git a/client/expected/00_installation_test.out b/client/expected/00_installation_test.out index 6ff9e30..1f08763 100644 --- a/client/expected/00_installation_test.out +++ b/client/expected/00_installation_test.out @@ -13,6 +13,20 @@ SELECT cartodb.cdb_conf_setconf('geocoder_server_config', '{"connection_str": "d (1 row) +-- Mock the user configuration +SELECT cartodb.cdb_conf_setconf('user_config', '{"is_organization": false, "entity_name": "test_user"}'); + cdb_conf_setconf +------------------ + +(1 row) + +-- Mock the geocoder configuration +SELECT cartodb.cdb_conf_setconf('geocoder_config', '{"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}'); + cdb_conf_setconf +------------------ + +(1 row) + -- Mock the server schema CREATE SCHEMA cdb_geocoder_server; -- Create a test user to check permissions diff --git a/client/expected/10_admin0_test.out b/client/expected/10_admin0_test.out index 2c4efee..f9e81f1 100644 --- a/client/expected/10_admin0_test.out +++ b/client/expected/10_admin0_test.out @@ -1,16 +1,16 @@ -- Mock the server function -CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_admin0_polygon(user_id name, tx_id bigint, country_name text) +CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_admin0_polygon(user_id name, user_config JSON, geocoder_config JSON, country_name text) RETURNS Geometry AS $$ BEGIN - RAISE NOTICE 'cdb_geocoder_server.geocode_admin0_polygon invoked with params (%, %, %)', user_id, 'some_transaction_id', country_name; + RAISE NOTICE 'cdb_geocoder_server.geocode_admin0_polygon invoked with params (%, %, %, %)', user_id, '{"is_organization": false, "entity_name": "test_user"}', '{"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}' , country_name; RETURN NULL; END; $$ LANGUAGE 'plpgsql'; -- Exercise the public and the proxied function 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 +NOTICE: cdb_geocoder_client._geocode_admin0_polygon(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.geocode_admin0_polygon invoked with params (postgres, {"is_organization": false, "entity_name": "test_user"}, {"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}, Spain) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_admin0_polygon(session_user, user_config, geocoder_config, country_name)" +PL/pgSQL function cdb_geocoder_client.geocode_admin0_polygon(text) line 9 at SQL statement geocode_admin0_polygon ------------------------ diff --git a/client/expected/20_admin1_test.out b/client/expected/20_admin1_test.out index 86b3214..838c81f 100644 --- a/client/expected/20_admin1_test.out +++ b/client/expected/20_admin1_test.out @@ -1,32 +1,32 @@ -- Mock the server functions -CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_admin1_polygon(user_id name, tx_id bigint, admin1_name text) +CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_admin1_polygon(user_id name, user_config JSON, geocoder_config JSON, admin1_name text) RETURNS Geometry AS $$ BEGIN - RAISE NOTICE 'cdb_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, '{"is_organization": false, "entity_name": "test_user"}', '{"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}', 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) +CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_admin1_polygon(user_id name, user_config JSON, geocoder_config JSON, admin1_name text, country_name text) RETURNS Geometry AS $$ BEGIN - RAISE NOTICE 'cdb_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, '{"is_organization": false, "entity_name": "test_user"}', '{"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}', 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: 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 +NOTICE: cdb_geocoder_client._geocode_admin1_polygon(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.geocode_admin1_polygon invoked with params (postgres, {"is_organization": false, "entity_name": "test_user"}, {"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}, California) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_admin1_polygon(session_user, user_config, geocoder_config, admin1_name)" +PL/pgSQL function cdb_geocoder_client.geocode_admin1_polygon(text) line 9 at SQL statement geocode_admin1_polygon ------------------------ (1 row) SELECT cdb_geocoder_client.geocode_admin1_polygon('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 +NOTICE: cdb_geocoder_client._geocode_admin1_polygon(5): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.geocode_admin1_polygon invoked with params (postgres, {"is_organization": false, "entity_name": "test_user"}, {"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}, California, United States) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_admin1_polygon(session_user, user_config, geocoder_config, admin1_name, country_name)" +PL/pgSQL function cdb_geocoder_client.geocode_admin1_polygon(text,text) line 9 at SQL statement geocode_admin1_polygon ------------------------ diff --git a/client/expected/30_namedplaces_test.out b/client/expected/30_namedplaces_test.out index e476459..bca445a 100644 --- a/client/expected/30_namedplaces_test.out +++ b/client/expected/30_namedplaces_test.out @@ -1,48 +1,48 @@ -- Mock the server functions -CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_namedplace_point(user_id name, tx_id bigint, city_name text) +CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_namedplace_point(user_id name, user_config JSON, geocoder_config JSON, city_name text) RETURNS Geometry AS $$ BEGIN - RAISE NOTICE 'cdb_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, '{"is_organization": false, "entity_name": "test_user"}', '{"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}', 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) +CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_namedplace_point(user_id name, user_config JSON, geocoder_config JSON, city_name text, country_name text) RETURNS Geometry AS $$ BEGIN - RAISE NOTICE 'cdb_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, '{"is_organization": false, "entity_name": "test_user"}', '{"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}', 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) +CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_namedplace_point(user_id name, user_config JSON, geocoder_config JSON, city_name text, admin1_name text, country_name text) RETURNS Geometry AS $$ BEGIN - RAISE NOTICE 'cdb_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, '{"is_organization": false, "entity_name": "test_user"}', '{"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}', 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: 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 +NOTICE: cdb_geocoder_client._geocode_namedplace_point(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.geocode_namedplace_point invoked with params (postgres, {"is_organization": false, "entity_name": "test_user"}, {"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}, Elx) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_namedplace_point(session_user, user_config, geocoder_config, city_name)" +PL/pgSQL function cdb_geocoder_client.geocode_namedplace_point(text) line 9 at SQL statement geocode_namedplace_point -------------------------- (1 row) SELECT cdb_geocoder_client.geocode_namedplace_point('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 +NOTICE: cdb_geocoder_client._geocode_namedplace_point(5): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.geocode_namedplace_point invoked with params (postgres, {"is_organization": false, "entity_name": "test_user"}, {"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}, Elx, Spain) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_namedplace_point(session_user, user_config, geocoder_config, city_name, country_name)" +PL/pgSQL function cdb_geocoder_client.geocode_namedplace_point(text,text) line 9 at SQL statement geocode_namedplace_point -------------------------- (1 row) SELECT cdb_geocoder_client.geocode_namedplace_point('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 +NOTICE: cdb_geocoder_client._geocode_namedplace_point(6): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.geocode_namedplace_point invoked with params (postgres, {"is_organization": false, "entity_name": "test_user"}, {"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}, Elx, Valencia, Spain) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_namedplace_point(session_user, user_config, geocoder_config, city_name, admin1_name, country_name)" +PL/pgSQL function cdb_geocoder_client.geocode_namedplace_point(text,text,text) line 9 at SQL statement geocode_namedplace_point -------------------------- diff --git a/client/expected/40_postalcodes_test.out b/client/expected/40_postalcodes_test.out index a4477ec..80117b5 100644 --- a/client/expected/40_postalcodes_test.out +++ b/client/expected/40_postalcodes_test.out @@ -1,32 +1,32 @@ -- Mock the server functions -CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_postalcode_polygon(user_id name, tx_id bigint, postal_code text, country_name text) +CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_postalcode_polygon(user_id name, user_config JSON, geocoder_config JSON, postal_code text, country_name text) RETURNS Geometry AS $$ BEGIN - RAISE NOTICE 'cdb_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, '{"is_organization": false, "entity_name": "test_user"}', '{"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}', 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) +CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_postalcode_point(user_id name, user_config JSON, geocoder_config JSON, postal_code text, country_name text) RETURNS Geometry AS $$ BEGIN - RAISE NOTICE 'cdb_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, '{"is_organization": false, "entity_name": "test_user"}', '{"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}', 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: 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 +NOTICE: cdb_geocoder_client._geocode_postalcode_polygon(5): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.geocode_postalcode_polygon invoked with params (postgres, {"is_organization": false, "entity_name": "test_user"}, {"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}, 03204, Spain) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_postalcode_polygon(session_user, user_config, geocoder_config, postal_code, country_name)" +PL/pgSQL function cdb_geocoder_client.geocode_postalcode_polygon(text,text) line 9 at SQL statement geocode_postalcode_polygon ---------------------------- (1 row) SELECT cdb_geocoder_client.geocode_postalcode_point('03204', 'Spain'); -NOTICE: cdb_geocoder_client._geocode_postalcode_point(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.geocode_postalcode_point 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 +NOTICE: cdb_geocoder_client._geocode_postalcode_point(5): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.geocode_postalcode_point invoked with params (postgres, {"is_organization": false, "entity_name": "test_user"}, {"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}, 03204, Spain) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_postalcode_point(session_user, user_config, geocoder_config, postal_code, country_name)" +PL/pgSQL function cdb_geocoder_client.geocode_postalcode_point(text,text) line 9 at SQL statement geocode_postalcode_point -------------------------- diff --git a/client/expected/50_ipaddresses_test.out b/client/expected/50_ipaddresses_test.out index ef79b1a..319032e 100644 --- a/client/expected/50_ipaddresses_test.out +++ b/client/expected/50_ipaddresses_test.out @@ -1,16 +1,16 @@ -- Mock the server functions -CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_ipaddress_point(user_id name, tx_id bigint, ip_address text) +CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_ipaddress_point(user_id name, user_config JSON, geocoder_config JSON, ip_address text) RETURNS Geometry AS $$ BEGIN - RAISE NOTICE 'cdb_geocoder_server.geocode_ipaddress_point invoked with params (%, %, %)', user_id, 'some_transaction_id', ip_address; + RAISE NOTICE 'cdb_geocoder_server.geocode_ipaddress_point invoked with params (%, %, %, %)', user_id, '{"is_organization": false, "entity_name": "test_user"}', '{"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}', ip_address; RETURN NULL; END; $$ LANGUAGE 'plpgsql'; -- Exercise the public and the proxied function 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 +NOTICE: cdb_geocoder_client._geocode_ipaddress_point(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.geocode_ipaddress_point invoked with params (postgres, {"is_organization": false, "entity_name": "test_user"}, {"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}, 8.8.8.8) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_ipaddress_point(session_user, user_config, geocoder_config, ip_address)" +PL/pgSQL function cdb_geocoder_client.geocode_ipaddress_point(text) line 9 at SQL statement geocode_ipaddress_point ------------------------- diff --git a/client/expected/90_permissions_test.out b/client/expected/90_permissions_test.out index 14e78f8..e36b005 100644 --- a/client/expected/90_permissions_test.out +++ b/client/expected/90_permissions_test.out @@ -3,102 +3,102 @@ SET ROLE test_regular_user; -- Exercise the public function -- it is public, it shall work 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 +NOTICE: cdb_geocoder_client._geocode_admin0_polygon(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.geocode_admin0_polygon invoked with params (postgres, {"is_organization": false, "entity_name": "test_user"}, {"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}, Spain) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_admin0_polygon(session_user, user_config, geocoder_config, country_name)" +PL/pgSQL function cdb_geocoder_client.geocode_admin0_polygon(text) line 9 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: 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 +NOTICE: cdb_geocoder_client._geocode_admin1_polygon(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.geocode_admin1_polygon invoked with params (postgres, {"is_organization": false, "entity_name": "test_user"}, {"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}, California) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_admin1_polygon(session_user, user_config, geocoder_config, admin1_name)" +PL/pgSQL function cdb_geocoder_client.geocode_admin1_polygon(text) line 9 at SQL statement geocode_admin1_polygon ------------------------ (1 row) SELECT cdb_geocoder_client.geocode_admin1_polygon('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 +NOTICE: cdb_geocoder_client._geocode_admin1_polygon(5): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.geocode_admin1_polygon invoked with params (postgres, {"is_organization": false, "entity_name": "test_user"}, {"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}, California, United States) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_admin1_polygon(session_user, user_config, geocoder_config, admin1_name, country_name)" +PL/pgSQL function cdb_geocoder_client.geocode_admin1_polygon(text,text) line 9 at SQL statement geocode_admin1_polygon ------------------------ (1 row) SELECT cdb_geocoder_client.geocode_namedplace_point('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 +NOTICE: cdb_geocoder_client._geocode_namedplace_point(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.geocode_namedplace_point invoked with params (postgres, {"is_organization": false, "entity_name": "test_user"}, {"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}, Elx) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_namedplace_point(session_user, user_config, geocoder_config, city_name)" +PL/pgSQL function cdb_geocoder_client.geocode_namedplace_point(text) line 9 at SQL statement geocode_namedplace_point -------------------------- (1 row) SELECT cdb_geocoder_client.geocode_namedplace_point('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 +NOTICE: cdb_geocoder_client._geocode_namedplace_point(5): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.geocode_namedplace_point invoked with params (postgres, {"is_organization": false, "entity_name": "test_user"}, {"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}, Elx, Valencia) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_namedplace_point(session_user, user_config, geocoder_config, city_name, country_name)" +PL/pgSQL function cdb_geocoder_client.geocode_namedplace_point(text,text) line 9 at SQL statement geocode_namedplace_point -------------------------- (1 row) SELECT cdb_geocoder_client.geocode_namedplace_point('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 +NOTICE: cdb_geocoder_client._geocode_namedplace_point(6): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.geocode_namedplace_point invoked with params (postgres, {"is_organization": false, "entity_name": "test_user"}, {"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}, Elx, Valencia, Spain) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_namedplace_point(session_user, user_config, geocoder_config, city_name, admin1_name, country_name)" +PL/pgSQL function cdb_geocoder_client.geocode_namedplace_point(text,text,text) line 9 at SQL statement geocode_namedplace_point -------------------------- (1 row) SELECT cdb_geocoder_client.geocode_postalcode_polygon('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 +NOTICE: cdb_geocoder_client._geocode_postalcode_polygon(5): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.geocode_postalcode_polygon invoked with params (postgres, {"is_organization": false, "entity_name": "test_user"}, {"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}, 03204, Spain) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_postalcode_polygon(session_user, user_config, geocoder_config, postal_code, country_name)" +PL/pgSQL function cdb_geocoder_client.geocode_postalcode_polygon(text,text) line 9 at SQL statement geocode_postalcode_polygon ---------------------------- (1 row) SELECT cdb_geocoder_client.geocode_postalcode_point('03204', 'Spain'); -NOTICE: cdb_geocoder_client._geocode_postalcode_point(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.geocode_postalcode_point 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 +NOTICE: cdb_geocoder_client._geocode_postalcode_point(5): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.geocode_postalcode_point invoked with params (postgres, {"is_organization": false, "entity_name": "test_user"}, {"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}, 03204, Spain) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_postalcode_point(session_user, user_config, geocoder_config, postal_code, country_name)" +PL/pgSQL function cdb_geocoder_client.geocode_postalcode_point(text,text) line 9 at SQL statement geocode_postalcode_point -------------------------- (1 row) 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 +NOTICE: cdb_geocoder_client._geocode_ipaddress_point(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.geocode_ipaddress_point invoked with params (postgres, {"is_organization": false, "entity_name": "test_user"}, {"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}, 8.8.8.8) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_ipaddress_point(session_user, user_config, geocoder_config, ip_address)" +PL/pgSQL function cdb_geocoder_client.geocode_ipaddress_point(text) line 9 at SQL statement geocode_ipaddress_point ------------------------- (1 row) -- Check the regular user has no permissions on private functions -SELECT cdb_geocoder_client._geocode_admin0_polygon('evil_user', 666, 'Hell'); +SELECT cdb_geocoder_client._geocode_admin0_polygon('evil_user', '{"is_organization": false, "entity_name": "test_user"}', '{"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}', 'Hell'); ERROR: permission denied for function _geocode_admin0_polygon -SELECT cdb_geocoder_client._geocode_admin1_polygon('evil_user', 666, 'Hell'); +SELECT cdb_geocoder_client._geocode_admin1_polygon('evil_user', '{"is_organization": false, "entity_name": "test_user"}', '{"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}', 'Hell'); ERROR: permission denied for function _geocode_admin1_polygon -SELECT cdb_geocoder_client._geocode_admin1_polygon('evil_user', 666, 'Sheol', 'Hell'); +SELECT cdb_geocoder_client._geocode_admin1_polygon('evil_user', '{"is_organization": false, "entity_name": "test_user"}', '{"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}', 'Sheol', 'Hell'); ERROR: permission denied for function _geocode_admin1_polygon -SELECT cdb_geocoder_client._geocode_namedplace_point('evil_user', 666, 'Sheol'); +SELECT cdb_geocoder_client._geocode_namedplace_point('evil_user', '{"is_organization": false, "entity_name": "test_user"}', '{"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}', 'Sheol'); ERROR: permission denied for function _geocode_namedplace_point -SELECT cdb_geocoder_client._geocode_namedplace_point('evil_user', 666, 'Sheol', 'Hell'); +SELECT cdb_geocoder_client._geocode_namedplace_point('evil_user', '{"is_organization": false, "entity_name": "test_user"}', '{"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}', 'Sheol', 'Hell'); ERROR: permission denied for function _geocode_namedplace_point -SELECT cdb_geocoder_client._geocode_namedplace_point('evil_user', 666, 'Sheol', 'Hell', 'Ugly world'); +SELECT cdb_geocoder_client._geocode_namedplace_point('evil_user', '{"is_organization": false, "entity_name": "test_user"}', '{"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}', 'Sheol', 'Hell', 'Ugly world'); ERROR: permission denied for function _geocode_namedplace_point -SELECT cdb_geocoder_client._geocode_postalcode_polygon('evil_user', 666, '66666', 'Hell'); +SELECT cdb_geocoder_client._geocode_postalcode_polygon('evil_user', '{"is_organization": false, "entity_name": "test_user"}', '{"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}', '66666', 'Hell'); ERROR: permission denied for function _geocode_postalcode_polygon -SELECT cdb_geocoder_client._geocode_postalcode_point('evil_user', 666, '66666', 'Hell'); +SELECT cdb_geocoder_client._geocode_postalcode_point('evil_user', '{"is_organization": false, "entity_name": "test_user"}', '{"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}', '66666', 'Hell'); ERROR: permission denied for function _geocode_postalcode_point -SELECT cdb_geocoder_client._geocode_ipaddress_point('evil_user', 666, '8.8.8.8'); +SELECT cdb_geocoder_client._geocode_ipaddress_point('evil_user', '{"is_organization": false, "entity_name": "test_user"}', '{"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}', '8.8.8.8'); ERROR: permission denied for function _geocode_ipaddress_point diff --git a/client/sql/00_installation_test.sql b/client/sql/00_installation_test.sql index e03cafd..49c85c4 100644 --- a/client/sql/00_installation_test.sql +++ b/client/sql/00_installation_test.sql @@ -10,6 +10,10 @@ CREATE EXTENSION cdb_geocoder_client; -- Mock the server connection to point to this very test db SELECT cartodb.cdb_conf_setconf('geocoder_server_config', '{"connection_str": "dbname=contrib_regression host=127.0.0.1 user=postgres"}'); +-- Mock the user configuration +SELECT cartodb.cdb_conf_setconf('user_config', '{"is_organization": false, "entity_name": "test_user"}'); +-- Mock the geocoder configuration +SELECT cartodb.cdb_conf_setconf('geocoder_config', '{"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}'); -- Mock the server schema CREATE SCHEMA cdb_geocoder_server; diff --git a/client/sql/10_admin0_test.sql b/client/sql/10_admin0_test.sql index e54a746..42f51e8 100644 --- a/client/sql/10_admin0_test.sql +++ b/client/sql/10_admin0_test.sql @@ -1,8 +1,8 @@ -- Mock the server function -CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_admin0_polygon(user_id name, tx_id bigint, country_name text) +CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_admin0_polygon(user_id name, user_config JSON, geocoder_config JSON, country_name text) RETURNS Geometry AS $$ BEGIN - RAISE NOTICE 'cdb_geocoder_server.geocode_admin0_polygon invoked with params (%, %, %)', user_id, 'some_transaction_id', country_name; + RAISE NOTICE 'cdb_geocoder_server.geocode_admin0_polygon invoked with params (%, %, %, %)', user_id, '{"is_organization": false, "entity_name": "test_user"}', '{"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}' , country_name; RETURN NULL; END; $$ LANGUAGE 'plpgsql'; diff --git a/client/sql/20_admin1_test.sql b/client/sql/20_admin1_test.sql index 6b908aa..9867d8e 100644 --- a/client/sql/20_admin1_test.sql +++ b/client/sql/20_admin1_test.sql @@ -1,16 +1,16 @@ -- Mock the server functions -CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_admin1_polygon(user_id name, tx_id bigint, admin1_name text) +CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_admin1_polygon(user_id name, user_config JSON, geocoder_config JSON, admin1_name text) RETURNS Geometry AS $$ BEGIN - RAISE NOTICE 'cdb_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, '{"is_organization": false, "entity_name": "test_user"}', '{"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}', 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) +CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_admin1_polygon(user_id name, user_config JSON, geocoder_config JSON, admin1_name text, country_name text) RETURNS Geometry AS $$ BEGIN - RAISE NOTICE 'cdb_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, '{"is_organization": false, "entity_name": "test_user"}', '{"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}', admin1_name, country_name; RETURN NULL; END; $$ LANGUAGE 'plpgsql'; diff --git a/client/sql/30_namedplaces_test.sql b/client/sql/30_namedplaces_test.sql index f1501e7..a32d562 100644 --- a/client/sql/30_namedplaces_test.sql +++ b/client/sql/30_namedplaces_test.sql @@ -1,24 +1,24 @@ -- Mock the server functions -CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_namedplace_point(user_id name, tx_id bigint, city_name text) +CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_namedplace_point(user_id name, user_config JSON, geocoder_config JSON, city_name text) RETURNS Geometry AS $$ BEGIN - RAISE NOTICE 'cdb_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, '{"is_organization": false, "entity_name": "test_user"}', '{"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}', 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) +CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_namedplace_point(user_id name, user_config JSON, geocoder_config JSON, city_name text, country_name text) RETURNS Geometry AS $$ BEGIN - RAISE NOTICE 'cdb_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, '{"is_organization": false, "entity_name": "test_user"}', '{"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}', 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) +CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_namedplace_point(user_id name, user_config JSON, geocoder_config JSON, city_name text, admin1_name text, country_name text) RETURNS Geometry AS $$ BEGIN - RAISE NOTICE 'cdb_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, '{"is_organization": false, "entity_name": "test_user"}', '{"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}', city_name, admin1_name, country_name; RETURN NULL; END; $$ LANGUAGE 'plpgsql'; diff --git a/client/sql/40_postalcodes_test.sql b/client/sql/40_postalcodes_test.sql index a93425e..6236d20 100644 --- a/client/sql/40_postalcodes_test.sql +++ b/client/sql/40_postalcodes_test.sql @@ -1,16 +1,16 @@ -- Mock the server functions -CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_postalcode_polygon(user_id name, tx_id bigint, postal_code text, country_name text) +CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_postalcode_polygon(user_id name, user_config JSON, geocoder_config JSON, postal_code text, country_name text) RETURNS Geometry AS $$ BEGIN - RAISE NOTICE 'cdb_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, '{"is_organization": false, "entity_name": "test_user"}', '{"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}', 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) +CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_postalcode_point(user_id name, user_config JSON, geocoder_config JSON, postal_code text, country_name text) RETURNS Geometry AS $$ BEGIN - RAISE NOTICE 'cdb_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, '{"is_organization": false, "entity_name": "test_user"}', '{"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}', postal_code, country_name; RETURN NULL; END; $$ LANGUAGE 'plpgsql'; diff --git a/client/sql/50_ipaddresses_test.sql b/client/sql/50_ipaddresses_test.sql index 2007820..bfbf126 100644 --- a/client/sql/50_ipaddresses_test.sql +++ b/client/sql/50_ipaddresses_test.sql @@ -1,8 +1,8 @@ -- Mock the server functions -CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_ipaddress_point(user_id name, tx_id bigint, ip_address text) +CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_ipaddress_point(user_id name, user_config JSON, geocoder_config JSON, ip_address text) RETURNS Geometry AS $$ BEGIN - RAISE NOTICE 'cdb_geocoder_server.geocode_ipaddress_point invoked with params (%, %, %)', user_id, 'some_transaction_id', ip_address; + RAISE NOTICE 'cdb_geocoder_server.geocode_ipaddress_point invoked with params (%, %, %, %)', user_id, '{"is_organization": false, "entity_name": "test_user"}', '{"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}', ip_address; RETURN NULL; END; $$ LANGUAGE 'plpgsql'; diff --git a/client/sql/90_permissions_test.sql b/client/sql/90_permissions_test.sql index bab2ee1..1973f8b 100644 --- a/client/sql/90_permissions_test.sql +++ b/client/sql/90_permissions_test.sql @@ -14,12 +14,12 @@ SELECT cdb_geocoder_client.geocode_postalcode_point('03204', 'Spain'); 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_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'); -SELECT cdb_geocoder_client._geocode_namedplace_point('evil_user', 666, 'Sheol', 'Hell'); -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_ipaddress_point('evil_user', 666, '8.8.8.8'); +SELECT cdb_geocoder_client._geocode_admin0_polygon('evil_user', '{"is_organization": false, "entity_name": "test_user"}', '{"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}', 'Hell'); +SELECT cdb_geocoder_client._geocode_admin1_polygon('evil_user', '{"is_organization": false, "entity_name": "test_user"}', '{"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}', 'Hell'); +SELECT cdb_geocoder_client._geocode_admin1_polygon('evil_user', '{"is_organization": false, "entity_name": "test_user"}', '{"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}', 'Sheol', 'Hell'); +SELECT cdb_geocoder_client._geocode_namedplace_point('evil_user', '{"is_organization": false, "entity_name": "test_user"}', '{"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}', 'Sheol'); +SELECT cdb_geocoder_client._geocode_namedplace_point('evil_user', '{"is_organization": false, "entity_name": "test_user"}', '{"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}', 'Sheol', 'Hell'); +SELECT cdb_geocoder_client._geocode_namedplace_point('evil_user', '{"is_organization": false, "entity_name": "test_user"}', '{"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}', 'Sheol', 'Hell', 'Ugly world'); +SELECT cdb_geocoder_client._geocode_postalcode_polygon('evil_user', '{"is_organization": false, "entity_name": "test_user"}', '{"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}', '66666', 'Hell'); +SELECT cdb_geocoder_client._geocode_postalcode_point('evil_user', '{"is_organization": false, "entity_name": "test_user"}', '{"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}', '66666', 'Hell'); +SELECT cdb_geocoder_client._geocode_ipaddress_point('evil_user', '{"is_organization": false, "entity_name": "test_user"}', '{"street_geocoder_provider": "nokia","nokia_monthly_quota": 100, "nokia_soft_geocoder_limit": false}', '8.8.8.8'); diff --git a/client/templates/20_public_functions.erb b/client/templates/20_public_functions.erb index 483a3a8..4c99bd6 100644 --- a/client/templates/20_public_functions.erb +++ b/client/templates/20_public_functions.erb @@ -8,8 +8,12 @@ CREATE OR REPLACE FUNCTION <%= GEOCODER_CLIENT_SCHEMA %>.<%= name %> (<%= params RETURNS <%= return_type %> AS $$ DECLARE ret <%= return_type %>; + user_config JSON; + geocoder_config JSON; BEGIN - SELECT <%= GEOCODER_CLIENT_SCHEMA %>._<%= name %>(session_user, txid_current(), <%= params %>) INTO ret; + SELECT cartodb.CDB_Conf_GetConf('user_config') INTO user_config; + SELECT cartodb.CDB_Conf_GetConf('geocoder_config') INTO geocoder_config; + SELECT <%= GEOCODER_CLIENT_SCHEMA %>._<%= name %>(session_user, user_config, geocoder_config, <%= params %>) INTO ret; RETURN ret; END; $$ LANGUAGE 'plpgsql' SECURITY DEFINER; diff --git a/client/templates/30_plproxy_functions.erb b/client/templates/30_plproxy_functions.erb index f6d01dd..9c77c71 100644 --- a/client/templates/30_plproxy_functions.erb +++ b/client/templates/30_plproxy_functions.erb @@ -1,5 +1,5 @@ -CREATE OR REPLACE FUNCTION <%= GEOCODER_CLIENT_SCHEMA %>._<%= name %> (user_id name, tx_id bigint, <%= params_with_type %>) +CREATE OR REPLACE FUNCTION <%= GEOCODER_CLIENT_SCHEMA %>._<%= name %> (user_id name, user_config JSON, geocoder_config JSON, <%= params_with_type %>) RETURNS <%= return_type %> AS $$ CONNECT <%= GEOCODER_CLIENT_SCHEMA %>._server_conn_str(); - SELECT cdb_geocoder_server.<%= name %> (user_id, tx_id, <%= params %>); + SELECT cdb_geocoder_server.<%= name %> (user_id, user_config, geocoder_config, <%= params %>); $$ LANGUAGE plproxy;