Rename some template functions internal terms
* credentials => user_org * private => superuser
This commit is contained in:
@@ -428,21 +428,21 @@
|
|||||||
- { name: service, type: "text" }
|
- { name: service, type: "text" }
|
||||||
|
|
||||||
- name: cdb_service_set_user_rate_limit
|
- name: cdb_service_set_user_rate_limit
|
||||||
private: true
|
superuser: true
|
||||||
return_type: void
|
return_type: void
|
||||||
params:
|
params:
|
||||||
- { name: service, type: "text" }
|
- { name: service, type: "text" }
|
||||||
- { name: rate_limit, type: json }
|
- { name: rate_limit, type: json }
|
||||||
|
|
||||||
- name: cdb_service_set_org_rate_limit
|
- name: cdb_service_set_org_rate_limit
|
||||||
private: true
|
superuser: true
|
||||||
return_type: void
|
return_type: void
|
||||||
params:
|
params:
|
||||||
- { name: service, type: "text" }
|
- { name: service, type: "text" }
|
||||||
- { name: rate_limit, type: json }
|
- { name: rate_limit, type: json }
|
||||||
|
|
||||||
- name: cdb_service_set_server_rate_limit
|
- name: cdb_service_set_server_rate_limit
|
||||||
private: true
|
superuser: true
|
||||||
return_type: void
|
return_type: void
|
||||||
params:
|
params:
|
||||||
- { name: service, type: "text" }
|
- { name: service, type: "text" }
|
||||||
|
|||||||
@@ -44,29 +44,29 @@ class SqlTemplateRenderer
|
|||||||
@function_signature['geocoder_config_key']
|
@function_signature['geocoder_config_key']
|
||||||
end
|
end
|
||||||
|
|
||||||
def parameters_info(with_credentials)
|
def parameters_info(with_user_org)
|
||||||
parameters = []
|
parameters = []
|
||||||
if with_credentials
|
if with_user_org
|
||||||
parameters << { 'name' => 'username', 'type' => 'text' }
|
parameters << { 'name' => 'username', 'type' => 'text' }
|
||||||
parameters << { 'name' => 'orgname', 'type' => 'text' }
|
parameters << { 'name' => 'orgname', 'type' => 'text' }
|
||||||
end
|
end
|
||||||
parameters + @function_signature['params'].reject(&:empty?)
|
parameters + @function_signature['params'].reject(&:empty?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def credentials_declaration()
|
def user_org_declaration()
|
||||||
"username text;\n orgname text;" if public_function?
|
"username text;\n orgname text;" unless superuser_function?
|
||||||
end
|
end
|
||||||
|
|
||||||
def params(with_credentials = !public_function?)
|
def params(with_user_org = superuser_function?)
|
||||||
parameters_info(with_credentials).map { |p| p['name'].to_s }
|
parameters_info(with_user_org).map { |p| p['name'].to_s }
|
||||||
end
|
end
|
||||||
|
|
||||||
def params_with_type(with_credentials = !public_function?)
|
def params_with_type(with_user_org = superuser_function?)
|
||||||
parameters_info(with_credentials).map { |p| "#{p['name']} #{p['type']}" }
|
parameters_info(with_user_org).map { |p| "#{p['name']} #{p['type']}" }
|
||||||
end
|
end
|
||||||
|
|
||||||
def params_with_type_and_default(with_credentials = !public_function?)
|
def params_with_type_and_default(with_user_org = superuser_function?)
|
||||||
parameters = parameters_info(with_credentials).map do |p|
|
parameters = parameters_info(with_user_org).map do |p|
|
||||||
if not p['default'].nil?
|
if not p['default'].nil?
|
||||||
"#{p['name']} #{p['type']} DEFAULT #{p['default']}"
|
"#{p['name']} #{p['type']} DEFAULT #{p['default']}"
|
||||||
else
|
else
|
||||||
@@ -76,8 +76,8 @@ class SqlTemplateRenderer
|
|||||||
return parameters
|
return parameters
|
||||||
end
|
end
|
||||||
|
|
||||||
def public_function?
|
def superuser_function?
|
||||||
!@function_signature['private']
|
!!@function_signature['superuser']
|
||||||
end
|
end
|
||||||
|
|
||||||
def void_return_type?
|
def void_return_type?
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ CREATE OR REPLACE FUNCTION <%= DATASERVICES_CLIENT_SCHEMA %>.<%= name %> (<%= pa
|
|||||||
RETURNS <%= return_type %> AS $$
|
RETURNS <%= return_type %> AS $$
|
||||||
DECLARE
|
DECLARE
|
||||||
<%= return_declaration if not multi_row %>
|
<%= return_declaration if not multi_row %>
|
||||||
<%= credentials_declaration %>
|
<%= user_org_declaration %>
|
||||||
BEGIN
|
BEGIN
|
||||||
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
|
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
|
||||||
RAISE EXCEPTION 'The api_key must be provided';
|
RAISE EXCEPTION 'The api_key must be provided';
|
||||||
@@ -19,6 +19,6 @@ BEGIN
|
|||||||
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
|
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
<% return_statement do %><%= DATASERVICES_CLIENT_SCHEMA %>._<%= name %>(<%= params(true).join(', ') %>)<% end %>
|
<% return_statement do %><%= DATASERVICES_CLIENT_SCHEMA %>._<%= name %>(<%= params(_with_user_org=true).join(', ') %>)<% end %>
|
||||||
END;
|
END;
|
||||||
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ CREATE OR REPLACE FUNCTION <%= DATASERVICES_CLIENT_SCHEMA %>._<%= name %>_except
|
|||||||
RETURNS <%= return_type %> AS $$
|
RETURNS <%= return_type %> AS $$
|
||||||
DECLARE
|
DECLARE
|
||||||
<%= return_declaration %>
|
<%= return_declaration %>
|
||||||
<%= credentials_declaration %>
|
<%= user_org_declaration %>
|
||||||
_returned_sqlstate TEXT;
|
_returned_sqlstate TEXT;
|
||||||
_message_text TEXT;
|
_message_text TEXT;
|
||||||
_pg_exception_context TEXT;
|
_pg_exception_context TEXT;
|
||||||
@@ -22,7 +22,7 @@ BEGIN
|
|||||||
|
|
||||||
|
|
||||||
BEGIN
|
BEGIN
|
||||||
<% return_statement do %><%= DATASERVICES_CLIENT_SCHEMA %>._<%= name %>(<%= params(true).join(', ') %>)<% end %>
|
<% return_statement do %><%= DATASERVICES_CLIENT_SCHEMA %>._<%= name %>(<%= params(_with_user_org=true).join(', ') %>)<% end %>
|
||||||
EXCEPTION
|
EXCEPTION
|
||||||
WHEN OTHERS THEN
|
WHEN OTHERS THEN
|
||||||
GET STACKED DIAGNOSTICS _returned_sqlstate = RETURNED_SQLSTATE,
|
GET STACKED DIAGNOSTICS _returned_sqlstate = RETURNED_SQLSTATE,
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
CREATE OR REPLACE FUNCTION <%= DATASERVICES_CLIENT_SCHEMA %>._<%= name %> (<%= params_with_type_and_default(true).join(', ') %>)
|
CREATE OR REPLACE FUNCTION <%= DATASERVICES_CLIENT_SCHEMA %>._<%= name %> (<%= params_with_type_and_default(_with_user_org=true).join(', ') %>)
|
||||||
RETURNS <%= return_type %> AS $$
|
RETURNS <%= return_type %> AS $$
|
||||||
CONNECT <%= DATASERVICES_CLIENT_SCHEMA %>._server_conn_str();
|
CONNECT <%= DATASERVICES_CLIENT_SCHEMA %>._server_conn_str();
|
||||||
<% if multi_field %>
|
<% if multi_field %>
|
||||||
SELECT * FROM <%= DATASERVICES_SERVER_SCHEMA %>.<%= name %> (<%= params(true).join(', ') %>);
|
SELECT * FROM <%= DATASERVICES_SERVER_SCHEMA %>.<%= name %> (<%= params(_with_user_org=true).join(', ') %>);
|
||||||
<% else %>
|
<% else %>
|
||||||
SELECT <%= DATASERVICES_SERVER_SCHEMA %>.<%= name %> (<%= params(true).join(', ') %>);
|
SELECT <%= DATASERVICES_SERVER_SCHEMA %>.<%= name %> (<%= params(_with_user_org=true).join(', ') %>);
|
||||||
<% end %>
|
<% end %>
|
||||||
$$ LANGUAGE plproxy;
|
$$ LANGUAGE plproxy;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<% if public_function? %>
|
<% unless superuser_function? %>
|
||||||
GRANT EXECUTE ON FUNCTION <%= DATASERVICES_CLIENT_SCHEMA %>.<%= name %>(<%= params_with_type.join(', ') %>) TO publicuser;
|
GRANT EXECUTE ON FUNCTION <%= DATASERVICES_CLIENT_SCHEMA %>.<%= name %>(<%= params_with_type.join(', ') %>) TO publicuser;
|
||||||
GRANT EXECUTE ON FUNCTION <%= DATASERVICES_CLIENT_SCHEMA %>._<%= name %>_exception_safe(<%= params_with_type.join(', ') %> ) TO publicuser;
|
GRANT EXECUTE ON FUNCTION <%= DATASERVICES_CLIENT_SCHEMA %>._<%= name %>_exception_safe(<%= params_with_type.join(', ') %> ) TO publicuser;
|
||||||
<% end %>
|
<% end %>
|
||||||
Reference in New Issue
Block a user