Class: Inspec::Resources::CassandradbSession
- Inherits:
-
Object
- Object
- Inspec::Resources::CassandradbSession
- Defined in:
- lib/inspec/resources/cassandradb_session.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ CassandradbSession
constructor
A new instance of CassandradbSession.
- #query(q) ⇒ Object
- #resource_id ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ CassandradbSession
Returns a new instance of CassandradbSession.
30 31 32 33 34 35 |
# File 'lib/inspec/resources/cassandradb_session.rb', line 30 def initialize(opts = {}) @user = opts[:user] || "cassandra" @password = opts[:password] || "cassandra" @host = opts[:host] @port = opts[:port] end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
28 29 30 |
# File 'lib/inspec/resources/cassandradb_session.rb', line 28 def host @host end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
28 29 30 |
# File 'lib/inspec/resources/cassandradb_session.rb', line 28 def password @password end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
28 29 30 |
# File 'lib/inspec/resources/cassandradb_session.rb', line 28 def port @port end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
28 29 30 |
# File 'lib/inspec/resources/cassandradb_session.rb', line 28 def user @user end |
Instance Method Details
#query(q) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/inspec/resources/cassandradb_session.rb', line 37 def query(q) cassandra_cmd = create_cassandra_cmd(q) cmd = inspec.command(cassandra_cmd) out = cmd.stdout + "\n" + cmd.stderr if cmd.exit_status != 0 || out =~ /Unable to connect to any servers/ || out.downcase =~ /^error:.*/ raise Inspec::Exceptions::ResourceFailed, "Cassandra query with errors: #{out}" else Lines.new(cmd.stdout.strip, "Cassandra query: #{q}", cmd.exit_status) end end |
#resource_id ⇒ Object
48 49 50 |
# File 'lib/inspec/resources/cassandradb_session.rb', line 48 def resource_id "cassandradb_session:User:#{@user}:Host:#{host}" end |
#to_s ⇒ Object
52 53 54 |
# File 'lib/inspec/resources/cassandradb_session.rb', line 52 def to_s "Cassandra DB Session" end |