Method: Shell.parse_json

Defined in:
lib/chef/shell.rb

.parse_jsonObject



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/chef/shell.rb', line 153

def self.parse_json
  # HACK: copied verbatim from chef/application/client, because it's not
  # reusable as written there :(
  if Chef::Config[:json_attribs]
    begin
      json_io = open(Chef::Config[:json_attribs])
    rescue SocketError => error
      fatal!("I cannot connect to #{Chef::Config[:json_attribs]}", 2)
    rescue Errno::ENOENT => error
      fatal!("I cannot find #{Chef::Config[:json_attribs]}", 2)
    rescue Errno::EACCES => error
      fatal!("Permissions are incorrect on #{Chef::Config[:json_attribs]}. Please chmod a+r #{Chef::Config[:json_attribs]}", 2)
    rescue Exception => error
      fatal!("Got an unexpected error reading #{Chef::Config[:json_attribs]}: #{error.message}", 2)
    end

    begin
      @json_attribs = Chef::JSONCompat.from_json(json_io.read)
    rescue JSON::ParserError => error
      fatal!("Could not parse the provided JSON file (#{Chef::Config[:json_attribs]})!: " + error.message, 2)
    end
  end
end