199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
|
# File 'lib/inspec/resources/package.rb', line 199
def info(package_name)
brew_path = inspec.command("brew").exist? ? "brew" : "/usr/local/bin/brew"
cmd = inspec.command("#{brew_path} info --json=v1 #{package_name}")
return {} if cmd.exit_status.to_i != 0
pkg = JSON.parse(cmd.stdout)[0]
return {} unless pkg.dig("installed", 0, "version")
{
name: pkg["name"],
installed: true,
version: pkg["installed"][0]["version"],
type: "brew",
}
rescue JSON::ParserError => e
raise Inspec::Exceptions::ResourceFailed,
"Failed to parse JSON from `brew` command. " \
"Error: #{e}"
end
|