inspec/lib/resources/env.rb

41 lines
731 B
Ruby
Raw Normal View History

2015-07-15 13:15:18 +00:00
# encoding: utf-8
# copyright: 2015, Vulcano Security GmbH
# license: All rights reserved
2015-07-26 10:30:12 +00:00
include Serverspec::Type
2015-07-14 22:47:04 +00:00
2015-07-26 10:30:12 +00:00
class EnvironmentVariable < Serverspec::Type::Base
2015-07-14 22:47:04 +00:00
2015-07-26 10:30:12 +00:00
def method_missing(method)
@command_result ||= @runner.run_command("su - root -c 'echo $#{name}'")
end
2015-07-14 22:47:04 +00:00
2015-07-26 10:30:12 +00:00
def content
command_result.stdout.chomp
end
2015-07-14 22:47:04 +00:00
2015-07-26 10:30:12 +00:00
def split
# -1 is required to catch cases like dir1::dir2:
# where we have a trailing :
command_result.stdout.chomp.split(':', -1)
end
2015-07-26 10:30:12 +00:00
def stderr
command_result.stderr
end
2015-07-14 22:47:04 +00:00
2015-07-26 10:30:12 +00:00
def exit_status
command_result.exit_status.to_i
end
2015-07-14 22:47:04 +00:00
2015-07-26 10:30:12 +00:00
def to_s
%Q[Environment Variable]
2015-07-14 22:47:04 +00:00
end
2015-07-26 10:30:12 +00:00
end
module Serverspec::Type
def os_env(name)
EnvironmentVariable.new(name)
end
end