mirror of
https://github.com/inspec/inspec
synced 2024-11-23 21:23:29 +00:00
4965bfd36d
Dont return nil als a falsy result. Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
51 lines
1 KiB
Ruby
51 lines
1 KiB
Ruby
# encoding: utf-8
|
|
|
|
# This resource talks with OneGet (https://github.com/OneGet/oneget)
|
|
# Its part of Windows Management Framework 5.0 and part of Windows 10
|
|
#
|
|
# Usage:
|
|
# describe oneget('zoomit') do
|
|
# it { should be_installed }
|
|
# end
|
|
class OneGetPackage < Vulcano.resource(1)
|
|
name 'oneget'
|
|
|
|
def initialize(package_name)
|
|
@package_name = package_name
|
|
end
|
|
|
|
def info
|
|
return @info unless @info.nil?
|
|
|
|
@info = {}
|
|
@info[:type] = 'oneget'
|
|
|
|
cmd = vulcano.run_command("Get-Package -Name '#{@package_name}' | ConvertTo-Json")
|
|
# cannot rely on exit code for now, successful command returns exit code 1
|
|
# return nil if cmd.exit_status != 0
|
|
# try to parse json
|
|
|
|
begin
|
|
pkgs = JSON.parse(cmd.stdout)
|
|
rescue JSON::ParserError => _e
|
|
return @info
|
|
end
|
|
|
|
@info[:name] = pkgs['Name']
|
|
@info[:version] = pkgs['Version']
|
|
@info[:installed] = true
|
|
@info
|
|
end
|
|
|
|
def installed?
|
|
info[:installed] == true
|
|
end
|
|
|
|
def version
|
|
info[:version]
|
|
end
|
|
|
|
def to_s
|
|
"oneget package #{@package_name}"
|
|
end
|
|
end
|