Class: Inspec::Resources::MysqlSession
- Inherits:
-
Object
- Object
- Inspec::Resources::MysqlSession
- Defined in:
- lib/inspec/resources/mysql_session.rb
Instance Method Summary collapse
-
#initialize(user = nil, pass = nil, host = "localhost", port = nil, socket = nil) ⇒ MysqlSession
constructor
A new instance of MysqlSession.
- #query(q, db = "") ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(user = nil, pass = nil, host = "localhost", port = nil, socket = nil) ⇒ MysqlSession
Returns a new instance of MysqlSession.
19 20 21 22 23 24 25 26 27 |
# File 'lib/inspec/resources/mysql_session.rb', line 19 def initialize(user = nil, pass = nil, host = "localhost", port = nil, socket = nil) @user = user @pass = pass @host = host @port = port @socket = socket init_fallback if user.nil? || pass.nil? skip_resource("Can't run MySQL SQL checks without authentication") if @user.nil? || @pass.nil? end |
Instance Method Details
#query(q, db = "") ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/inspec/resources/mysql_session.rb', line 29 def query(q, db = "") mysql_cmd = create_mysql_cmd(q, db) cmd = inspec.command(mysql_cmd) out = cmd.stdout + "\n" + cmd.stderr if out =~ /Can't connect to .* MySQL server/ || out.downcase =~ /^error / # skip this test if the server can't run the query warn("Can't connect to MySQL instance for SQL checks.") end # return the raw command output cmd end |
#to_s ⇒ Object
42 43 44 |
# File 'lib/inspec/resources/mysql_session.rb', line 42 def to_s "MySQL Session" end |