inspec/lib/resources/os_env.rb

40 lines
769 B
Ruby
Raw Normal View History

2015-07-15 15:15:18 +02:00
# encoding: utf-8
# copyright: 2015, Vulcano Security GmbH
# license: All rights reserved
2015-09-05 20:09:55 +02:00
# Usage:
#
# describe os_env('PATH') do |dirs|
# its(:split) { should_not include('') }
# its(:split) { should_not include('.') }
# end
class OsEnv < Vulcano.resource(1)
name 'os_env'
2015-07-15 00:47:04 +02:00
attr_reader :content
2015-09-04 09:59:30 +02:00
def initialize(env)
@osenv = env
@command_result = vulcano.run_command("su - root -c 'echo $#{env}'")
@content = @command_result.stdout.chomp
2015-07-26 12:30:12 +02:00
end
2015-07-15 00:47:04 +02:00
2015-07-26 12:30:12 +02:00
def split
# -1 is required to catch cases like dir1::dir2:
# where we have a trailing :
@content.split(':', -1)
2015-07-26 12:30:12 +02:00
end
2015-07-26 12:30:12 +02:00
def stderr
@command_result.stderr
2015-07-26 12:30:12 +02:00
end
2015-07-15 00:47:04 +02:00
2015-07-26 12:30:12 +02:00
def exit_status
@command_result.exit_status.to_i
2015-07-26 12:30:12 +02:00
end
2015-07-15 00:47:04 +02:00
2015-07-26 12:30:12 +02:00
def to_s
2015-09-04 09:59:30 +02:00
"Environment variable #{@osenv}"
2015-07-15 00:47:04 +02:00
end
2015-07-26 12:30:12 +02:00
end