inspec/lib/resources/npm.rb
Miah Johnson 7b23fa479c Add correct supports platform to resources. (#2674)
* Add correct `supports platform` to resources.

Signed-off-by: Miah Johnson <miah@chia-pet.org>

* Remove 'os_family' and update platforms to specify what they did.

Signed-off-by: Miah Johnson <miah@chia-pet.org>

* Add esx and cisco to generic resources.

Signed-off-by: Jared Quick <jquick@chef.io>
2018-02-19 15:26:49 +01:00

48 lines
1.1 KiB
Ruby

# encoding: utf-8
module Inspec::Resources
class NpmPackage < Inspec.resource(1)
name 'npm'
supports platform: 'unix'
supports platform: 'windows'
desc 'Use the npm InSpec audit resource to test if a global npm package is installed. npm is the the package manager for Nodejs packages, such as bower and StatsD.'
example "
describe npm('bower') do
it { should be_installed }
end
"
def initialize(package_name)
@package_name = package_name
@cache = nil
end
def info
return @info if defined?(@info)
cmd = inspec.command("npm ls -g --json #{@package_name}")
@info = {
name: @package_name,
type: 'npm',
installed: cmd.exit_status == 0,
}
return @info unless @info[:installed]
pkgs = JSON.parse(cmd.stdout)
@info[:version] = pkgs['dependencies'][@package_name]['version']
@info
end
def installed?
info[:installed] == true
end
def version
info[:version]
end
def to_s
"Npm Package #{@package_name}"
end
end
end