Class: Inspec::Resources::Rpm

Inherits:
PkgManagement show all
Defined in:
lib/inspec/resources/package.rb

Overview

RHEL family

Instance Attribute Summary

Attributes inherited from PkgManagement

#inspec

Instance Method Summary collapse

Constructor Details

#initialize(inspec, opts) ⇒ Rpm

Returns a new instance of Rpm.



179
180
181
182
183
# File 'lib/inspec/resources/package.rb', line 179

def initialize(inspec, opts)
  super(inspec)

  @dbpath = opts.fetch(:rpm_dbpath, nil)
end

Instance Method Details

#info(package_name) ⇒ Object



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/inspec/resources/package.rb', line 195

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",
    only_version_no: "#{v}",
  }
end

#latest_version(package_name) ⇒ Object



228
229
230
231
# File 'lib/inspec/resources/package.rb', line 228

def latest_version(package_name)
  cmd_string = "yum list #{package_name}"
  fetch_latest_version(cmd_string)
end

#missing_requirementsObject



185
186
187
188
189
190
191
192
193
# File 'lib/inspec/resources/package.rb', line 185

def missing_requirements
  missing_requirements = []

  unless @dbpath.nil? || inspec.directory(@dbpath).directory?
    missing_requirements << "RPMDB #{@dbpath} does not exist"
  end

  missing_requirements
end