Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize
end

def handle_request(args)
return {} unless args[:params]['collection_name']
return [] unless args[:params]['collection_name']

datasource = ForestAdminRpcAgent::Facades::Container.datasource
collection = get_collection_safe(datasource, args[:params]['collection_name'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ def initialize
end

def handle_request(args)
return {} unless args[:params]['collection_name']
return [] unless args[:params]['collection_name']

datasource = ForestAdminRpcAgent::Facades::Container.datasource
collection = get_collection_safe(datasource, args[:params]['collection_name'])

aggregation = Aggregation.new(
operation: args[:params]['aggregation']['operation'],
field: args[:params]['aggregation']['field'],
groups: args[:params]['aggregation']['groups']
groups: args[:params]['aggregation']['groups'] || []
Comment thread
arnaud-moncel marked this conversation as resolved.
)
filter = FilterFactory.from_plain_object(args[:params]['filter'])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ def register_rails(router)

# Skip authentication for health check (root path)
if @url == '/'
params = deep_symbolize_keys(request.query_parameters.merge(request.request_parameters))
result = handle_request({ params: params.with_indifferent_access, caller: nil, request: request })
params = extract_request_params(request)
result = handle_request({ params: params, caller: nil, request: request })
build_rails_response(result)
else
auth_middleware = ForestAdminRpcAgent::Middleware::Authentication.new(->(_env) { [200, {}, ['OK']] })
status, headers, response = auth_middleware.call(request.env)

if status == 200
params = deep_symbolize_keys(request.query_parameters.merge(request.request_parameters))
result = handle_request({ params: params.with_indifferent_access, caller: headers[:caller], request: request })
params = extract_request_params(request)
result = handle_request({ params: params, caller: headers[:caller], request: request })
build_rails_response(result)
else
[status, headers, response]
Expand Down Expand Up @@ -87,6 +87,16 @@ def get_collection_safe(datasource, collection_name)

private

# Merge path params (e.g. :collection_name from the URL) with query and body params so
# consumers that don't duplicate `collection_name` in the body (the Node datasource-rpc)
# still resolve the route correctly.
def extract_request_params(request)
merged = request.path_parameters
.merge(request.query_parameters)
.merge(request.request_parameters)
deep_symbolize_keys(merged).with_indifferent_access
end

def deep_symbolize_keys(obj)
case obj
when Hash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def initialize
end

def handle_request(args)
return {} unless args[:params]['collection_name']
return [] unless args[:params]['collection_name']
Comment thread
arnaud-moncel marked this conversation as resolved.
Outdated

datasource = ForestAdminRpcAgent::Facades::Container.datasource
collection = get_collection_safe(datasource, args[:params]['collection_name'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize
end

def handle_request(args)
return {} unless args[:params]['collection_name']
return [] unless args[:params]['collection_name']

datasource = ForestAdminRpcAgent::Facades::Container.datasource
collection = get_collection_safe(datasource, args[:params]['collection_name'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ module Routes
context 'when collection_name is missing' do
let(:params) { {} }

it 'returns an empty hash' do
it 'returns an empty array' do
response = route.handle_request(args)
expect(response).to eq({})
expect(response).to eq([])
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ module Routes
end

context 'when collection_name is missing' do
it 'returns an empty hash' do
it 'returns an empty array' do
result = route.handle_request(params: {})
expect(result).to eq({})
expect(result).to eq([])
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ module Routes
end

context 'when collection_name is missing' do
it 'returns an empty hash' do
it 'returns an empty array' do
result = route.handle_request(params: {})
expect(result).to eq({})
expect(result).to eq([])
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ module Routes
end

context 'when collection_name is missing' do
it 'returns an empty hash' do
it 'returns an empty array' do
result = route.handle_request(params: {})
expect(result).to eq({})
expect(result).to eq([])
end
end
end
Expand Down
Loading