summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@may.lt>2016-12-05 10:26:50 +0000
committerGitHub <noreply@github.com>2016-12-05 10:26:50 +0000
commit3b969c992fcb7b4be58d165b700ae6994ed7d116 (patch)
tree487d40907b5e0d953a1cc2b1270682d4dde7144e
parent1c172661f6d6ddf9bf37cda4f7b9651adbc2eb53 (diff)
parent78a11d032d641fda1a4702abc3535b80bb2f0bda (diff)
downloadchef-zero-3b969c992fcb7b4be58d165b700ae6994ed7d116.tar.gz
Merge pull request #247 from chef/nls/SPOOL-436/toomanyrows
Handle the start and rows parameters correctly
-rw-r--r--Gemfile9
-rw-r--r--lib/chef_zero/endpoints/search_endpoint.rb12
2 files changed, 15 insertions, 6 deletions
diff --git a/Gemfile b/Gemfile
index 9e2d501..45d999a 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,9 +1,9 @@
source "https://rubygems.org"
gemspec
-# gem 'rest-client', :github => 'chef/rest-client'
+# gem 'rest-client', :git => 'https://github.com/chef/rest-client.git'
-gem "oc-chef-pedant", :github => "chef/chef-server"
+gem "oc-chef-pedant", :git => "https://github.com/chef/chef-server.git"
group :changelog do
gem "github_changelog_generator"
@@ -13,10 +13,7 @@ group :development, :test do
gem "chefstyle", "= 0.3.1"
end
-# bundler resolve failure on "rspec_junit_formatter"
-# gem 'chef-pedant', :github => 'opscode/chef-pedant', :ref => "server-cli-option"
-
-gem "chef", github: "chef/chef" # until chef 12.15 is released
+gem "chef"
if ENV["GEMFILE_MOD"]
puts "GEMFILE_MOD: #{ENV['GEMFILE_MOD']}"
diff --git a/lib/chef_zero/endpoints/search_endpoint.rb b/lib/chef_zero/endpoints/search_endpoint.rb
index 1e20025..16da462 100644
--- a/lib/chef_zero/endpoints/search_endpoint.rb
+++ b/lib/chef_zero/endpoints/search_endpoint.rb
@@ -12,7 +12,19 @@ module ChefZero
def get(request)
orgname = request.rest_path[1]
results = search(request, orgname)
+
results["rows"] = results["rows"].map { |name, uri, value, search_value| value }
+
+ # Slice the array based on the value of the "rows" query parameter. If
+ # this is a positive integer, we'll get the number of rows asked for.
+ # If it's nil, we'll get -1, which gives us all of the elements.
+ #
+ # Do the same for "start", which will start at 0 if that value is not
+ # given.
+ results["rows"] =
+ results["rows"][request.query_params["start"].to_i..
+ (request.query_params["rows"].to_i - 1)]
+
json_response(200, results)
rescue ChefZero::Solr::ParseError
bad_search_request(request)