Class: Inspec::Resources::Rpm
- Inherits:
-
PkgManagement
- Object
- PkgManagement
- Inspec::Resources::Rpm
- Defined in:
- lib/resources/package.rb
Overview
RHEL family
Instance Attribute Summary
Attributes inherited from PkgManagement
Instance Method Summary collapse
- #info(package_name) ⇒ Object
-
#initialize(inspec, opts) ⇒ Rpm
constructor
A new instance of Rpm.
- #missing_requirements ⇒ Object
Constructor Details
#initialize(inspec, opts) ⇒ Rpm
Returns a new instance of Rpm.
134 135 136 137 138 |
# File 'lib/resources/package.rb', line 134 def initialize(inspec, opts) super(inspec) @dbpath = opts.fetch(:rpm_dbpath, nil) end |
Instance Method Details
#info(package_name) ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/resources/package.rb', line 150 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 ⇒ Object
140 141 142 143 144 145 146 147 148 |
# File 'lib/resources/package.rb', line 140 def missing_requirements missing_requirements = [] unless @dbpath.nil? || inspec.directory(@dbpath).directory? missing_requirements << "RPMDB #{@dbpath} does not exist" end missing_requirements end |