mirror of
https://github.com/inspec/inspec
synced 2025-02-17 06:28:40 +00:00
add to_s methods to resources, fixes #98
This commit is contained in:
parent
187dcf4a7e
commit
03f07e1a3e
42 changed files with 144 additions and 61 deletions
|
@ -106,4 +106,8 @@ class ApacheConf < Vulcano.resource(1)
|
|||
def read_file(path)
|
||||
@files_contents[path] ||= vulcano.file(path).content
|
||||
end
|
||||
|
||||
def to_s
|
||||
"Apache Config #{@conf_path}"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -52,7 +52,7 @@ class AptRepository < Vulcano.resource(1)
|
|||
end
|
||||
|
||||
def to_s
|
||||
"apt #{@deb_url}"
|
||||
"Apt Repository #{@deb_url}"
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -58,6 +58,6 @@ class AuditPolicy < Vulcano.resource(1)
|
|||
end
|
||||
|
||||
def to_s
|
||||
'Windows Advanced Auditing'
|
||||
'Audit Policy'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,14 +20,14 @@ class AuditDaemonConf < Vulcano.resource(1)
|
|||
@conf_path = path || '/etc/audit/auditd.conf'
|
||||
end
|
||||
|
||||
def to_s
|
||||
'audit daemon configuration file'
|
||||
end
|
||||
|
||||
def method_missing(name)
|
||||
read_params[name.to_s]
|
||||
end
|
||||
|
||||
def to_s
|
||||
'Audit Daemon Config'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def read_params
|
||||
|
|
|
@ -9,6 +9,7 @@ module Vulcano::Resources
|
|||
name 'bond'
|
||||
|
||||
def initialize(bond)
|
||||
@bond = bond
|
||||
@path = "/proc/net/bonding/#{bond}"
|
||||
@file = vulcano.file(@path)
|
||||
@content = nil
|
||||
|
@ -50,5 +51,9 @@ module Vulcano::Resources
|
|||
def interfaces
|
||||
params['Slave Interface']
|
||||
end
|
||||
|
||||
def to_s
|
||||
"Bond #{@bond}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -37,6 +37,10 @@ class Bridge < Vulcano.resource(1)
|
|||
bridge_info.nil? ? nil : bridge_info[:interfaces]
|
||||
end
|
||||
|
||||
def to_s
|
||||
"Bridge #{@bridge_name}"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def bridge_info
|
||||
|
|
|
@ -30,4 +30,8 @@ class Cmd < Vulcano.resource(1)
|
|||
res = vulcano.backend.run_command("type \"#{@command}\" > /dev/null")
|
||||
res.exit_status.to_i == 0
|
||||
end
|
||||
|
||||
def to_s
|
||||
"Command #{@command}"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -25,4 +25,8 @@ class CsvConfig < JsonConfig
|
|||
# convert to hash
|
||||
csv.to_a.map(&:to_hash)
|
||||
end
|
||||
|
||||
def to_s
|
||||
"Csv #{@path}"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,4 +8,8 @@ module Vulcano::Resources
|
|||
class Directory < File
|
||||
name 'directory'
|
||||
end
|
||||
|
||||
def to_s
|
||||
"Directory #{@path}"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -40,10 +40,6 @@ class EtcGroup < Vulcano.resource(1)
|
|||
unless %w{ubuntu debian redhat fedora arch darwin freebsd}.include?(vulcano.os[:family])
|
||||
end
|
||||
|
||||
def to_s
|
||||
@path
|
||||
end
|
||||
|
||||
def groups(filter = nil)
|
||||
entries = filter || @entries
|
||||
entries.map { |x| x['name'] } if !entries.nil?
|
||||
|
@ -87,6 +83,10 @@ class EtcGroup < Vulcano.resource(1)
|
|||
EtcGroupView.new(self, res)
|
||||
end
|
||||
|
||||
def to_s
|
||||
'/etc/group'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def parse_group(path)
|
||||
|
|
|
@ -63,7 +63,7 @@ module Vulcano::Resources
|
|||
end
|
||||
|
||||
def to_s
|
||||
"Path '#{@path}'"
|
||||
"File #{@path}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -69,6 +69,10 @@ class Group < Vulcano.resource(1)
|
|||
end
|
||||
end
|
||||
|
||||
def to_s
|
||||
"Group #{@group}"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def group_info
|
||||
|
|
|
@ -59,7 +59,7 @@ class Host < Vulcano.resource(1)
|
|||
end
|
||||
|
||||
def to_s
|
||||
"host #{@hostname}"
|
||||
"Host #{@hostname}"
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -21,10 +21,6 @@ class InetdConf < Vulcano.resource(1)
|
|||
@conf_path = path || '/etc/inetd.conf'
|
||||
end
|
||||
|
||||
def to_s
|
||||
'inetd_conf'
|
||||
end
|
||||
|
||||
def method_missing(name)
|
||||
read_params[name.to_s]
|
||||
end
|
||||
|
@ -53,4 +49,8 @@ class InetdConf < Vulcano.resource(1)
|
|||
)
|
||||
@params = conf.params
|
||||
end
|
||||
|
||||
def to_s
|
||||
'inetd.conf'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -40,6 +40,10 @@ class NetworkInterface < Vulcano.resource(1)
|
|||
interface_info.nil? ? nil : interface_info[:speed]
|
||||
end
|
||||
|
||||
def to_s
|
||||
"Interface #{@iface}"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def interface_info
|
||||
|
|
|
@ -60,6 +60,6 @@ class IpTables < Vulcano.resource(1)
|
|||
end
|
||||
|
||||
def to_s
|
||||
format('iptables %s %s', @table.nil? ? '' : "table: #{@table}", @chain.nil? ? '' : "chain: #{@chain}").strip
|
||||
format('Iptables %s %s', @table.nil? ? '' : "table: #{@table}", @chain.nil? ? '' : "chain: #{@chain}").strip
|
||||
end
|
||||
end
|
||||
|
|
|
@ -54,4 +54,8 @@ class JsonConfig < Vulcano.resource(1)
|
|||
keys = name.to_s.split('.')
|
||||
extract_value(keys, @params.clone)
|
||||
end
|
||||
|
||||
def to_s
|
||||
"Json #{@path}"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -19,10 +19,6 @@ class LimitsConf < Vulcano.resource(1)
|
|||
@conf_path = path || '/etc/security/limits.conf'
|
||||
end
|
||||
|
||||
def to_s
|
||||
'limits_conf'
|
||||
end
|
||||
|
||||
def method_missing(name)
|
||||
read_params[name.to_s]
|
||||
end
|
||||
|
@ -52,4 +48,8 @@ class LimitsConf < Vulcano.resource(1)
|
|||
)
|
||||
@params = conf.params
|
||||
end
|
||||
|
||||
def to_s
|
||||
'limits.conf'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -25,10 +25,6 @@ class LoginDef < Vulcano.resource(1)
|
|||
@conf_path = path || '/etc/login.defs'
|
||||
end
|
||||
|
||||
def to_s
|
||||
'login_def'
|
||||
end
|
||||
|
||||
def method_missing(name)
|
||||
read_params[name.to_s]
|
||||
end
|
||||
|
@ -57,4 +53,8 @@ class LoginDef < Vulcano.resource(1)
|
|||
)
|
||||
@params = conf.params
|
||||
end
|
||||
|
||||
def to_s
|
||||
'login.defs'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -74,4 +74,8 @@ class Mysql < Vulcano.resource(1)
|
|||
@log_group = 'mysql'
|
||||
@log_dir_group = 'root'
|
||||
end
|
||||
|
||||
def to_s
|
||||
'MySQL'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -109,4 +109,8 @@ class MysqlConf < Vulcano.resource(1)
|
|||
def read_file(path)
|
||||
@files_contents[path] ||= vulcano.file(path).content
|
||||
end
|
||||
|
||||
def to_s
|
||||
'MySQL Configuration'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -32,6 +32,10 @@ class MysqlSession < Vulcano.resource(1)
|
|||
cmd
|
||||
end
|
||||
|
||||
def to_s
|
||||
'MySQL Session'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def init_fallback
|
||||
|
|
|
@ -39,6 +39,6 @@ class NpmPackage < Vulcano.resource(1)
|
|||
end
|
||||
|
||||
def to_s
|
||||
"npm package #{@package_name}"
|
||||
"Npm Package #{@package_name}"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,10 +20,6 @@ class NtpConf < Vulcano.resource(1)
|
|||
@conf_path = path || '/etc/ntp.conf'
|
||||
end
|
||||
|
||||
def to_s
|
||||
'ntp_conf'
|
||||
end
|
||||
|
||||
def method_missing(name)
|
||||
param = read_params[name.to_s]
|
||||
# extract first value if we have only one value in array
|
||||
|
@ -31,6 +27,10 @@ class NtpConf < Vulcano.resource(1)
|
|||
param
|
||||
end
|
||||
|
||||
def to_s
|
||||
'ntp.conf'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def read_params
|
||||
|
|
|
@ -58,6 +58,6 @@ class OneGetPackage < Vulcano.resource(1)
|
|||
end
|
||||
|
||||
def to_s
|
||||
"oneget package #{@package_name}"
|
||||
"OneGet Package #{@package_name}"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,19 +2,21 @@
|
|||
# author: Dominik Richter
|
||||
# author: Christoph Hartmann
|
||||
|
||||
module Vulcano::Resources
|
||||
class OS < Vulcano.resource(1)
|
||||
name 'os'
|
||||
class OS < Vulcano.resource(1)
|
||||
name 'os'
|
||||
|
||||
# reuse helper methods from backend
|
||||
%w{redhat? debian? suse? bsd? solaris? linux? unix? windows?}.each do |os_family|
|
||||
define_method((os_family).to_sym) do
|
||||
vulcano.backend.os.send(os_family)
|
||||
end
|
||||
end
|
||||
|
||||
def [](name)
|
||||
vulcano.backend.os[name]
|
||||
# reuse helper methods from backend
|
||||
%w{redhat? debian? suse? bsd? solaris? linux? unix? windows?}.each do |os_family|
|
||||
define_method((os_family).to_sym) do
|
||||
vulcano.backend.os.send(os_family)
|
||||
end
|
||||
end
|
||||
|
||||
def [](name)
|
||||
vulcano.backend.os[name]
|
||||
end
|
||||
|
||||
def to_s
|
||||
'Operating System Detection'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -36,6 +36,6 @@ class OsEnv < Vulcano.resource(1)
|
|||
end
|
||||
|
||||
def to_s
|
||||
"Environment variable #{@osenv}"
|
||||
"Environment Variable #{@osenv}"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -54,7 +54,7 @@ class Package < Vulcano.resource(1)
|
|||
end
|
||||
|
||||
def to_s
|
||||
"System package #{@package_name}"
|
||||
"System Package #{@package_name}"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -26,10 +26,6 @@ class PConfig < Vulcano.resource(1)
|
|||
read_content if @content.nil?
|
||||
end
|
||||
|
||||
def to_s
|
||||
"parse_config #{@conf_path}"
|
||||
end
|
||||
|
||||
def method_missing(name)
|
||||
@params || read_content
|
||||
@params[name.to_s]
|
||||
|
@ -59,6 +55,10 @@ class PConfig < Vulcano.resource(1)
|
|||
@params = SimpleConfig.new(@content, @opts).params
|
||||
@content
|
||||
end
|
||||
|
||||
def to_s
|
||||
"Parse Config #{@conf_path}"
|
||||
end
|
||||
end
|
||||
|
||||
class PConfigFile < PConfig
|
||||
|
@ -68,4 +68,8 @@ class PConfigFile < PConfig
|
|||
super(nil, opts)
|
||||
parse_file(path)
|
||||
end
|
||||
|
||||
def to_s
|
||||
"Parse Config File #{@conf_path}"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -41,10 +41,6 @@ class Passwd < Vulcano.resource(1)
|
|||
@parsed = parse_passwd(@content)
|
||||
end
|
||||
|
||||
def to_s
|
||||
@path
|
||||
end
|
||||
|
||||
# call passwd().uid(0)
|
||||
# returns a seperate object with reference to this object
|
||||
def uid(uid)
|
||||
|
@ -73,6 +69,10 @@ class Passwd < Vulcano.resource(1)
|
|||
}
|
||||
end
|
||||
|
||||
def to_s
|
||||
'/etc/passwd'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def map_data(id)
|
||||
|
|
|
@ -42,7 +42,7 @@ class PipPackage < Vulcano.resource(1)
|
|||
end
|
||||
|
||||
def to_s
|
||||
"pip package #{@package_name}"
|
||||
"Pip Package #{@package_name}"
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -56,6 +56,10 @@ class Port < Vulcano.resource(1)
|
|||
res.size > 0 ? res : nil
|
||||
end
|
||||
|
||||
def to_s
|
||||
"Port #{@port}"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def info
|
||||
|
|
|
@ -30,4 +30,8 @@ class Postgres < Vulcano.resource(1)
|
|||
@conf_path = File.join @conf_dir, 'postgresql.conf'
|
||||
end
|
||||
end
|
||||
|
||||
def to_s
|
||||
'PostgreSQL'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -80,4 +80,8 @@ class PostgresConf < Vulcano.resource(1)
|
|||
def read_file(path)
|
||||
@files_contents[path] ||= vulcano.file(path).content
|
||||
end
|
||||
|
||||
def to_s
|
||||
'PostgreSQL Configuration'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -21,6 +21,10 @@ class Processes < Vulcano.resource(1)
|
|||
end
|
||||
end
|
||||
|
||||
def to_s
|
||||
'Processes'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def ps_aux
|
||||
|
|
|
@ -27,4 +27,8 @@ class Script < Cmd
|
|||
def exist?
|
||||
nil
|
||||
end
|
||||
|
||||
def to_s
|
||||
'Script'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -68,6 +68,6 @@ class SecurityPolicy < Vulcano.resource(1)
|
|||
end
|
||||
|
||||
def to_s
|
||||
%{Security Policy}
|
||||
'Security Policy'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,10 +15,6 @@ class SshConf < Vulcano.resource(1)
|
|||
@type = type || "SSH #{typename} configuration #{conf_path}"
|
||||
end
|
||||
|
||||
def to_s
|
||||
@type
|
||||
end
|
||||
|
||||
def content
|
||||
read_content
|
||||
end
|
||||
|
@ -37,6 +33,10 @@ class SshConf < Vulcano.resource(1)
|
|||
param
|
||||
end
|
||||
|
||||
def to_s
|
||||
'SSH Configuration'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def read_content
|
||||
|
|
|
@ -142,7 +142,7 @@ class User < Vulcano.resource(1)
|
|||
end
|
||||
|
||||
def to_s
|
||||
"user #{@user}"
|
||||
"User #{@user}"
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -72,6 +72,6 @@ class WindowsFeature < Vulcano.resource(1)
|
|||
end
|
||||
|
||||
def to_s
|
||||
"Windows feature '#{@feature}'"
|
||||
"Windows Feature '#{@feature}'"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,4 +16,8 @@ class YamlConfig < JsonConfig
|
|||
def parse(content)
|
||||
YAML.load(content)
|
||||
end
|
||||
|
||||
def to_s
|
||||
"YAML #{@path}"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -80,6 +80,10 @@ module Vulcano::Resources
|
|||
repo(name.to_s) if !name.nil?
|
||||
end
|
||||
|
||||
def to_s
|
||||
"yum repository"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Removes lefthand and righthand whitespace
|
||||
|
|
Loading…
Add table
Reference in a new issue