Class: Inspec::Resources::CassandradbSession

Inherits:
Object
  • Object
show all
Defined in:
lib/inspec/resources/cassandradb_session.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#hostObject (readonly)

Returns the value of attribute host.



28
29
30
# File 'lib/inspec/resources/cassandradb_session.rb', line 28

def host
  @host
end

#passwordObject (readonly)

Returns the value of attribute password.



28
29
30
# File 'lib/inspec/resources/cassandradb_session.rb', line 28

def password
  @password
end

#portObject (readonly)

Returns the value of attribute port.



28
29
30
# File 'lib/inspec/resources/cassandradb_session.rb', line 28

def port
  @port
end

#userObject (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_idObject



48
49
50
# File 'lib/inspec/resources/cassandradb_session.rb', line 48

def resource_id
  "cassandradb_session:User:#{@user}:Host:#{host}"
end

#to_sObject



52
53
54
# File 'lib/inspec/resources/cassandradb_session.rb', line 52

def to_s
  "Cassandra DB Session"
end