Class: Inspec::Resources::OracledbSession
- Inherits:
-
Object
- Object
- Inspec::Resources::OracledbSession
- Defined in:
- lib/inspec/resources/oracledb_session.rb
Overview
STABILITY: Experimental This resource needs further testing and refinement
Instance Attribute Summary collapse
-
#bin ⇒ Object
readonly
Returns the value of attribute bin.
-
#db_role ⇒ Object
readonly
Returns the value of attribute db_role.
-
#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.
-
#service ⇒ Object
readonly
Returns the value of attribute service.
-
#su_user ⇒ Object
readonly
Returns the value of attribute su_user.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ OracledbSession
constructor
A new instance of OracledbSession.
- #query(sql) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ OracledbSession
Returns a new instance of OracledbSession.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/inspec/resources/oracledb_session.rb', line 27 def initialize(opts = {}) @user = opts[:user] @password = opts[:password] || opts[:pass] if opts[:pass] Inspec.deprecate(:oracledb_session_pass_option, "The oracledb_session `pass` option is deprecated. Please use `password`.") end @bin = "sqlplus" @host = opts[:host] || "localhost" @port = opts[:port] || "1521" @service = opts[:service] @su_user = opts[:as_os_user] @db_role = opts[:as_db_role] @sqlcl_bin = opts[:sqlcl_bin] || nil @sqlplus_bin = opts[:sqlplus_bin] || "sqlplus" skip_resource "Option 'as_os_user' not available in Windows" if inspec.os.windows? && su_user fail_resource "Can't run Oracle checks without authentication" unless su_user && (user || password) fail_resource "You must provide a service name for the session" unless service end |
Instance Attribute Details
#bin ⇒ Object (readonly)
Returns the value of attribute bin.
24 25 26 |
# File 'lib/inspec/resources/oracledb_session.rb', line 24 def bin @bin end |
#db_role ⇒ Object (readonly)
Returns the value of attribute db_role.
24 25 26 |
# File 'lib/inspec/resources/oracledb_session.rb', line 24 def db_role @db_role end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
24 25 26 |
# File 'lib/inspec/resources/oracledb_session.rb', line 24 def host @host end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
24 25 26 |
# File 'lib/inspec/resources/oracledb_session.rb', line 24 def password @password end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
24 25 26 |
# File 'lib/inspec/resources/oracledb_session.rb', line 24 def port @port end |
#service ⇒ Object (readonly)
Returns the value of attribute service.
24 25 26 |
# File 'lib/inspec/resources/oracledb_session.rb', line 24 def service @service end |
#su_user ⇒ Object (readonly)
Returns the value of attribute su_user.
24 25 26 |
# File 'lib/inspec/resources/oracledb_session.rb', line 24 def su_user @su_user end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
24 25 26 |
# File 'lib/inspec/resources/oracledb_session.rb', line 24 def user @user end |
Instance Method Details
#query(sql) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/inspec/resources/oracledb_session.rb', line 47 def query(sql) if @sqlcl_bin && inspec.command(@sqlcl_bin).exist? @bin = @sqlcl_bin = "set sqlformat csv\nSET FEEDBACK OFF" parser = :parse_csv_result else @bin = "#{@sqlplus_bin} -S" = "SET MARKUP HTML ON\nSET PAGESIZE 32000\nSET FEEDBACK OFF" parser = :parse_html_result end command = command_builder(, sql) inspec_cmd = inspec.command(command) DatabaseHelper::SQLQueryResult.new(inspec_cmd, send(parser, inspec_cmd.stdout)) end |
#to_s ⇒ Object
65 66 67 |
# File 'lib/inspec/resources/oracledb_session.rb', line 65 def to_s "Oracle Session" end |