diff --git a/lib/resources/apache_conf.rb b/lib/resources/apache_conf.rb index 5e6718c24..f8c91328e 100644 --- a/lib/resources/apache_conf.rb +++ b/lib/resources/apache_conf.rb @@ -5,12 +5,12 @@ require 'utils/simpleconfig' require 'utils/find_files' -class ApacheConf +class ApacheConf < Vulcano.resource(1) + name 'apache_conf' def initialize( conf_path ) - @runner = Specinfra::Runner @conf_path = conf_path - @conf_dir = File.expand_path(File.dirname @conf_path) + @conf_dir = File.dirname(@conf_path) @files_contents = {} @content = nil @params = nil @@ -45,11 +45,13 @@ class ApacheConf @params = {} # skip if the main configuration file doesn't exist - if !@runner.check_file_is_file(@conf_path) + file = @vulcano.file(@conf_path) + if !file.is_file? return skip_resource "Can't find file \"#{@conf_path}\"" end - raw_conf = read_file(@conf_path) - if raw_conf.empty? && @runner.get_file_size(@conf_path).stdout.strip.to_i > 0 + + raw_conf = file.contents + if raw_conf.empty? && file.size > 0 return skip_resource("Can't read file \"#{@conf_path}\"") end @@ -100,6 +102,6 @@ class ApacheConf end def read_file(path) - @files_contents[path] ||= @runner.get_file_content(path).stdout + @files_contents[path] ||= @vulcano.file(path).contents end end diff --git a/lib/resources/env.rb b/lib/resources/env.rb index 000cd1b83..9f8619834 100644 --- a/lib/resources/env.rb +++ b/lib/resources/env.rb @@ -2,40 +2,31 @@ # copyright: 2015, Vulcano Security GmbH # license: All rights reserved -include Serverspec::Type +class OsEnv < Vulcano.resource(1) + name 'os_env' -class EnvironmentVariable < Serverspec::Type::Base - - def method_missing(method) - @command_result ||= @runner.run_command("su - root -c 'echo $#{name}'") - end - - def content - command_result.stdout.chomp + attr_reader :content + def initialize(field) + @command_result = @vulcano.run_command("su - root -c 'echo $#{name}'") + @content = @command_result.stdout.chomp end def split # -1 is required to catch cases like dir1::dir2: # where we have a trailing : - command_result.stdout.chomp.split(':', -1) + @content.split(':', -1) end def stderr - command_result.stderr + @command_result.stderr end def exit_status - command_result.exit_status.to_i + @command_result.exit_status.to_i end def to_s - %Q[Environment Variable] + "Environment variable #{field}" end end - -module Serverspec::Type - def os_env(name) - EnvironmentVariable.new(name) - end -end \ No newline at end of file diff --git a/lib/vulcano/resources.rb b/lib/vulcano/resources.rb index 4153e89f3..4b5ab7801 100644 --- a/lib/vulcano/resources.rb +++ b/lib/vulcano/resources.rb @@ -1,12 +1,12 @@ # encoding: utf-8 require 'vulcano/resource' -# require 'resources/apache_conf' +require 'resources/apache_conf' # require 'resources/audit_policy' # require 'resources/auditd_conf' # require 'resources/auditd_rules' # require 'resources/command' -# require 'resources/env' +require 'resources/env' require 'resources/etc_group' # require 'resources/file' # require 'resources/group_policy'