diff --git a/interface/generate-grant-execute.rb b/interface/generate-grant-execute.rb index b572723..2cb001f 100644 --- a/interface/generate-grant-execute.rb +++ b/interface/generate-grant-execute.rb @@ -23,9 +23,28 @@ class GrantExecute end end +class PublicFunctionDefinition + TEMPLATE_FILE = 'templates/public-function-definition.erb' + + attr_reader :function_signature + + def initialize(function_signature) + @function_signature = function_signature + @template = File.read(TEMPLATE_FILE) + end + + def render + ERB.new(@template).result(binding) + end +end CSV.foreach(INTERFACE_SOURCE_FILE, {headers: true}) do |function_signature| + + function_definition = PublicFunctionDefinition.new(function_signature).render + puts function_definition + + grant = GrantExecute.new(function_signature).render - puts grant + #puts grant end diff --git a/interface/templates/public-function-definition.erb b/interface/templates/public-function-definition.erb new file mode 100644 index 0000000..8bef626 --- /dev/null +++ b/interface/templates/public-function-definition.erb @@ -0,0 +1,24 @@ +-- +-- 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 <%= GEOCODER_CLIENT_SCHEMA %>.<%= function_signature['function_name'] %> (<%= function_signature['argument_data_types'] %>) +RETURNS <%= function_signature['result_data_type'] %> AS $$ +DECLARE + ret <%= function_signature['result_data_type'] %>; +BEGIN + -- TODO: this is to be changed according to the feature doc + SELECT <%= GEOCODER_CLIENT_SCHEMA %>._geocode_admin0_polygon(session_user, txid_current(), <%= function_signature['argument_data_types'] %>) INTO ret; + RETURN ret; +END; +$$ LANGUAGE 'plpgsql' SECURITY DEFINER; + +-------------------------------------------------------------------------------- + +CREATE OR REPLACE FUNCTION <%= GEOCODER_CLIENT_SCHEMA %>._<%= function_signature['function_name'] %> (user_id name, tx_id bigint, <%= function_signature['argument_data_types'] %>) +RETURNS Geometry AS $$ + CONNECT <%= GEOCODER_CLIENT_SCHEMA %>._server_conn_str(); + SELECT cdb_geocoder_server.<%= function_signature['function_name'] %> (user_id, tx_id, function_signature['argument_data_types']); +$$ LANGUAGE plproxy;