Class: Chef::ConfigFetcher
Instance Attribute Summary collapse
-
#config_location ⇒ Object
readonly
Returns the value of attribute config_location.
Instance Method Summary collapse
- #config_missing? ⇒ Boolean
- #fetch_json ⇒ Object
- #fetch_remote_config ⇒ Object
- #http ⇒ Object
-
#initialize(config_location) ⇒ ConfigFetcher
constructor
A new instance of ConfigFetcher.
- #read_config ⇒ Object
- #read_local_config ⇒ Object
- #remote_config? ⇒ Boolean
Constructor Details
#initialize(config_location) ⇒ ConfigFetcher
Returns a new instance of ConfigFetcher.
11 12 13 |
# File 'lib/chef/config_fetcher.rb', line 11 def initialize(config_location) @config_location = config_location end |
Instance Attribute Details
#config_location ⇒ Object (readonly)
Returns the value of attribute config_location.
9 10 11 |
# File 'lib/chef/config_fetcher.rb', line 9 def config_location @config_location end |
Instance Method Details
#config_missing? ⇒ Boolean
46 47 48 49 50 51 52 53 54 |
# File 'lib/chef/config_fetcher.rb', line 46 def config_missing? return false if remote_config? # Check if the config file exists Pathname.new(config_location).realpath.to_s false rescue Errno::ENOENT return true end |
#fetch_json ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/chef/config_fetcher.rb', line 15 def fetch_json config_data = read_config begin Chef::JSONCompat.from_json(config_data) rescue Chef::Exceptions::JSON::ParseError => error Chef::Application.fatal!("Could not parse the provided JSON file (#{config_location}): " + error., 2) end end |
#fetch_remote_config ⇒ Object
32 33 34 35 36 |
# File 'lib/chef/config_fetcher.rb', line 32 def fetch_remote_config http.get("") rescue SocketError, SystemCallError, Net::HTTPServerException => error Chef::Application.fatal!("Cannot fetch config '#{config_location}': '#{error.class}: #{error.}", 2) end |
#http ⇒ Object
56 57 58 |
# File 'lib/chef/config_fetcher.rb', line 56 def http Chef::HTTP::Simple.new(config_location) end |
#read_config ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/chef/config_fetcher.rb', line 24 def read_config if remote_config? fetch_remote_config else read_local_config end end |
#read_local_config ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/chef/config_fetcher.rb', line 38 def read_local_config ::File.read(config_location) rescue Errno::ENOENT => error Chef::Application.fatal!("Cannot load configuration from #{config_location}", 2) rescue Errno::EACCES => error Chef::Application.fatal!("Permissions are incorrect on #{config_location}. Please chmod a+r #{config_location}", 2) end |
#remote_config? ⇒ Boolean
60 61 62 |
# File 'lib/chef/config_fetcher.rb', line 60 def remote_config? !!(config_location =~ %r{^(http|https)://}) end |