mirror of
https://github.com/inspec/inspec
synced 2024-11-30 16:39:20 +00:00
577688a3a0
Many of the resources are named as a top-level class with a fairly generic class name, such as "OS". This causes an issue specifically with kitchen-google which depends on a gem which depends on the "os" gem which itself defines an OS class with a different superclass. This prevents users from using TK, Google Compute, and Inspec without this fix. Some mocked commands had their digest changed as well due to the new indentation, specifically in the User and RegistryKey classes. I strongly recommend viewing this diff with `git diff --ignore-space-change` to see the *real* changes. :)
50 lines
1.1 KiB
Ruby
50 lines
1.1 KiB
Ruby
# encoding: utf-8
|
|
# author: Christoph Hartmann
|
|
# author: Dominik Richter
|
|
|
|
module Inspec::Resources
|
|
class GemPackage < Inspec.resource(1)
|
|
name 'gem'
|
|
desc 'Use the gem InSpec audit resource to test if a global gem package is installed.'
|
|
example "
|
|
describe gem('rubocop') do
|
|
it { should be_installed }
|
|
end
|
|
"
|
|
|
|
def initialize(package_name)
|
|
@package_name = package_name
|
|
end
|
|
|
|
def info
|
|
return @info if defined?(@info)
|
|
|
|
cmd = inspec.command("gem list --local -a -q \^#{@package_name}\$")
|
|
@info = {
|
|
installed: cmd.exit_status == 0,
|
|
type: 'gem',
|
|
}
|
|
return @info unless @info[:installed]
|
|
|
|
# extract package name and version
|
|
# parses data like winrm (1.3.4, 1.3.3)
|
|
params = /^\s*([^\(]*?)\s*\((.*?)\)\s*$/.match(cmd.stdout.chomp)
|
|
versions = params[2].split(',')
|
|
@info[:name] = params[1]
|
|
@info[:version] = versions[0]
|
|
@info
|
|
end
|
|
|
|
def installed?
|
|
info[:installed] == true
|
|
end
|
|
|
|
def version
|
|
info[:version]
|
|
end
|
|
|
|
def to_s
|
|
"gem package #{@package_name}"
|
|
end
|
|
end
|
|
end
|