2015-09-20 21:55:00 +00:00
|
|
|
# encoding: utf-8
|
2015-10-06 16:55:44 +00:00
|
|
|
# author: Dominik Richter
|
|
|
|
# author: Christoph Hartmann
|
2015-09-20 21:55:00 +00:00
|
|
|
|
2016-03-08 18:06:55 +00:00
|
|
|
module Inspec::Resources
|
2016-03-09 09:35:45 +00:00
|
|
|
class OSResource < Inspec.resource(1)
|
2016-03-08 18:06:55 +00:00
|
|
|
name 'os'
|
|
|
|
desc 'Use the os InSpec audit resource to test the platform on which the system is running.'
|
|
|
|
example "
|
2016-05-30 08:32:28 +00:00
|
|
|
describe os.family do
|
2016-03-08 18:06:55 +00:00
|
|
|
it { should eq 'redhat' }
|
|
|
|
end
|
2016-05-30 08:32:28 +00:00
|
|
|
|
|
|
|
describe os.redhat? do
|
|
|
|
it { should eq true }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe os.linux? do
|
|
|
|
it { should eq true }
|
|
|
|
end
|
2016-03-08 18:06:55 +00:00
|
|
|
"
|
2015-09-20 21:55:00 +00:00
|
|
|
|
2016-03-08 18:06:55 +00:00
|
|
|
# reuse helper methods from backend
|
2016-08-19 22:18:53 +00:00
|
|
|
%w{aix? redhat? debian? suse? bsd? solaris? linux? unix? windows? hpux? darwin?}.each do |os_family|
|
2016-03-08 18:06:55 +00:00
|
|
|
define_method(os_family.to_sym) do
|
|
|
|
inspec.backend.os.send(os_family)
|
|
|
|
end
|
2015-10-07 16:28:34 +00:00
|
|
|
end
|
|
|
|
|
2016-03-08 18:06:55 +00:00
|
|
|
def [](name)
|
|
|
|
# convert string to symbol
|
|
|
|
name = name.to_sym if name.is_a? String
|
|
|
|
inspec.backend.os[name]
|
|
|
|
end
|
2015-10-12 11:01:58 +00:00
|
|
|
|
2016-05-30 08:32:28 +00:00
|
|
|
# add helper methods for easy access of properties
|
|
|
|
# allows users to use os.name, os.family, os.release, os.arch
|
|
|
|
%w{name family release arch}.each do |property|
|
|
|
|
define_method(property.to_sym) do
|
|
|
|
inspec.backend.os[property.to_sym]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# helper to collect a hash object easily
|
2016-04-26 18:00:00 +00:00
|
|
|
def params
|
|
|
|
{
|
|
|
|
name: inspec.backend.os[:name],
|
|
|
|
family: inspec.backend.os[:family],
|
|
|
|
release: inspec.backend.os[:release],
|
|
|
|
arch: inspec.backend.os[:arch],
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2016-03-08 18:06:55 +00:00
|
|
|
def to_s
|
|
|
|
'Operating System Detection'
|
|
|
|
end
|
2015-09-20 21:55:00 +00:00
|
|
|
end
|
|
|
|
end
|