Expose client-side rate limit configuration interface
The client functions to make configuration changes are not publicly available (require a super user) and they have username, orgname parameters like the server-sixe functions
This commit is contained in:
@@ -17,7 +17,7 @@ class SqlTemplateRenderer
|
||||
end
|
||||
|
||||
def render
|
||||
ERB.new(@template).result(binding)
|
||||
ERB.new(@template, nil, '-').result(binding)
|
||||
end
|
||||
|
||||
def name
|
||||
@@ -44,16 +44,29 @@ class SqlTemplateRenderer
|
||||
@function_signature['geocoder_config_key']
|
||||
end
|
||||
|
||||
def params
|
||||
@function_signature['params'].reject(&:empty?).map { |p| "#{p['name']}"}
|
||||
def parameters_info(with_credentials)
|
||||
parameters = []
|
||||
if with_credentials
|
||||
parameters << { 'name' => 'username', 'type' => 'text' }
|
||||
parameters << { 'name' => 'orgname', 'type' => 'text' }
|
||||
end
|
||||
parameters + @function_signature['params'].reject(&:empty?)
|
||||
end
|
||||
|
||||
def params_with_type
|
||||
@function_signature['params'].reject(&:empty?).map { |p| "#{p['name']} #{p['type']}" }
|
||||
def credentials_declaration()
|
||||
"username text;\n orgname text;" if public_function?
|
||||
end
|
||||
|
||||
def params_with_type_and_default
|
||||
parameters = @function_signature['params'].reject(&:empty?).map do |p|
|
||||
def params(with_credentials = !public_function?)
|
||||
parameters_info(with_credentials).map { |p| p['name'].to_s }
|
||||
end
|
||||
|
||||
def params_with_type(with_credentials = !public_function?)
|
||||
parameters_info(with_credentials).map { |p| "#{p['name']} #{p['type']}" }
|
||||
end
|
||||
|
||||
def params_with_type_and_default(with_credentials = !public_function?)
|
||||
parameters = parameters_info(with_credentials).map do |p|
|
||||
if not p['default'].nil?
|
||||
"#{p['name']} #{p['type']} DEFAULT #{p['default']}"
|
||||
else
|
||||
@@ -62,6 +75,49 @@ class SqlTemplateRenderer
|
||||
end
|
||||
return parameters
|
||||
end
|
||||
|
||||
def public_function?
|
||||
!@function_signature['private']
|
||||
end
|
||||
|
||||
def void_return_type?
|
||||
return_type.downcase == 'void'
|
||||
end
|
||||
|
||||
def return_declaration
|
||||
"ret #{return_type};" unless void_return_type? || multi_row
|
||||
end
|
||||
|
||||
def return_statement(&block)
|
||||
if block
|
||||
erbout = block.binding.eval('_erbout')
|
||||
|
||||
if multi_row
|
||||
erbout << 'RETURN QUERY SELECT * FROM '
|
||||
elsif multi_field
|
||||
erbout << 'SELECT * FROM '
|
||||
elsif void_return_type?
|
||||
erbout << 'PERFORM '
|
||||
else
|
||||
erbout << 'SELECT '
|
||||
end
|
||||
yield
|
||||
if multi_row || void_return_type?
|
||||
erbout << ';'
|
||||
else
|
||||
erbout << ' INTO ret;'
|
||||
end
|
||||
if !multi_row && !void_return_type?
|
||||
erbout << ' RETURN ret;'
|
||||
end
|
||||
else
|
||||
if !multi_row && !void_return_type?
|
||||
' RETURN ret;'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user