Merge pull request #28 from CartoDB/implementing_client_functions
Implementing client functions
This commit is contained in:
commit
20fa7da928
34
client/expected/20_admin1_test.out
Normal file
34
client/expected/20_admin1_test.out
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
-- Mock the server functions
|
||||||
|
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;
|
||||||
|
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;
|
||||||
|
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)
|
||||||
|
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
|
||||||
|
------------------------
|
||||||
|
|
||||||
|
(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)
|
||||||
|
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
|
||||||
|
------------------------
|
||||||
|
|
||||||
|
(1 row)
|
||||||
|
|
50
client/expected/30_namedplaces_test.out
Normal file
50
client/expected/30_namedplaces_test.out
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
-- Mock the server functions
|
||||||
|
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;
|
||||||
|
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;
|
||||||
|
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;
|
||||||
|
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)
|
||||||
|
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
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
(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)
|
||||||
|
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
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
(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)
|
||||||
|
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
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
(1 row)
|
||||||
|
|
34
client/expected/40_postalcodes_test.out
Normal file
34
client/expected/40_postalcodes_test.out
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
-- 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)
|
||||||
|
RETURNS Geometry AS $$
|
||||||
|
BEGIN
|
||||||
|
RAISE NOTICE 'cbd_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;
|
||||||
|
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)
|
||||||
|
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
|
||||||
|
----------------------------
|
||||||
|
|
||||||
|
(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)
|
||||||
|
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
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
(1 row)
|
||||||
|
|
18
client/expected/50_ipaddresses_test.out
Normal file
18
client/expected/50_ipaddresses_test.out
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
-- Mock the server functions
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_ip(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;
|
||||||
|
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
|
||||||
|
------------
|
||||||
|
|
||||||
|
(1 row)
|
||||||
|
|
@ -11,9 +11,97 @@ PL/pgSQL function cdb_geocoder_client.geocode_admin0_polygons(text) line 5 at SQ
|
|||||||
|
|
||||||
(1 row)
|
(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)
|
||||||
|
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
|
||||||
|
------------------------
|
||||||
|
|
||||||
|
(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)
|
||||||
|
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
|
||||||
|
------------------------
|
||||||
|
|
||||||
|
(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)
|
||||||
|
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
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
(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)
|
||||||
|
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
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
(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)
|
||||||
|
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
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
(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)
|
||||||
|
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
|
||||||
|
----------------------------
|
||||||
|
|
||||||
|
(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)
|
||||||
|
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
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
(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
|
||||||
|
------------
|
||||||
|
|
||||||
|
(1 row)
|
||||||
|
|
||||||
-- Check the regular user has no permissions on private functions
|
-- 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_polygons('evil_user', 666, 'Hell');
|
||||||
ERROR: permission denied for function _geocode_admin0_polygons
|
ERROR: permission denied for function _geocode_admin0_polygons
|
||||||
|
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');
|
||||||
|
ERROR: permission denied for function _geocode_admin1_polygon
|
||||||
|
SELECT cdb_geocoder_client._geocode_namedplace_point('evil_user', 666, 'Sheol');
|
||||||
|
ERROR: permission denied for function _geocode_namedplace_point
|
||||||
|
SELECT cdb_geocoder_client._geocode_namedplace_point('evil_user', 666, 'Sheol', 'Hell');
|
||||||
|
ERROR: permission denied for function _geocode_namedplace_point
|
||||||
|
SELECT cdb_geocoder_client._geocode_namedplace_point('evil_user', 666, 'Sheol', 'Hell', 'Ugly world');
|
||||||
|
ERROR: permission denied for function _geocode_namedplace_point
|
||||||
|
SELECT cdb_geocoder_client._geocode_postalcode_polygon('evil_user', 666, '66666', 'Hell');
|
||||||
|
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
|
-- Check the regular user cannot look into config table
|
||||||
SELECT * from cdb_geocoder_client._config;
|
SELECT * from cdb_geocoder_client._config;
|
||||||
ERROR: permission denied for relation _config
|
ERROR: permission denied for relation _config
|
||||||
|
45
client/sql/0.0.1/20_admin1.sql
Normal file
45
client/sql/0.0.1/20_admin1.sql
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
--
|
||||||
|
-- Public geocoder API function
|
||||||
|
--
|
||||||
|
-- These are the only ones with permissions to publicuser role
|
||||||
|
-- and should also be the only ones with SECURITY DEFINER
|
||||||
|
|
||||||
|
---- geocode_admin1_polygon(admin1_name text)
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_geocoder_client.geocode_admin1_polygon(admin1_name text)
|
||||||
|
RETURNS Geometry AS $$
|
||||||
|
DECLARE
|
||||||
|
ret Geometry;
|
||||||
|
BEGIN
|
||||||
|
SELECT cdb_geocoder_client._geocode_admin1_polygon(session_user, txid_current(), admin1_name) INTO ret;
|
||||||
|
RETURN ret;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||||
|
|
||||||
|
---- geocode_admin1_polygon(admin1_name text, country_name text)
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_geocoder_client.geocode_admin1_polygon(admin1_name text, country_name text)
|
||||||
|
RETURNS Geometry AS $$
|
||||||
|
DECLARE
|
||||||
|
ret Geometry;
|
||||||
|
BEGIN
|
||||||
|
SELECT cdb_geocoder_client._geocode_admin1_polygon(session_user, txid_current(), admin1_name, country_name) INTO ret;
|
||||||
|
RETURN ret;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||||
|
|
||||||
|
-- TODO: review all permissions stuff [I'd explicitly grant permissions to the public functions]
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
---- geocode_admin1_polygon(admin1_name text)
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_geocoder_client._geocode_admin1_polygon(user_id name, tx_id bigint, admin1_name text)
|
||||||
|
RETURNS Geometry AS $$
|
||||||
|
CONNECT cdb_geocoder_client._server_conn_str();
|
||||||
|
SELECT cdb_geocoder_server.geocode_admin1_polygon(user_id, tx_id, admin1_name);
|
||||||
|
$$ LANGUAGE plproxy;
|
||||||
|
|
||||||
|
---- geocode_admin1_polygon(admin1_name text, country_name text)
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_geocoder_client._geocode_admin1_polygon(user_id name, tx_id bigint, admin1_name text, country_name text)
|
||||||
|
RETURNS Geometry AS $$
|
||||||
|
CONNECT cdb_geocoder_client._server_conn_str();
|
||||||
|
SELECT cdb_geocoder_server.geocode_admin1_polygon(user_id, tx_id, admin1_name, country_name);
|
||||||
|
$$ LANGUAGE plproxy;
|
62
client/sql/0.0.1/30_namedplaces.sql
Normal file
62
client/sql/0.0.1/30_namedplaces.sql
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
--
|
||||||
|
-- Public geocoder API function
|
||||||
|
--
|
||||||
|
-- These are the only ones with permissions to publicuser role
|
||||||
|
-- and should also be the only ones with SECURITY DEFINER
|
||||||
|
|
||||||
|
---- geocode_namedplace_point(city_name text)
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_geocoder_client.geocode_namedplace_point(city_name text)
|
||||||
|
RETURNS Geometry AS $$
|
||||||
|
DECLARE
|
||||||
|
ret Geometry;
|
||||||
|
BEGIN
|
||||||
|
SELECT cdb_geocoder_client._geocode_namedplace_point(session_user, txid_current(), city_name) INTO ret;
|
||||||
|
RETURN ret;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||||
|
|
||||||
|
---- geocode_namedplace_point(city_name text, country_name text)
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_geocoder_client.geocode_namedplace_point(city_name text, country_name text)
|
||||||
|
RETURNS Geometry AS $$
|
||||||
|
DECLARE
|
||||||
|
ret Geometry;
|
||||||
|
BEGIN
|
||||||
|
SELECT cdb_geocoder_client._geocode_namedplace_point(session_user, txid_current(), city_name, country_name) INTO ret;
|
||||||
|
RETURN ret;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||||
|
|
||||||
|
---- geocode_namedplace_point(city_name text, admin1_name text, country_name text)
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_geocoder_client.geocode_namedplace_point(city_name text, admin1_name text, country_name text)
|
||||||
|
RETURNS Geometry AS $$
|
||||||
|
DECLARE
|
||||||
|
ret Geometry;
|
||||||
|
BEGIN
|
||||||
|
SELECT cdb_geocoder_client._geocode_namedplace_point(session_user, txid_current(), city_name, admin1_name, country_name) INTO ret;
|
||||||
|
RETURN ret;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||||
|
-- TODO: review all permissions stuff [I'd explicitly grant permissions to the public functions]
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
---- geocode_namedplace_point(city_name text)
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_geocoder_client._geocode_namedplace_point(user_id name, tx_id bigint, city_name text)
|
||||||
|
RETURNS Geometry AS $$
|
||||||
|
CONNECT cdb_geocoder_client._server_conn_str();
|
||||||
|
SELECT cdb_geocoder_server.geocode_namedplace_point(user_id, tx_id, city_name);
|
||||||
|
$$ LANGUAGE plproxy;
|
||||||
|
|
||||||
|
---- geocode_namedplace_point(city_name text, country_name text)
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_geocoder_client._geocode_namedplace_point(user_id name, tx_id bigint, city_name text, country_name text)
|
||||||
|
RETURNS Geometry AS $$
|
||||||
|
CONNECT cdb_geocoder_client._server_conn_str();
|
||||||
|
SELECT cdb_geocoder_server.geocode_namedplace_point(user_id, tx_id, city_name, country_name);
|
||||||
|
$$ LANGUAGE plproxy;
|
||||||
|
|
||||||
|
---- geocode_namedplace_point(city_name text, admin1_name text, country_name text)
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_geocoder_client._geocode_namedplace_point(user_id name, tx_id bigint, city_name text, admin1_name text, country_name text)
|
||||||
|
RETURNS Geometry AS $$
|
||||||
|
CONNECT cdb_geocoder_client._server_conn_str();
|
||||||
|
SELECT cdb_geocoder_server.geocode_namedplace_point(user_id, tx_id, city_name, admin1_name, country_name);
|
||||||
|
$$ LANGUAGE plproxy;
|
45
client/sql/0.0.1/40_postalcodes.sql
Normal file
45
client/sql/0.0.1/40_postalcodes.sql
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
--
|
||||||
|
-- Public geocoder API function
|
||||||
|
--
|
||||||
|
-- These are the only ones with permissions to publicuser role
|
||||||
|
-- and should also be the only ones with SECURITY DEFINER
|
||||||
|
|
||||||
|
---- geocode_postalcode_polygon(postal_code text, country_name text)
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_geocoder_client.geocode_postalcode_polygon(postal_code text, country_name text)
|
||||||
|
RETURNS Geometry AS $$
|
||||||
|
DECLARE
|
||||||
|
ret Geometry;
|
||||||
|
BEGIN
|
||||||
|
SELECT cdb_geocoder_client._geocode_postalcode_polygon(session_user, txid_current(), postal_code, country_name) INTO ret;
|
||||||
|
RETURN ret;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||||
|
|
||||||
|
---- geocode_postalcode_polygon(postal_code integer, country_name text)
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_geocoder_client.geocode_postalcode_point(postal_code text, country_name text)
|
||||||
|
RETURNS Geometry AS $$
|
||||||
|
DECLARE
|
||||||
|
ret Geometry;
|
||||||
|
BEGIN
|
||||||
|
SELECT cdb_geocoder_client._geocode_postalcode_point(session_user, txid_current(), postal_code, country_name) INTO ret;
|
||||||
|
RETURN ret;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||||
|
|
||||||
|
-- TODO: review all permissions stuff [I'd explicitly grant permissions to the public functions]
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
---- geocode_postalcode_polygon(postal_code text, country_name text)
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_geocoder_client._geocode_postalcode_polygon(user_id name, tx_id bigint, postal_code text, country_name text)
|
||||||
|
RETURNS Geometry AS $$
|
||||||
|
CONNECT cdb_geocoder_client._server_conn_str();
|
||||||
|
SELECT cdb_geocoder_server.geocode_postalcode_polygon(user_id, tx_id, postal_code, country_name);
|
||||||
|
$$ LANGUAGE plproxy;
|
||||||
|
|
||||||
|
---- geocode_postalcode_polygon(postal_code text, country_name text)
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_geocoder_client._geocode_postalcode_point(user_id name, tx_id bigint, postal_code text, country_name text)
|
||||||
|
RETURNS Geometry AS $$
|
||||||
|
CONNECT cdb_geocoder_client._server_conn_str();
|
||||||
|
SELECT cdb_geocoder_server.geocode_postalcode_polygon(user_id, tx_id, postal_code, country_name);
|
||||||
|
$$ LANGUAGE plproxy;
|
27
client/sql/0.0.1/50_ipaddresses.sql
Normal file
27
client/sql/0.0.1/50_ipaddresses.sql
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
--
|
||||||
|
-- Public geocoder API function
|
||||||
|
--
|
||||||
|
-- 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)
|
||||||
|
RETURNS Geometry AS $$
|
||||||
|
DECLARE
|
||||||
|
ret Geometry;
|
||||||
|
BEGIN
|
||||||
|
SELECT cdb_geocoder_client._geocode_ip(session_user, txid_current(), ip_address) INTO ret;
|
||||||
|
RETURN ret;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||||
|
|
||||||
|
-- TODO: review all permissions stuff [I'd explicitly grant permissions to the public functions]
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
---- geocode_ip(ip_address text)
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_geocoder_client._geocode_ip(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);
|
||||||
|
$$ LANGUAGE plproxy;
|
@ -13,3 +13,11 @@ REVOKE EXECUTE ON ALL FUNCTIONS IN SCHEMA cdb_geocoder_client FROM PUBLIC, publi
|
|||||||
-- Explicitly grant permissions to public functions
|
-- Explicitly grant permissions to public functions
|
||||||
-- NOTE: All public functions must be listed below, grating permissions to publicuser
|
-- 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_polygons(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;
|
||||||
|
GRANT EXECUTE ON FUNCTION cdb_geocoder_client.geocode_namedplace_point(city_name text, country_name text) TO publicuser;
|
||||||
|
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;
|
||||||
|
21
client/sql/20_admin1_test.sql
Normal file
21
client/sql/20_admin1_test.sql
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
-- Mock the server functions
|
||||||
|
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;
|
||||||
|
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;
|
||||||
|
RETURN NULL;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE 'plpgsql';
|
||||||
|
|
||||||
|
|
||||||
|
-- Exercise the public and the proxied function
|
||||||
|
SELECT cdb_geocoder_client.geocode_admin1_polygon('California');
|
||||||
|
SELECT cdb_geocoder_client.geocode_admin1_polygon('California', 'United States');
|
30
client/sql/30_namedplaces_test.sql
Normal file
30
client/sql/30_namedplaces_test.sql
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
-- Mock the server functions
|
||||||
|
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;
|
||||||
|
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;
|
||||||
|
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;
|
||||||
|
RETURN NULL;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE 'plpgsql';
|
||||||
|
|
||||||
|
-- Exercise the public and the proxied function
|
||||||
|
SELECT cdb_geocoder_client.geocode_namedplace_point('Elx');
|
||||||
|
SELECT cdb_geocoder_client.geocode_namedplace_point('Elx', 'Spain');
|
||||||
|
SELECT cdb_geocoder_client.geocode_namedplace_point('Elx', 'Valencia', 'Spain');
|
||||||
|
|
20
client/sql/40_postalcodes_test.sql
Normal file
20
client/sql/40_postalcodes_test.sql
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
-- 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)
|
||||||
|
RETURNS Geometry AS $$
|
||||||
|
BEGIN
|
||||||
|
RAISE NOTICE 'cbd_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;
|
||||||
|
RETURN NULL;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE 'plpgsql';
|
||||||
|
|
||||||
|
-- Exercise the public and the proxied function
|
||||||
|
SELECT cdb_geocoder_client.geocode_postalcode_polygon('03204', 'Spain');
|
||||||
|
SELECT cdb_geocoder_client.geocode_postalcode_point('03204', 'Spain');
|
12
client/sql/50_ipaddresses_test.sql
Normal file
12
client/sql/50_ipaddresses_test.sql
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
-- Mock the server functions
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_ip(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;
|
||||||
|
RETURN NULL;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE 'plpgsql';
|
||||||
|
|
||||||
|
|
||||||
|
-- Exercise the public and the proxied function
|
||||||
|
SELECT cdb_geocoder_client.geocode_ip('8.8.8.8');
|
@ -4,9 +4,25 @@ SET ROLE test_regular_user;
|
|||||||
-- Exercise the public function
|
-- Exercise the public function
|
||||||
-- it is public, it shall work
|
-- it is public, it shall work
|
||||||
SELECT cdb_geocoder_client.geocode_admin0_polygons('Spain');
|
SELECT cdb_geocoder_client.geocode_admin0_polygons('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');
|
||||||
|
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');
|
||||||
|
|
||||||
-- Check the regular user has no permissions on private functions
|
-- 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_polygons('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_ip('evil_user', 666, '8.8.8.8');
|
||||||
|
|
||||||
-- Check the regular user cannot look into config table
|
-- Check the regular user cannot look into config table
|
||||||
SELECT * from cdb_geocoder_client._config;
|
SELECT * from cdb_geocoder_client._config;
|
||||||
|
Loading…
Reference in New Issue
Block a user