migrate env and apache conf

Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
This commit is contained in:
Dominik Richter 2015-08-28 13:02:18 -07:00
parent dddc9daed0
commit 2a8b8d3394
3 changed files with 21 additions and 28 deletions

View file

@ -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

View file

@ -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

View file

@ -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'