summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/exceptions.rb2
-rw-r--r--lib/chef/knife.rb2
-rw-r--r--lib/chef/server_api.rb18
3 files changed, 22 insertions, 0 deletions
diff --git a/lib/chef/exceptions.rb b/lib/chef/exceptions.rb
index 5b470f574e..a73062b676 100644
--- a/lib/chef/exceptions.rb
+++ b/lib/chef/exceptions.rb
@@ -521,5 +521,7 @@ This error is most often caused by network issues (proxies, etc) outside of chef
# exception specific to invalid usage of 'dsc_resource' resource
class DSCModuleNameMissing < ArgumentError; end
+
+ class NotAChefServerException < ArgumentError; end
end
end
diff --git a/lib/chef/knife.rb b/lib/chef/knife.rb
index aa30f2e2ed..ed54d141be 100644
--- a/lib/chef/knife.rb
+++ b/lib/chef/knife.rb
@@ -474,6 +474,8 @@ class Chef
when Chef::Exceptions::InvalidRedirect
ui.error "Invalid Redirect: #{e.message}"
ui.info "Change your server location in knife.rb to the server's FQDN to avoid unwanted redirections."
+ when Chef::Exceptions::NotAChefServerException
+ ui.error "#{Chef::Config[:chef_server_url]} is not a valid chef server"
else
ui.error "#{e.class.name}: #{e.message}"
end
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.