summaryrefslogtreecommitdiff
path: root/chef/bin
diff options
context:
space:
mode:
authorDavid Balatero <dbalatero@evri.com>2009-04-29 12:59:43 -0700
committerDavid Balatero <dbalatero@evri.com>2009-04-29 12:59:43 -0700
commitced222d6829731b3dbc1fa9b93be7c92571948b2 (patch)
tree909b18c8f0885a887b2480666d8b5d016c94e09c /chef/bin
parentee315cbb4d0ff3a46304746a2a5d107d8c11996b (diff)
downloadchef-ced222d6829731b3dbc1fa9b93be7c92571948b2.tar.gz
Updated the chef-client / chef-solo binaries to allow JSON configs to be
passed in via URL, as per ticket CHEF-249. Also improved error handling for loading the JSON config in both cases.
Diffstat (limited to 'chef/bin')
-rwxr-xr-xchef/bin/chef-client29
-rwxr-xr-xchef/bin/chef-solo30
2 files changed, 51 insertions, 8 deletions
diff --git a/chef/bin/chef-client b/chef/bin/chef-client
index f960794c5d..f5c11c74a4 100755
--- a/chef/bin/chef-client
+++ b/chef/bin/chef-client
@@ -38,7 +38,7 @@ opts = OptionParser.new do |opts|
:group=> { :short=>"-g GROUP", :long=>"--group GROUP", :description=>"Group to change gid to before daemonizing", :proc=>nil },
:daemonize=> { :short=>"-d", :long=>"--daemonize", :description=>"Daemonize the process", :proc=> lambda { |p| true} },
:interval=> { :short=>"-i SECONDS", :long=>"--interval SECONDS", :description=>"Run chef-client periodically, in seconds", :proc=>nil },
- :json_attribs=>{ :short=>"-j JSON_ATTRIBS", :long=>"--json-attributes JSON_ATTRIBS", :description=>"Load attributes from a JSON file", :proc=>nil },
+ :json_attribs=>{ :short=>"-j JSON_ATTRIBS", :long=>"--json-attributes JSON_ATTRIBS", :description=>"Load attributes from a JSON file/URL", :proc=>nil },
:node_name=> { :short=>"-N NODE_NAME", :long=>"--node-name NODE_NAME", :description=>"The node name for this client", :proc=>nil },
:splay=> { :short=>"-s SECONDS", :long=>"--splay SECONDS", :description=>"The splay time for running at intervals, in seconds", :proc=>nil },
:log_level=> { :short=>"-l LEVEL", :long=>"--loglevel LEVEL", :description=>"Set the log level (debug, info, warn, error, fatal)", :proc=>lambda { |p| p.to_sym} },
@@ -71,10 +71,29 @@ unless File.exists?(config[:config_file]) and File.readable?(config[:config_file
end
if config[:json_attribs]
- if File.exists?(config[:json_attribs]) and File.readable?(config[:json_attribs])
- config[:json_attribs] = JSON.parse(IO.read(config[:json_attribs]))
- else
- Chef.fatal!("I cannot find or read #{config[:json_attribs]}", 2)
+ require 'net/http'
+ require 'open-uri'
+
+ json_io = nil
+ begin
+ json_io = open(config[:json_attribs])
+ rescue SocketError => error
+ Chef.fatal!("I cannot connect to #{config[:json_attribs]}", 2)
+ rescue Errno::ENOENT => error
+ Chef.fatal!("I cannot find #{config[:json_attribs]}", 2)
+ rescue Errno::EACCES => error
+ Chef.fatal!("Permissions are incorrect on #{config[:json_attribs]}. Please chmod a+r #{config[:json_attribs]}", 2)
+ rescue Exception => error
+ Chef.fatal!("Got an unexpected error reading #{config[:json_attribs]}: #{error.message}", 2)
+ end
+
+ json_contents = json_io.read
+
+ begin
+ config[:json_attribs] = JSON.parse(json_contents)
+ rescue JSON::ParserError => error
+ Chef.fatal!("Could not parse the provided JSON file (#{config[:json_attribs]})!: " + error.message, 2)
+ exit 2
end
end
diff --git a/chef/bin/chef-solo b/chef/bin/chef-solo
index ecc2c57f8a..60fae7a52b 100755
--- a/chef/bin/chef-solo
+++ b/chef/bin/chef-solo
@@ -41,7 +41,7 @@ opts = OptionParser.new do |opts|
opts.on("-r RECIPEURL", "--recipe-url RECIPEURL", "Pull down a remote gzipped tarball of recipes and untar it into the proer place.") do |r|
config[:recipes] = r
end
- opts.on("-j JSON_ATTRIBS", "--json-attributes JSON_ATTRIBS", "Load attributes from a JSON file") do |j|
+ opts.on("-j JSON_ATTRIBS", "--json-attributes JSON_ATTRIBS", "Load attributes from a JSON file (path or URL)") do |j|
config[:json_attribs] = j
end
opts.on_tail("-l LEVEL", "--loglevel LEVEL", "Set the log level (debug, info, warn, error, fatal)") do |l|
@@ -61,11 +61,35 @@ unless File.exists?(config[:config_file]) && File.readable?(config[:config_file]
end
if config[:json_attribs]
- unless File.exists?(config[:json_attribs])
+ require 'net/http'
+ require 'open-uri'
+
+ json_io = nil
+ begin
+ json_io = open(config[:json_attribs])
+ rescue SocketError => error
+ puts "I cannot connect to #{config[:json_attribs]}"
+ exit 2
+ rescue Errno::ENOENT => error
puts "I cannot find #{config[:json_attribs]}"
exit 2
+ rescue Errno::EACCES => error
+ puts "Permissions are incorrect on #{config[:json_attribs]}. Please chmod a+r #{config[:json_attribs]}"
+ exit 2
+ rescue Exception => error
+ puts "Got an unexpected error reading #{config[:json_attribs]}: #{error.message}"
+ exit 2
+ end
+
+ json_contents = json_io.read
+
+ begin
+ config[:json_attribs] = JSON.parse(json_contents)
+ rescue JSON::ParserError => error
+ puts "Could not parse the provided JSON file (#{config[:json_attribs]})!"
+ puts error.message
+ exit 2
end
- config[:json_attribs] = JSON.parse(IO.read(config[:json_attribs]))
end
# Load our config file