diff --git a/client/Makefile b/client/Makefile index 652539f..02066e2 100644 --- a/client/Makefile +++ b/client/Makefile @@ -12,14 +12,29 @@ PG_CONFIG = pg_config PGXS := $(shell $(PG_CONFIG) --pgxs) include $(PGXS) +SOURCES_DATA_DIR = sql/$(EXTVERSION) -SOURCES_DATA = $(wildcard sql/$(EXTVERSION)/*.sql) +# The interface definition is used along with some templates to automatically generate code +RENDERER = ../sql-template-renderer +INTERFACE_FILE = ../interface.csv +TEMPLATE_DIR = templates +TEMPLATE_FILES = $(wildcard $(TEMPLATE_DIR)/*.erb) +GENERATED_SQL_FILES = $(patsubst $(TEMPLATE_DIR)/%.erb, $(SOURCES_DATA_DIR)/%.sql, $(TEMPLATE_FILES)) + +$(GENERATED_SQL_FILES): $(SOURCES_DATA_DIR)/%.sql: $(TEMPLATE_DIR)/%.erb $(INTERFACE_FILE) $(RENDERER) + $(RENDERER) $(INTERFACE_FILE) $< > $@ + +all: $(GENERATED_SQL_FILES) + @echo $(GENERATED_SQL_FILES) + + +SOURCES_DATA = $(wildcard $(SOURCES_DATA_DIR)/*.sql) $(DATA): $(SOURCES_DATA) rm -f $@ cat $(SOURCES_DATA) >> $@ -all: $(DATA) +#all: $(DATA) # Only meant for development time, do not use once a version is released devclean: diff --git a/client/sql/0.0.1/10_admin0.sql b/client/sql/0.0.1/10_admin0.sql deleted file mode 100644 index 6337496..0000000 --- a/client/sql/0.0.1/10_admin0.sql +++ /dev/null @@ -1,26 +0,0 @@ --- --- Public geocoder API function --- --- 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_polygon(country_name text) -RETURNS Geometry AS $$ -DECLARE - ret Geometry; -BEGIN - SELECT cdb_geocoder_client._geocode_admin0_polygon(session_user, txid_current(), 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] - --------------------------------------------------------------------------------- - -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_polygon(user_id, tx_id, country_name); -$$ LANGUAGE plproxy; diff --git a/client/sql/0.0.1/06_geocoder_server_conn.sql b/client/sql/0.0.1/10_geocoder_server_conn.sql similarity index 100% rename from client/sql/0.0.1/06_geocoder_server_conn.sql rename to client/sql/0.0.1/10_geocoder_server_conn.sql diff --git a/client/sql/0.0.1/20_admin1.sql b/client/sql/0.0.1/20_admin1.sql deleted file mode 100644 index f7d0088..0000000 --- a/client/sql/0.0.1/20_admin1.sql +++ /dev/null @@ -1,45 +0,0 @@ --- --- 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; diff --git a/client/sql/0.0.1/30_namedplaces.sql b/client/sql/0.0.1/30_namedplaces.sql deleted file mode 100644 index 8ac6a9d..0000000 --- a/client/sql/0.0.1/30_namedplaces.sql +++ /dev/null @@ -1,62 +0,0 @@ --- --- 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; \ No newline at end of file diff --git a/client/sql/0.0.1/40_postalcodes.sql b/client/sql/0.0.1/40_postalcodes.sql deleted file mode 100644 index f3afcc8..0000000 --- a/client/sql/0.0.1/40_postalcodes.sql +++ /dev/null @@ -1,45 +0,0 @@ --- --- 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; diff --git a/client/sql/0.0.1/50_ipaddresses.sql b/client/sql/0.0.1/50_ipaddresses.sql deleted file mode 100644 index 60602ab..0000000 --- a/client/sql/0.0.1/50_ipaddresses.sql +++ /dev/null @@ -1,27 +0,0 @@ --- --- 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_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_ipaddress_point(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_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_ipaddress_point(user_id, tx_id, ip_address); -$$ LANGUAGE plproxy; diff --git a/client/sql/0.0.1/80_permissions.sql b/client/sql/0.0.1/80_permissions.sql new file mode 100644 index 0000000..16fc021 --- /dev/null +++ b/client/sql/0.0.1/80_permissions.sql @@ -0,0 +1,9 @@ +-- Make sure by default there are no permissions for publicuser +-- NOTE: this happens at extension creation time, as part of an implicit transaction. +REVOKE ALL PRIVILEGES ON SCHEMA cdb_geocoder_client FROM PUBLIC, publicuser CASCADE; + +-- Grant permissions on the schema to publicuser (but just the schema) +GRANT USAGE ON SCHEMA cdb_geocoder_client TO publicuser; + +-- Revoke execute permissions on all functions in the schema by default +REVOKE EXECUTE ON ALL FUNCTIONS IN SCHEMA cdb_geocoder_client FROM PUBLIC, publicuser; diff --git a/client/sql/0.0.1/90_permissions.sql b/client/sql/0.0.1/90_permissions.sql deleted file mode 100644 index 9fea793..0000000 --- a/client/sql/0.0.1/90_permissions.sql +++ /dev/null @@ -1,23 +0,0 @@ --- Make sure by default there are no permissions for publicuser --- NOTE: this happens at extension creation time, as part of an implicit transaction. -REVOKE ALL PRIVILEGES ON SCHEMA cdb_geocoder_client FROM PUBLIC, publicuser CASCADE; - --- Grant permissions on the schema to publicuser (but just the schema) -GRANT USAGE ON SCHEMA cdb_geocoder_client TO publicuser; - --- Revoke execute permissions on all functions in the schema by default -REVOKE EXECUTE ON ALL FUNCTIONS IN SCHEMA cdb_geocoder_client FROM PUBLIC, publicuser; - --------------------------------------------------------------------------------- - --- 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_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; -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_ipaddress_point(ip_address text) TO publicuser; diff --git a/interface/templates/client-public-function.erb b/client/templates/20_public_functions.erb similarity index 100% rename from interface/templates/client-public-function.erb rename to client/templates/20_public_functions.erb diff --git a/interface/templates/client-plproxy-function.erb b/client/templates/30_plproxy_functions.erb similarity index 100% rename from interface/templates/client-plproxy-function.erb rename to client/templates/30_plproxy_functions.erb diff --git a/interface/templates/client-grant-execute.erb b/client/templates/90_grant_execute.erb similarity index 100% rename from interface/templates/client-grant-execute.erb rename to client/templates/90_grant_execute.erb diff --git a/interface/interface.csv b/interface.csv similarity index 100% rename from interface/interface.csv rename to interface.csv diff --git a/interface/sql-template-renderer b/sql-template-renderer similarity index 100% rename from interface/sql-template-renderer rename to sql-template-renderer