summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAdam Leff <adam@leff.co>2016-07-05 15:29:22 -0400
committerGitHub <noreply@github.com>2016-07-05 15:29:22 -0400
commit0d584cae915a9fd84ba2f212739f1621abb10f19 (patch)
tree7ab143605416ca310109aee7de7b2f1628eb96f1 /lib
parent599b71bd469f25bd7fd8e58da3ae968e7a0b47df (diff)
parent9cafaa5c68ac987cb7498eef0a413cb8b823b650 (diff)
downloadchef-0d584cae915a9fd84ba2f212739f1621abb10f19.tar.gz
Merge pull request #5076 from chef/adamleff/ipo-277-uri-validation
Data Collector server URL validation, and disable on host down
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/data_collector.rb19
-rw-r--r--lib/chef/data_collector/resource_report.rb1
2 files changed, 19 insertions, 1 deletions
diff --git a/lib/chef/data_collector.rb b/lib/chef/data_collector.rb
index d307fff2ba..dbb0b3771a 100644
--- a/lib/chef/data_collector.rb
+++ b/lib/chef/data_collector.rb
@@ -57,6 +57,8 @@ class Chef
:current_resource_report, :enabled
def initialize
+ validate_data_collector_server_url!
+
@all_resource_reports = []
@current_resource_loaded = nil
@error_descriptions = {}
@@ -236,7 +238,8 @@ class Chef
yield
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET,
Errno::ECONNREFUSED, EOFError, Net::HTTPBadResponse,
- Net::HTTPHeaderSyntaxError, Net::ProtocolError, OpenSSL::SSL::SSLError => e
+ Net::HTTPHeaderSyntaxError, Net::ProtocolError, OpenSSL::SSL::SSLError,
+ Errno::EHOSTDOWN => e
disable_data_collector_reporter
code = if e.respond_to?(:response) && e.response.code
e.response.code.to_s
@@ -376,6 +379,20 @@ class Chef
def nested_resource?(new_resource)
@current_resource_report && @current_resource_report.new_resource != new_resource
end
+
+ def validate_data_collector_server_url!
+ raise Chef::Exceptions::ConfigurationError,
+ "Chef::Config[:data_collector][:server_url] is empty. Please supply a valid URL." if data_collector_server_url.empty?
+
+ begin
+ uri = URI(data_collector_server_url)
+ rescue URI::InvalidURIError
+ raise Chef::Exceptions::ConfigurationError, "Chef::Config[:data_collector][:server_url] (#{data_collector_server_url}) is not a valid URI."
+ end
+
+ raise Chef::Exceptions::ConfigurationError,
+ "Chef::Config[:data_collector][:server_url] (#{data_collector_server_url}) is a URI with no host. Please supply a valid URL." if uri.host.nil?
+ end
end
end
end
diff --git a/lib/chef/data_collector/resource_report.rb b/lib/chef/data_collector/resource_report.rb
index e031d4bcb6..dcaf9c8e44 100644
--- a/lib/chef/data_collector/resource_report.rb
+++ b/lib/chef/data_collector/resource_report.rb
@@ -80,6 +80,7 @@ class Chef
if new_resource.cookbook_name
hash["cookbook_name"] = new_resource.cookbook_name
hash["cookbook_version"] = new_resource.cookbook_version.version
+ hash["recipe_name"] = new_resource.recipe_name
end
hash["conditional"] = conditional.to_text if status == "skipped"