Sha256: 0b21dda2ad537301c6866a311eae7df89ab4428d3c39d9cdeb884ffba99121b8

Contents?: true

Size: 1.08 KB

Versions: 22

Compression:

Stored size: 1.08 KB

Contents

# 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

Version data entries

22 entries across 22 versions & 2 rubygems

Version Path
inspec-core-2.1.84 lib/resources/npm.rb
inspec-2.1.84 lib/resources/npm.rb
inspec-core-2.1.83 lib/resources/npm.rb
inspec-2.1.83 lib/resources/npm.rb
inspec-core-2.1.81 lib/resources/npm.rb
inspec-core-2.1.80 lib/resources/npm.rb
inspec-2.1.80 lib/resources/npm.rb
inspec-core-2.1.78 lib/resources/npm.rb
inspec-2.1.78 lib/resources/npm.rb
inspec-core-2.1.72 lib/resources/npm.rb
inspec-2.1.72 lib/resources/npm.rb
inspec-core-2.1.68 lib/resources/npm.rb
inspec-2.1.68 lib/resources/npm.rb
inspec-core-2.1.67 lib/resources/npm.rb
inspec-2.1.67 lib/resources/npm.rb
inspec-2.1.59 lib/resources/npm.rb
inspec-2.1.54 lib/resources/npm.rb
inspec-2.1.43 lib/resources/npm.rb
inspec-2.1.30 lib/resources/npm.rb
inspec-2.1.0 lib/resources/npm.rb