class Inspec::Resources::Rpm
RHEL family
Public Class Methods
new(inspec, opts)
click to toggle source
Calls superclass method
Inspec::Resources::PkgManagement::new
# File lib/inspec/resources/package.rb, line 139 def initialize(inspec, opts) super(inspec) @dbpath = opts.fetch(:rpm_dbpath, nil) end
Public Instance Methods
info(package_name)
click to toggle source
# File lib/inspec/resources/package.rb, line 155 def info(package_name) rpm_cmd = rpm_command(package_name) cmd = inspec.command(rpm_cmd) # CentOS does not return an error code if the package is not installed, # therefore we need to check for emptyness return {} if cmd.exit_status.to_i != 0 || cmd.stdout.chomp.empty? params = SimpleConfig.new( cmd.stdout.chomp, assignment_regex: /^\s*([^:]*?)\s*:\s*(.*?)\s*$/, multiple_values: false ).params # On some (all?) systems, the linebreak before the vendor line is missing if params["Version"] =~ /\s*Vendor:/ v = params["Version"].split(" ")[0] else v = params["Version"] end # On some (all?) systems, the linebreak before the build line is missing if params["Release"] =~ /\s*Build Date:/ r = params["Release"].split(" ")[0] else r = params["Release"] end { name: params["Name"], installed: true, version: "#{v}-#{r}", type: "rpm", } end
missing_requirements()
click to toggle source
# File lib/inspec/resources/package.rb, line 145 def missing_requirements missing_requirements = [] unless @dbpath.nil? || inspec.directory(@dbpath).directory? missing_requirements << "RPMDB #{@dbpath} does not exist" end missing_requirements end
Private Instance Methods
rpm_command(package_name)
click to toggle source
# File lib/inspec/resources/package.rb, line 189 def rpm_command(package_name) cmd = "" cmd += "rpm -qi" cmd += " --dbpath #{@dbpath}" if @dbpath cmd += " " + package_name cmd end