Class: Inspec::Resources::MongodbSession
- Inherits:
-
Object
- Object
- Inspec::Resources::MongodbSession
- Defined in:
- lib/inspec/resources/mongodb_session.rb
Instance Attribute Summary collapse
-
#database ⇒ Object
readonly
Returns the value of attribute database.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ MongodbSession
constructor
A new instance of MongodbSession.
- #query(command) ⇒ Object
- #resource_id ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ MongodbSession
Returns a new instance of MongodbSession.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/inspec/resources/mongodb_session.rb', line 37 def initialize(opts = {}) @user = opts[:user] || nil @password = opts[:password] || nil @host = opts[:host] || "127.0.0.1" @port = opts[:port] || "27017" @database = opts[:database] || nil @auth_mech = opts[:auth_mech] || :scram @auth_source = opts[:auth_source] || @database @ssl = opts[:ssl] || false @ssl_cert = opts[:ssl_cert] || nil @ssl_key = opts[:ssl_key] || nil @ssl_ca_cert = opts[:ssl_ca_cert] || nil @auth_mech_properties = opts[:auth_mech_properties] || {} @client = nil fail_resource "Can't run MongoDB checks without authentication." unless user && @password fail_resource "You must provide a database name for the session." unless database create_session end |
Instance Attribute Details
#database ⇒ Object (readonly)
Returns the value of attribute database.
35 36 37 |
# File 'lib/inspec/resources/mongodb_session.rb', line 35 def database @database end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
35 36 37 |
# File 'lib/inspec/resources/mongodb_session.rb', line 35 def host @host end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
35 36 37 |
# File 'lib/inspec/resources/mongodb_session.rb', line 35 def params @params end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
35 36 37 |
# File 'lib/inspec/resources/mongodb_session.rb', line 35 def port @port end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
35 36 37 |
# File 'lib/inspec/resources/mongodb_session.rb', line 35 def user @user end |
Instance Method Details
#query(command) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/inspec/resources/mongodb_session.rb', line 58 def query(command) raise Inspec::Exceptions::ResourceFailed, "#{}" if resource_failed? Lines.new(@client.command(command).documents.first, "MongoDB query: #{command}") rescue => e raise Inspec::Exceptions::ResourceFailed, "Can't run MongoDB command Error: #{e.}" end |
#resource_id ⇒ Object
66 67 68 |
# File 'lib/inspec/resources/mongodb_session.rb', line 66 def resource_id "mongodb_session:User:#{@user}:Host:#{@host}:Database:#{@database}" end |