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
|
# parse the file
|
||||||
@params = SimpleConfig.new(
|
@params = SimpleConfig.new(
|
||||||
@content,
|
@content,
|
||||||
multiple_values: false
|
multiple_values: false,
|
||||||
).params
|
).params
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,7 +18,7 @@ class AuditDaemonRules < Vulcano.resource(1)
|
||||||
|
|
||||||
@opts = {
|
@opts = {
|
||||||
assignment_re: /^\s*([^:]*?)\s*:\s*(.*?)\s*$/,
|
assignment_re: /^\s*([^:]*?)\s*:\s*(.*?)\s*$/,
|
||||||
multiple_values: true
|
multiple_values: true,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -33,12 +33,13 @@ class AuditDaemonRules < Vulcano.resource(1)
|
||||||
def status(name)
|
def status(name)
|
||||||
@status_opts = {
|
@status_opts = {
|
||||||
assignment_re: /^\s*([^:]*?)\s*:\s*(.*?)\s*$/,
|
assignment_re: /^\s*([^:]*?)\s*:\s*(.*?)\s*$/,
|
||||||
multiple_values: false
|
multiple_values: false,
|
||||||
}
|
}
|
||||||
@status_content ||= vulcano.run_command('/sbin/auditctl -s').stdout.chomp
|
@status_content ||= vulcano.run_command('/sbin/auditctl -s').stdout.chomp
|
||||||
@status_params = SimpleConfig.new(@status_content, @status_opts).params
|
@status_params = SimpleConfig.new(@status_content, @status_opts).params
|
||||||
|
|
||||||
status = @status_params['AUDIT_STATUS']
|
status = @status_params['AUDIT_STATUS']
|
||||||
if (status == nil) then return nil end
|
return nil if status.nil?
|
||||||
|
|
||||||
items = Hash[status.scan(/([^=]+)=(\w*)\s*/)]
|
items = Hash[status.scan(/([^=]+)=(\w*)\s*/)]
|
||||||
items[name]
|
items[name]
|
||||||
|
|
|
@ -20,7 +20,7 @@ module Vulcano::Resources
|
||||||
@params = SimpleConfig.new(
|
@params = SimpleConfig.new(
|
||||||
@file.content,
|
@file.content,
|
||||||
assignment_re: /^\s*([^:]*?)\s*:\s*(.*?)\s*$/,
|
assignment_re: /^\s*([^:]*?)\s*:\s*(.*?)\s*$/,
|
||||||
multiple_values: true
|
multiple_values: true,
|
||||||
).params if @file.exists?
|
).params if @file.exists?
|
||||||
@loaded = true
|
@loaded = true
|
||||||
@content
|
@content
|
||||||
|
|
|
@ -22,7 +22,7 @@ module Vulcano::Resources
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def contain(pattern, from, to)
|
def contain(*_)
|
||||||
fail ' not yet implemented '
|
fail ' not yet implemented '
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ class GemPackage < Vulcano.resource(1)
|
||||||
@cache = {
|
@cache = {
|
||||||
name: params[1],
|
name: params[1],
|
||||||
version: versions[0],
|
version: versions[0],
|
||||||
type: 'gem'
|
type: 'gem',
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ class InetdConf < Vulcano.resource(1)
|
||||||
@content,
|
@content,
|
||||||
assignment_re: /^\s*(\S+?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s*$/,
|
assignment_re: /^\s*(\S+?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s*$/,
|
||||||
key_vals: 6,
|
key_vals: 6,
|
||||||
multiple_values: false
|
multiple_values: false,
|
||||||
).params
|
).params
|
||||||
@content
|
@content
|
||||||
end
|
end
|
||||||
|
|
|
@ -45,7 +45,7 @@ class LimitsConf < Vulcano.resource(1)
|
||||||
@content,
|
@content,
|
||||||
assignment_re: /^\s*(\S+?)\s+(.*?)\s+(.*?)\s+(.*?)\s*$/,
|
assignment_re: /^\s*(\S+?)\s+(.*?)\s+(.*?)\s+(.*?)\s*$/,
|
||||||
key_vals: 3,
|
key_vals: 3,
|
||||||
multiple_values: true
|
multiple_values: true,
|
||||||
).params
|
).params
|
||||||
@content
|
@content
|
||||||
end
|
end
|
||||||
|
|
|
@ -50,7 +50,7 @@ class LoginDef < Vulcano.resource(1)
|
||||||
@params = SimpleConfig.new(
|
@params = SimpleConfig.new(
|
||||||
@content,
|
@content,
|
||||||
assignment_re: /^\s*(\S+)\s+(\S*)\s*$/,
|
assignment_re: /^\s*(\S+)\s+(\S*)\s*$/,
|
||||||
multiple_values: false
|
multiple_values: false,
|
||||||
).params
|
).params
|
||||||
@content
|
@content
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,7 +20,7 @@ class NpmPackage < Vulcano.resource(1)
|
||||||
@cache = {
|
@cache = {
|
||||||
name: @package_name,
|
name: @package_name,
|
||||||
version: pkgs['dependencies'][@package_name]['version'],
|
version: pkgs['dependencies'][@package_name]['version'],
|
||||||
type: 'npm'
|
type: 'npm',
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ class NtpConf < Vulcano.resource(1)
|
||||||
@params = SimpleConfig.new(
|
@params = SimpleConfig.new(
|
||||||
@content,
|
@content,
|
||||||
assignment_re: /^\s*(\S+)\s+(.*)\s*$/,
|
assignment_re: /^\s*(\S+)\s+(.*)\s*$/,
|
||||||
multiple_values: true
|
multiple_values: true,
|
||||||
).params
|
).params
|
||||||
@content
|
@content
|
||||||
end
|
end
|
||||||
|
|
|
@ -31,7 +31,7 @@ class Package < Vulcano.resource(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
# returns true if the package is installed
|
# returns true if the package is installed
|
||||||
def installed?(provider = nil, version = nil)
|
def installed?(_provider, _version)
|
||||||
!info.nil?
|
!info.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -17,13 +17,11 @@ class PConfig < Vulcano.resource(1)
|
||||||
def initialize(content = nil, useropts = {})
|
def initialize(content = nil, useropts = {})
|
||||||
default_options = {}
|
default_options = {}
|
||||||
@opts = default_options.merge(useropts)
|
@opts = default_options.merge(useropts)
|
||||||
@content = content
|
|
||||||
@files_contents = {}
|
@files_contents = {}
|
||||||
@params = nil
|
@params = nil
|
||||||
|
|
||||||
if @content != nil then
|
@content = content
|
||||||
read_content
|
read_content if @content.nil?
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
|
|
|
@ -77,7 +77,7 @@ class Passwd < Vulcano.resource(1)
|
||||||
'gid' => x.at(3),
|
'gid' => x.at(3),
|
||||||
'desc' => x.at(4),
|
'desc' => x.at(4),
|
||||||
'home' => x.at(5),
|
'home' => x.at(5),
|
||||||
'shell' => x.at(6)
|
'shell' => x.at(6),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,13 +13,25 @@ class Processes < Vulcano.resource(1)
|
||||||
grep = Regexp.new('^' + grep + '(\s|$)')
|
grep = Regexp.new('^' + grep + '(\s|$)')
|
||||||
end
|
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
|
# get all running processes
|
||||||
cmd = vulcano.run_command('ps aux')
|
cmd = vulcano.run_command('ps aux')
|
||||||
all = cmd.stdout.split("\n")[1..-1]
|
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
|
# 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+(.*)$/)
|
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],
|
user: m[1],
|
||||||
pid: m[2],
|
pid: m[2],
|
||||||
|
@ -31,12 +43,8 @@ class Processes < Vulcano.resource(1)
|
||||||
stat: m[8],
|
stat: m[8],
|
||||||
start: m[9],
|
start: m[9],
|
||||||
time: m[10],
|
time: m[10],
|
||||||
command: m[11]
|
command: m[11],
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@list = all_cmds.find_all do |hm|
|
|
||||||
hm[:command] =~ grep
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,19 +16,19 @@ class RegistryKey < Vulcano.resource(1)
|
||||||
|
|
||||||
def initialize(name, reg_key = nil)
|
def initialize(name, reg_key = nil)
|
||||||
# if we have one parameter, we use it as name
|
# if we have one parameter, we use it as name
|
||||||
reg_key = name if reg_key == nil
|
reg_key ||= name
|
||||||
@name = name
|
@name = name
|
||||||
@reg_key = reg_key
|
@reg_key = reg_key
|
||||||
end
|
end
|
||||||
|
|
||||||
def getRegistryValue(path, key)
|
def registry_value(path, key)
|
||||||
cmd = "(Get-Item 'Registry::#{path}').GetValue('#{key}')"
|
cmd = "(Get-Item 'Registry::#{path}').GetValue('#{key}')"
|
||||||
command_result ||= vulcano.run_command(cmd)
|
command_result ||= vulcano.run_command(cmd)
|
||||||
val = { exit_code: command_result.exit_status.to_i, data: command_result.stdout }
|
val = { exit_code: command_result.exit_status.to_i, data: command_result.stdout }
|
||||||
val
|
val
|
||||||
end
|
end
|
||||||
|
|
||||||
def convertValue(value)
|
def convert_value(value)
|
||||||
val = value.strip
|
val = value.strip
|
||||||
val = val.to_i if val.match(/^\d+$/)
|
val = val.to_i if val.match(/^\d+$/)
|
||||||
val
|
val
|
||||||
|
@ -37,11 +37,11 @@ class RegistryKey < Vulcano.resource(1)
|
||||||
# returns nil, if not existant or value
|
# returns nil, if not existant or value
|
||||||
def method_missing(meth)
|
def method_missing(meth)
|
||||||
# get data
|
# get data
|
||||||
val = getRegistryValue(@reg_key, meth)
|
val = registry_value(@reg_key, meth)
|
||||||
|
|
||||||
# verify data
|
# verify data
|
||||||
if (val[:exit_code] == 0)
|
if (val[:exit_code] == 0)
|
||||||
return convertValue(val[:data])
|
return convert_value(val[:data])
|
||||||
else
|
else
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
|
@ -107,7 +107,7 @@ class YumRepo
|
||||||
# extracts the shortname from a repo id
|
# extracts the shortname from a repo id
|
||||||
# e.g. extras/7/x86_64 -> extras
|
# e.g. extras/7/x86_64 -> extras
|
||||||
def shortname(id)
|
def shortname(id)
|
||||||
val = /^\s*([^\/]*?)\/(.*?)\s*$/.match(id)
|
val = %r{^\s*([^/]*?)/(.*?)\s*$}.match(id)
|
||||||
val[1]
|
val[1]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue