mirror of
https://github.com/inspec/inspec
synced 2024-11-27 07:00:39 +00:00
wrap up core resource linting
Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
This commit is contained in:
parent
903b9642e4
commit
470c2ef920
16 changed files with 38 additions and 31 deletions
|
@ -45,7 +45,7 @@ class AuditDaemonConf < Vulcano.resource(1)
|
|||
# parse the file
|
||||
@params = SimpleConfig.new(
|
||||
@content,
|
||||
multiple_values: false
|
||||
multiple_values: false,
|
||||
).params
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,7 +18,7 @@ class AuditDaemonRules < Vulcano.resource(1)
|
|||
|
||||
@opts = {
|
||||
assignment_re: /^\s*([^:]*?)\s*:\s*(.*?)\s*$/,
|
||||
multiple_values: true
|
||||
multiple_values: true,
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -33,12 +33,13 @@ class AuditDaemonRules < Vulcano.resource(1)
|
|||
def status(name)
|
||||
@status_opts = {
|
||||
assignment_re: /^\s*([^:]*?)\s*:\s*(.*?)\s*$/,
|
||||
multiple_values: false
|
||||
multiple_values: false,
|
||||
}
|
||||
@status_content ||= vulcano.run_command('/sbin/auditctl -s').stdout.chomp
|
||||
@status_params = SimpleConfig.new(@status_content, @status_opts).params
|
||||
|
||||
status = @status_params['AUDIT_STATUS']
|
||||
if (status == nil) then return nil end
|
||||
return nil if status.nil?
|
||||
|
||||
items = Hash[status.scan(/([^=]+)=(\w*)\s*/)]
|
||||
items[name]
|
||||
|
|
|
@ -20,7 +20,7 @@ module Vulcano::Resources
|
|||
@params = SimpleConfig.new(
|
||||
@file.content,
|
||||
assignment_re: /^\s*([^:]*?)\s*:\s*(.*?)\s*$/,
|
||||
multiple_values: true
|
||||
multiple_values: true,
|
||||
).params if @file.exists?
|
||||
@loaded = true
|
||||
@content
|
||||
|
|
|
@ -22,7 +22,7 @@ module Vulcano::Resources
|
|||
end
|
||||
end
|
||||
|
||||
def contain(pattern, from, to)
|
||||
def contain(*_)
|
||||
fail ' not yet implemented '
|
||||
end
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ class GemPackage < Vulcano.resource(1)
|
|||
@cache = {
|
||||
name: params[1],
|
||||
version: versions[0],
|
||||
type: 'gem'
|
||||
type: 'gem',
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ class InetdConf < Vulcano.resource(1)
|
|||
@content,
|
||||
assignment_re: /^\s*(\S+?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s*$/,
|
||||
key_vals: 6,
|
||||
multiple_values: false
|
||||
multiple_values: false,
|
||||
).params
|
||||
@content
|
||||
end
|
||||
|
|
|
@ -45,7 +45,7 @@ class LimitsConf < Vulcano.resource(1)
|
|||
@content,
|
||||
assignment_re: /^\s*(\S+?)\s+(.*?)\s+(.*?)\s+(.*?)\s*$/,
|
||||
key_vals: 3,
|
||||
multiple_values: true
|
||||
multiple_values: true,
|
||||
).params
|
||||
@content
|
||||
end
|
||||
|
|
|
@ -50,7 +50,7 @@ class LoginDef < Vulcano.resource(1)
|
|||
@params = SimpleConfig.new(
|
||||
@content,
|
||||
assignment_re: /^\s*(\S+)\s+(\S*)\s*$/,
|
||||
multiple_values: false
|
||||
multiple_values: false,
|
||||
).params
|
||||
@content
|
||||
end
|
||||
|
|
|
@ -20,7 +20,7 @@ class NpmPackage < Vulcano.resource(1)
|
|||
@cache = {
|
||||
name: @package_name,
|
||||
version: pkgs['dependencies'][@package_name]['version'],
|
||||
type: 'npm'
|
||||
type: 'npm',
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ class NtpConf < Vulcano.resource(1)
|
|||
@params = SimpleConfig.new(
|
||||
@content,
|
||||
assignment_re: /^\s*(\S+)\s+(.*)\s*$/,
|
||||
multiple_values: true
|
||||
multiple_values: true,
|
||||
).params
|
||||
@content
|
||||
end
|
||||
|
|
|
@ -31,7 +31,7 @@ class Package < Vulcano.resource(1)
|
|||
end
|
||||
|
||||
# returns true if the package is installed
|
||||
def installed?(provider = nil, version = nil)
|
||||
def installed?(_provider, _version)
|
||||
!info.nil?
|
||||
end
|
||||
|
||||
|
|
|
@ -17,13 +17,11 @@ class PConfig < Vulcano.resource(1)
|
|||
def initialize(content = nil, useropts = {})
|
||||
default_options = {}
|
||||
@opts = default_options.merge(useropts)
|
||||
@content = content
|
||||
@files_contents = {}
|
||||
@params = nil
|
||||
|
||||
if @content != nil then
|
||||
read_content
|
||||
end
|
||||
@content = content
|
||||
read_content if @content.nil?
|
||||
end
|
||||
|
||||
def to_s
|
||||
|
|
|
@ -77,7 +77,7 @@ class Passwd < Vulcano.resource(1)
|
|||
'gid' => x.at(3),
|
||||
'desc' => x.at(4),
|
||||
'home' => x.at(5),
|
||||
'shell' => x.at(6)
|
||||
'shell' => x.at(6),
|
||||
}
|
||||
}
|
||||
end
|
||||
|
|
|
@ -13,13 +13,25 @@ class Processes < Vulcano.resource(1)
|
|||
grep = Regexp.new('^' + grep + '(\s|$)')
|
||||
end
|
||||
|
||||
all_cmds = ps_aux
|
||||
@list = all_cmds.find_all do |hm|
|
||||
hm[:command] =~ grep
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def ps_aux
|
||||
# get all running processes
|
||||
cmd = vulcano.run_command('ps aux')
|
||||
all = cmd.stdout.split("\n")[1..-1]
|
||||
all_cmds = all.map do |line|
|
||||
|
||||
lines = all.map do |line|
|
||||
# user 32296 0.0 0.0 42592 7972 pts/15 Ss+ Apr06 0:00 zsh
|
||||
line.match(/^([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+(.*)$/)
|
||||
end.compact.map do |m|
|
||||
end.compact
|
||||
|
||||
lines.map do |m|
|
||||
{
|
||||
user: m[1],
|
||||
pid: m[2],
|
||||
|
@ -31,12 +43,8 @@ class Processes < Vulcano.resource(1)
|
|||
stat: m[8],
|
||||
start: m[9],
|
||||
time: m[10],
|
||||
command: m[11]
|
||||
command: m[11],
|
||||
}
|
||||
end
|
||||
|
||||
@list = all_cmds.find_all do |hm|
|
||||
hm[:command] =~ grep
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,19 +16,19 @@ class RegistryKey < Vulcano.resource(1)
|
|||
|
||||
def initialize(name, reg_key = nil)
|
||||
# if we have one parameter, we use it as name
|
||||
reg_key = name if reg_key == nil
|
||||
reg_key ||= name
|
||||
@name = name
|
||||
@reg_key = reg_key
|
||||
end
|
||||
|
||||
def getRegistryValue(path, key)
|
||||
def registry_value(path, key)
|
||||
cmd = "(Get-Item 'Registry::#{path}').GetValue('#{key}')"
|
||||
command_result ||= vulcano.run_command(cmd)
|
||||
val = { exit_code: command_result.exit_status.to_i, data: command_result.stdout }
|
||||
val
|
||||
end
|
||||
|
||||
def convertValue(value)
|
||||
def convert_value(value)
|
||||
val = value.strip
|
||||
val = val.to_i if val.match(/^\d+$/)
|
||||
val
|
||||
|
@ -37,11 +37,11 @@ class RegistryKey < Vulcano.resource(1)
|
|||
# returns nil, if not existant or value
|
||||
def method_missing(meth)
|
||||
# get data
|
||||
val = getRegistryValue(@reg_key, meth)
|
||||
val = registry_value(@reg_key, meth)
|
||||
|
||||
# verify data
|
||||
if (val[:exit_code] == 0)
|
||||
return convertValue(val[:data])
|
||||
return convert_value(val[:data])
|
||||
else
|
||||
return nil
|
||||
end
|
||||
|
|
|
@ -107,7 +107,7 @@ class YumRepo
|
|||
# extracts the shortname from a repo id
|
||||
# e.g. extras/7/x86_64 -> extras
|
||||
def shortname(id)
|
||||
val = /^\s*([^\/]*?)\/(.*?)\s*$/.match(id)
|
||||
val = %r{^\s*([^/]*?)/(.*?)\s*$}.match(id)
|
||||
val[1]
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue