mirror of
https://github.com/inspec/inspec
synced 2024-11-23 13:13:22 +00:00
migrate env and apache conf
Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
This commit is contained in:
parent
dddc9daed0
commit
2a8b8d3394
3 changed files with 21 additions and 28 deletions
|
@ -5,12 +5,12 @@
|
||||||
require 'utils/simpleconfig'
|
require 'utils/simpleconfig'
|
||||||
require 'utils/find_files'
|
require 'utils/find_files'
|
||||||
|
|
||||||
class ApacheConf
|
class ApacheConf < Vulcano.resource(1)
|
||||||
|
name 'apache_conf'
|
||||||
|
|
||||||
def initialize( conf_path )
|
def initialize( conf_path )
|
||||||
@runner = Specinfra::Runner
|
|
||||||
@conf_path = conf_path
|
@conf_path = conf_path
|
||||||
@conf_dir = File.expand_path(File.dirname @conf_path)
|
@conf_dir = File.dirname(@conf_path)
|
||||||
@files_contents = {}
|
@files_contents = {}
|
||||||
@content = nil
|
@content = nil
|
||||||
@params = nil
|
@params = nil
|
||||||
|
@ -45,11 +45,13 @@ class ApacheConf
|
||||||
@params = {}
|
@params = {}
|
||||||
|
|
||||||
# skip if the main configuration file doesn't exist
|
# 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}\""
|
return skip_resource "Can't find file \"#{@conf_path}\""
|
||||||
end
|
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}\"")
|
return skip_resource("Can't read file \"#{@conf_path}\"")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -100,6 +102,6 @@ class ApacheConf
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_file(path)
|
def read_file(path)
|
||||||
@files_contents[path] ||= @runner.get_file_content(path).stdout
|
@files_contents[path] ||= @vulcano.file(path).contents
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,40 +2,31 @@
|
||||||
# copyright: 2015, Vulcano Security GmbH
|
# copyright: 2015, Vulcano Security GmbH
|
||||||
# license: All rights reserved
|
# license: All rights reserved
|
||||||
|
|
||||||
include Serverspec::Type
|
class OsEnv < Vulcano.resource(1)
|
||||||
|
name 'os_env'
|
||||||
|
|
||||||
class EnvironmentVariable < Serverspec::Type::Base
|
attr_reader :content
|
||||||
|
def initialize(field)
|
||||||
def method_missing(method)
|
@command_result = @vulcano.run_command("su - root -c 'echo $#{name}'")
|
||||||
@command_result ||= @runner.run_command("su - root -c 'echo $#{name}'")
|
@content = @command_result.stdout.chomp
|
||||||
end
|
|
||||||
|
|
||||||
def content
|
|
||||||
command_result.stdout.chomp
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def split
|
def split
|
||||||
# -1 is required to catch cases like dir1::dir2:
|
# -1 is required to catch cases like dir1::dir2:
|
||||||
# where we have a trailing :
|
# where we have a trailing :
|
||||||
command_result.stdout.chomp.split(':', -1)
|
@content.split(':', -1)
|
||||||
end
|
end
|
||||||
|
|
||||||
def stderr
|
def stderr
|
||||||
command_result.stderr
|
@command_result.stderr
|
||||||
end
|
end
|
||||||
|
|
||||||
def exit_status
|
def exit_status
|
||||||
command_result.exit_status.to_i
|
@command_result.exit_status.to_i
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
%Q[Environment Variable]
|
"Environment variable #{field}"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module Serverspec::Type
|
|
||||||
def os_env(name)
|
|
||||||
EnvironmentVariable.new(name)
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,12 +1,12 @@
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
require 'vulcano/resource'
|
require 'vulcano/resource'
|
||||||
|
|
||||||
# require 'resources/apache_conf'
|
require 'resources/apache_conf'
|
||||||
# require 'resources/audit_policy'
|
# require 'resources/audit_policy'
|
||||||
# require 'resources/auditd_conf'
|
# require 'resources/auditd_conf'
|
||||||
# require 'resources/auditd_rules'
|
# require 'resources/auditd_rules'
|
||||||
# require 'resources/command'
|
# require 'resources/command'
|
||||||
# require 'resources/env'
|
require 'resources/env'
|
||||||
require 'resources/etc_group'
|
require 'resources/etc_group'
|
||||||
# require 'resources/file'
|
# require 'resources/file'
|
||||||
# require 'resources/group_policy'
|
# require 'resources/group_policy'
|
||||||
|
|
Loading…
Reference in a new issue