Class: Chef::ConfigFetcher
- Inherits:
-
Object
- Object
- Chef::ConfigFetcher
- Defined in:
- lib/chef/config_fetcher.rb
Instance Attribute Summary collapse
-
#config_location ⇒ Object
readonly
Returns the value of attribute config_location.
Instance Method Summary collapse
- #config_missing? ⇒ Boolean
- #expanded_path ⇒ Object
- #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
54 55 56 57 58 59 60 61 62 |
# File 'lib/chef/config_fetcher.rb', line 54 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 true end |
#expanded_path ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/chef/config_fetcher.rb', line 15 def if config_location.nil? || remote_config? config_location else File.(config_location) end end |
#fetch_json ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/chef/config_fetcher.rb', line 23 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.) end end |
#fetch_remote_config ⇒ Object
40 41 42 43 44 |
# File 'lib/chef/config_fetcher.rb', line 40 def fetch_remote_config http.get("") rescue SocketError, SystemCallError, Net::HTTPClientException => error Chef::Application.fatal!("Cannot fetch config '#{config_location}': '#{error.class}: #{error.}") end |
#http ⇒ Object
64 65 66 |
# File 'lib/chef/config_fetcher.rb', line 64 def http Chef::HTTP::Simple.new(config_location) end |
#read_config ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/chef/config_fetcher.rb', line 32 def read_config if remote_config? fetch_remote_config else read_local_config end end |
#read_local_config ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/chef/config_fetcher.rb', line 46 def read_local_config ::File.read(config_location) rescue Errno::ENOENT Chef::Application.fatal!("Cannot load configuration from #{config_location}") rescue Errno::EACCES Chef::Application.fatal!("Permissions are incorrect on #{config_location}. Please chmod a+r #{config_location}") end |
#remote_config? ⇒ Boolean
68 69 70 |
# File 'lib/chef/config_fetcher.rb', line 68 def remote_config? !!(config_location =~ %r{^(http|https)://}) end |