From 23fc4db954c22bce2c6cc8996d5fafb175e2b747 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Thu, 17 Feb 2011 14:59:59 -0800 Subject: (#5132) Provide a query REST interface for inventory This REST interface returns a list of nodes that match a fact query. Fact queries can use (in)equality testing as a string comparison, and >, <, >=, <= numerical comparisons. Multiple tests can be done as AND comparisons, not OR. The fact queries need to be prefixed by facts, and the comparisons other than equality are specified with a .comparison_type after the fact name. This will be better explained in the REST documentation on the website. Searches that don't match anything now return empty array instead of a 404 error. Conflicts: spec/spec_helper.rb --- lib/puppet/network/http/api/v1.rb | 3 +-- lib/puppet/network/http/handler.rb | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'lib/puppet/network') diff --git a/lib/puppet/network/http/api/v1.rb b/lib/puppet/network/http/api/v1.rb index 8aa1f0ee1..0a04a465f 100644 --- a/lib/puppet/network/http/api/v1.rb +++ b/lib/puppet/network/http/api/v1.rb @@ -60,9 +60,8 @@ module Puppet::Network::HTTP::API::V1 # fix to not need this, and our goal is to move away from the complication # that leads to the fix being too long. return :singular if indirection == "facts" - - # "status" really is singular return :singular if indirection == "status" + return :plural if indirection == "inventory" result = (indirection =~ /s$/) ? :plural : :singular diff --git a/lib/puppet/network/http/handler.rb b/lib/puppet/network/http/handler.rb index 9e9356b2f..e192613ad 100644 --- a/lib/puppet/network/http/handler.rb +++ b/lib/puppet/network/http/handler.rb @@ -131,7 +131,7 @@ module Puppet::Network::HTTP::Handler def do_search(indirection_request, request, response) result = indirection_request.model.search(indirection_request.key, indirection_request.to_hash) - if result.nil? or (result.is_a?(Array) and result.empty?) + if result.nil? return do_exception(response, "Could not find instances in #{indirection_request.indirection_name} with '#{indirection_request.key}'", 404) end -- cgit From a7cebf80abc9e8b1b570ce7fd2e7b86cf1dd15b3 Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Thu, 17 Feb 2011 18:18:44 -0800 Subject: (#6337) Fix Ruby warning on 1.8.6 about "future compatibility" Ruby 1.8.6 (but not later versions) warn about requiring parenthesis on some function calls; having one of those in our network rights checking means that we emit ... quite a few of these, and annoy anything that tracks our logs. By using the more standard form of raise we can avoid the warning entirely, and keep consistent code style across the file. Reviewed-By: Paul Berry --- lib/puppet/network/rights.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet/network') diff --git a/lib/puppet/network/rights.rb b/lib/puppet/network/rights.rb index 00ee04f8d..b1daef67c 100755 --- a/lib/puppet/network/rights.rb +++ b/lib/puppet/network/rights.rb @@ -88,7 +88,7 @@ class Rights else # there were no rights allowing/denying name # if name is not a path, let's throw - raise ArgumentError.new "Unknown namespace right '#{name}'" + raise ArgumentError, "Unknown namespace right '#{name}'" end error end -- cgit From d1f1858ea52d3089fd2088994e80d6f49d7e0347 Mon Sep 17 00:00:00 2001 From: Max Martin Date: Fri, 18 Feb 2011 15:19:46 -0800 Subject: (#6376) Add support and testing for _search GET requests Added support for adding "_search" to the end of any indirection to 'pluralize' it, and added tests to check this functionality and to test hidden side effect of plurality method unpluralizing indirections. Paired-With:Paul Berry --- lib/puppet/network/http/api/v1.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/puppet/network') diff --git a/lib/puppet/network/http/api/v1.rb b/lib/puppet/network/http/api/v1.rb index 0a04a465f..9e51aae36 100644 --- a/lib/puppet/network/http/api/v1.rb +++ b/lib/puppet/network/http/api/v1.rb @@ -63,9 +63,9 @@ module Puppet::Network::HTTP::API::V1 return :singular if indirection == "status" return :plural if indirection == "inventory" - result = (indirection =~ /s$/) ? :plural : :singular + result = (indirection =~ /s$|_search$/) ? :plural : :singular - indirection.sub!(/s$/, '') if result + indirection.sub!(/s$|_search$|es$/, '') result end -- cgit From 0e9858f19d9d2e021a9d0aa43b69c6ddee229352 Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Tue, 22 Feb 2011 14:18:57 -0800 Subject: (#6407) Fix spec test hang with Mocha >= 0.9.11 in zlib testing We had a combination of bad logic, and bad testing, and a nasty behaviour of Mocha <= 0.9.10 that would result in a false pass for one of our tests. This not only falsely passed, but hid an infinite loop retrying decompression on an invalid data stream; it could be triggered by anything that sent an HTTP request with an invalid compressed body, resulting in a livelock. Paired-with: Jesse Wolfe Signed-off-by: Daniel Pittman --- lib/puppet/network/http/compression.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib/puppet/network') diff --git a/lib/puppet/network/http/compression.rb b/lib/puppet/network/http/compression.rb index d9b56f184..c8d001169 100644 --- a/lib/puppet/network/http/compression.rb +++ b/lib/puppet/network/http/compression.rb @@ -75,7 +75,10 @@ module Puppet::Network::HTTP::Compression # in this case, we try with a verbatim (no header) # deflater. @uncompressor = Zlib::Inflate.new - retry if @first + if @first then + @first = false + retry + end raise end -- cgit From 02626335b5e7fdbecf46639e4a4efe8e18ead982 Mon Sep 17 00:00:00 2001 From: nfagerlund Date: Mon, 14 Mar 2011 13:19:17 -0700 Subject: (#6707) Fix typo in rest_authconfig.rb "Where" -> "were." Capitalize "ACL." --- lib/puppet/network/rest_authconfig.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet/network') diff --git a/lib/puppet/network/rest_authconfig.rb b/lib/puppet/network/rest_authconfig.rb index 7a6147a82..e6067612a 100644 --- a/lib/puppet/network/rest_authconfig.rb +++ b/lib/puppet/network/rest_authconfig.rb @@ -61,7 +61,7 @@ module Puppet def insert_default_acl DEFAULT_ACL.each do |acl| unless rights[acl[:acl]] - Puppet.info "Inserting default '#{acl[:acl]}'(#{acl[:authenticated] ? "auth" : "non-auth"}) acl because #{( !exists? ? "#{Puppet[:rest_authconfig]} doesn't exist" : "none where found in '#{@file}'")}" + Puppet.info "Inserting default '#{acl[:acl]}'(#{acl[:authenticated] ? "auth" : "non-auth"}) ACL because #{( !exists? ? "#{Puppet[:rest_authconfig]} doesn't exist" : "none were found in '#{@file}'")}" mk_acl(acl) end end -- cgit