summaryrefslogtreecommitdiff
path: root/lib/chef/server_api.rb
diff options
context:
space:
mode:
authorJose Asuncion <jose.asuncion@gmail.com>2017-09-25 16:57:28 -0700
committerJose Asuncion <jose.asuncion@gmail.com>2017-09-25 16:57:32 -0700
commitbdf090c43e46a1aeec80c6b495c6858f9c2d6300 (patch)
tree07957702473690436a144dab862270b990e5095d /lib/chef/server_api.rb
parentb3eec2dc4c27bba5256b1ae42edb70cf422997ac (diff)
downloadchef-bdf090c43e46a1aeec80c6b495c6858f9c2d6300.tar.gz
move chef server heuristic to server_api
Signed-off-by: Jose Asuncion <jeunito@gmail.com>
Diffstat (limited to 'lib/chef/server_api.rb')
-rw-r--r--lib/chef/server_api.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/chef/server_api.rb b/lib/chef/server_api.rb
index 2bdc5d9fe8..3bf0df4880 100644
--- a/lib/chef/server_api.rb
+++ b/lib/chef/server_api.rb
@@ -25,6 +25,7 @@ require "chef/http/json_output"
require "chef/http/remote_request_id"
require "chef/http/validate_content_length"
require "chef/http/api_versions"
+require "ffi_yajl"
class Chef
class ServerAPI < Chef::HTTP
@@ -56,6 +57,23 @@ class Chef
alias :post_rest :post
alias :put_rest :put
+ def get(path, headers={})
+ begin
+ request(:GET, path, headers)
+ rescue Net::HTTPServerException => e
+ if e.response.kind_of?(Net::HTTPNotFound)
+ begin
+ FFI_Yajl::Parser.parse(e.response.body)
+ rescue FFI_Yajl::ParseError => e
+ raise Chef::Exceptions::NotAChefServerException
+ end
+ raise
+ else
+ raise
+ end
+ end
+ end
+
# Makes an HTTP request to +path+ with the given +method+, +headers+, and
# +data+ (if applicable). Does not apply any middleware, besides that
# needed for Authentication.