mirror of
https://github.com/inspec/inspec
synced 2024-11-27 07:00:39 +00:00
support package for windows
This commit is contained in:
parent
e51b18bd80
commit
78fea3d3a2
1 changed files with 27 additions and 1 deletions
|
@ -25,13 +25,15 @@ class Package < Vulcano.resource(1)
|
|||
@pkgman = Pacman.new(vulcano)
|
||||
when 'darwin'
|
||||
@pkgman = Brew.new(vulcano)
|
||||
when 'windows'
|
||||
@pkgman = WindowsPkg.new(vulcano)
|
||||
else
|
||||
return skip_resource 'The `package` resource is not supported on your OS yet.'
|
||||
end
|
||||
end
|
||||
|
||||
# returns true if the package is installed
|
||||
def installed?(_provider, _version)
|
||||
def installed?(_provider=nil, _version=nil)
|
||||
!info.nil?
|
||||
end
|
||||
|
||||
|
@ -134,3 +136,27 @@ class Pacman < PkgManagement
|
|||
}
|
||||
end
|
||||
end
|
||||
|
||||
# Determines the installed packages on Windows
|
||||
# Currently we use 'Get-WmiObject -Class Win32_Product' as a detection method
|
||||
# TODO: evaluate if alternative methods as proposed by Microsoft are still valid:
|
||||
# @see: http://blogs.technet.com/b/heyscriptingguy/archive/2013/11/15/use-powershell-to-find-installed-software.aspx
|
||||
class WindowsPkg < PkgManagement
|
||||
def info(package_name)
|
||||
# Find the package
|
||||
cmd = @vulcano.run_command("Get-WmiObject -Class Win32_Product | Where-Object {$_.Name -eq '#{package_name}'} | Select-Object -Property Name,Version,Vendor,PackageCode,Caption,Description | ConvertTo-Json")
|
||||
|
||||
begin
|
||||
package = JSON.parse(cmd.stdout)
|
||||
rescue JSON::ParserError => _e
|
||||
return nil
|
||||
end
|
||||
|
||||
{
|
||||
name: package['Name'],
|
||||
installed: true,
|
||||
version: package['Version'],
|
||||
type: 'windows',
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue