use os.linux and os.windows where possible

This commit is contained in:
Christoph Hartmann 2016-01-28 14:24:51 +01:00
parent a5f526b368
commit dd59dd9a5a
4 changed files with 30 additions and 31 deletions

View file

@ -22,21 +22,21 @@ class Package < Inspec.resource(1)
@package_name = package_name
@name = @package_name
@cache = nil
# select package manager
@pkgman = nil
case inspec.os[:family]
when 'ubuntu', 'debian'
os = inspec.os
if os.debian?
@pkgman = Deb.new(inspec)
when 'redhat', 'fedora', 'centos', 'opensuse', 'wrlinux'
elsif os.redhat? || os.suse?
@pkgman = Rpm.new(inspec)
when 'arch'
elsif ['arch'].include?(os[:family])
@pkgman = Pacman.new(inspec)
when 'darwin'
elsif ['darwin'].include?(os[:family])
@pkgman = Brew.new(inspec)
when 'windows'
elsif inspec.os.windows?
@pkgman = WindowsPkg.new(inspec)
when 'aix'
elsif ['aix'].include?(os[:family])
@pkgman = BffPkg.new(inspec)
else
return skip_resource 'The `package` resource is not supported on your OS yet.'

View file

@ -30,18 +30,17 @@ class Port < Inspec.resource(1)
@port = port
@port_manager = nil
@cache = nil
case inspec.os[:family]
when 'ubuntu', 'debian', 'redhat', 'fedora', 'centos', 'arch', 'wrlinux'
os = inspec.os
if os.linux?
@port_manager = LinuxPorts.new(inspec)
when 'darwin', 'aix'
elsif %w{darwin aix}.include?(os[:family])
# AIX: see http://www.ibm.com/developerworks/aix/library/au-lsof.html#resources
# and https://www-01.ibm.com/marketing/iwm/iwm/web/reg/pick.do?source=aixbp
# Darwin: https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man8/lsof.8.html
@port_manager = LsofPorts.new(inspec)
when 'windows'
elsif os.windows?
@port_manager = WindowsPorts.new(inspec)
when 'freebsd'
elsif ['freebsd'].include?(os[:family])
@port_manager = FreeBsdPorts.new(inspec)
else
return skip_resource 'The `port` resource is not supported on your OS yet.'

View file

@ -44,9 +44,9 @@ class Service < Inspec.resource(1)
end
def select_service_mgmt # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
family = inspec.os[:family]
os = inspec.os
family = os[:family]
case family
# Ubuntu
# @see: https://wiki.ubuntu.com/SystemdForUpstartUsers
# Ubuntu 15.04 : Systemd
@ -55,38 +55,38 @@ class Service < Inspec.resource(1)
# Ubuntu < 15.04 : Upstart
# Upstart runs with PID 1 as /sbin/init.
# Systemd runs with PID 1 as /lib/systemd/systemd.
when 'ubuntu'
if %w{ubuntu}.include?(family)
version = inspec.os[:release].to_f
if version < 15.04
Upstart.new(inspec, service_ctl)
else
Systemd.new(inspec, service_ctl)
end
when 'debian'
elsif %w{debian}.include?(family)
version = inspec.os[:release].to_i
if version > 7
Systemd.new(inspec, service_ctl)
else
SysV.new(inspec, service_ctl || '/usr/sbin/service')
end
when 'redhat', 'fedora', 'centos'
elsif %w{redhat fedora centos}.include?(family)
version = inspec.os[:release].to_i
if (%w{ redhat centos }.include?(family) && version >= 7) || (family == 'fedora' && version >= 15)
Systemd.new(inspec, service_ctl)
else
SysV.new(inspec, service_ctl || '/sbin/service')
end
when 'wrlinux'
elsif %w{wrlinux}.include?(family)
SysV.new(inspec, service_ctl)
when 'darwin'
elsif %w{darwin}.include?(family)
LaunchCtl.new(inspec, service_ctl)
when 'windows'
elsif os.windows?
WindowsSrv.new(inspec)
when 'freebsd'
elsif %w{freebsd}.include?(family)
BSDInit.new(inspec, service_ctl)
when 'arch', 'opensuse'
elsif %w{arch opensuse}.include?(family)
Systemd.new(inspec, service_ctl)
when 'aix'
elsif %w{aix}.include?(family)
SrcMstr.new(inspec)
end
end

View file

@ -53,16 +53,16 @@ class User < Inspec.resource(1)
# select package manager
@user_provider = nil
case inspec.os[:family]
when 'ubuntu', 'debian', 'redhat', 'fedora', 'centos', 'arch', 'opensuse', 'wrlinux'
os = inspec.os
if os.linux?
@user_provider = LinuxUser.new(inspec)
when 'windows'
elsif os.windows?
@user_provider = WindowsUser.new(inspec)
when 'darwin'
elsif ['darwin'].include?(os[:family])
@user_provider = DarwinUser.new(inspec)
when 'freebsd'
elsif ['freebsd'].include?(os[:family])
@user_provider = FreeBSDUser.new(inspec)
when 'aix'
elsif ['aix'].include?(os[:family])
@user_provider = AixUser.new(inspec)
else
return skip_resource 'The `user` resource is not supported on your OS yet.'