migrate all mysql resources

Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
This commit is contained in:
Dominik Richter 2015-08-28 12:41:48 -07:00
parent 1a45f32f0b
commit 8004d6f129
4 changed files with 17 additions and 33 deletions

View file

@ -2,7 +2,9 @@
# copyright: 2015, Vulcano Security GmbH
# license: All rights reserved
class Mysql
class Mysql < Vulcano.resource(1)
name 'mysql'
attr_reader :package, :service, :conf_dir, :conf_path, :data_dir, :log_dir, :log_path, :log_group, :log_dir_group
def initialize
# set OS-dependent filenames and paths
@ -55,9 +57,3 @@ class Mysql
end
end
end
module Serverspec::Type
def mysql
@mysql ||= Mysql.new()
end
end

View file

@ -8,16 +8,17 @@ require 'resources/mysql'
class MysqlConfEntry
def initialize( path, params )
@runner = Specinfra::Runner
@params = params
@path = path
end
def method_missing name, *args
k = name.to_s
res = @params[k]
return true if res.nil? && @params.key?(k)
@params[k]
end
def to_s
group = ' '
group = "[#{@path.join('][')}] " unless @path.nil? or @path.empty?
@ -25,10 +26,10 @@ class MysqlConfEntry
end
end
class MysqlConf < Vulcano::Resource
class MysqlConf < Vulcano.resource(1)
name 'mysql_conf'
def initialize( conf_path )
@runner = Specinfra::Runner
@conf_path = conf_path
@files_contents = {}
@content = nil
@ -59,11 +60,11 @@ class MysqlConf < Vulcano::Resource
@params = {}
# skip if the main configuration file doesn't exist
if !@runner.check_file_is_file(@conf_path)
if !@vulcano.file(@conf_path).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
if raw_conf.empty? && @vulcano.file(@conf_path).size > 0
return skip_resource("Can't read file \"#{@conf_path}\"")
end
@ -91,14 +92,6 @@ class MysqlConf < Vulcano::Resource
end
def read_file(path)
@files_contents[path] ||= @runner.get_file_content(path).stdout
@files_contents[path] ||= @vulcano.file(path).contents
end
end
module Serverspec::Type
def mysql_conf(path = nil)
@mysql_conf ||= {}
dpath = path || mysql.conf_path
@mysql_conf[dpath] ||= MysqlConf.new( dpath )
end
end

View file

@ -4,11 +4,12 @@
$__SCOPE = self
class MysqlSession < Vulcano::Resource
class MysqlSession < Vulcano.resource(1)
name 'mysql_session'
def initialize user, pass
@user = user
@pass = pass
@runner = Specinfra::Runner
initialize_fallback if user.nil? or pass.nil?
skip_resource("Can't run MySQL SQL checks without authentication") if @user.nil? or @pass.nil?
end
@ -33,7 +34,7 @@ class MysqlSession < Vulcano::Resource
def initialize_fallback
# support debian mysql administration login
debian = @runner.run_command("test -f /etc/mysql/debian.cnf && cat /etc/mysql/debian.cnf").stdout
debian = @vulcano.run_command("test -f /etc/mysql/debian.cnf && cat /etc/mysql/debian.cnf").stdout
unless debian.empty?
user = debian.match(/^\s*user\s*=\s*([^ ]*)\s*$/)
pass = debian.match(/^\s*password\s*=\s*([^ ]*)\s*$/)
@ -44,9 +45,3 @@ class MysqlSession < Vulcano::Resource
end
end
end
module Serverspec::Type
def mysql_session( user=nil, password=nil )
MysqlSession.new(user, password)
end
end

View file

@ -13,9 +13,9 @@ require 'vulcano/resource'
# require 'resources/inetd_conf'
# require 'resources/limits_conf'
# require 'resources/login_def'
# require 'resources/mysql'
# require 'resources/mysql_conf'
# require 'resources/mysql_session'
require 'resources/mysql'
require 'resources/mysql_conf'
require 'resources/mysql_session'
require 'resources/ntp_conf'
require 'resources/parse_config'
require 'resources/passwd'