Method: Inspec::Resources::OracledbSession#initialize

Defined in:
lib/resources/oracledb_session.rb

#initialize(opts = {}) ⇒ OracledbSession

rubocop:disable Metrics/PerceivedComplexity,Metrics/CyclomaticComplexity



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/resources/oracledb_session.rb', line 27

def initialize(opts = {})
  @user = opts[:user]
  @password = opts[:password] || opts[:pass]
  if opts[:pass]
    warn '[DEPRECATED] use `password` option to supply password instead of `pass`'
  end

  @host = opts[:host] || 'localhost'
  @port = opts[:port] || '1521'
  @service = opts[:service]

  # connection as sysdba stuff
  return skip_resource "Option 'as_os_user' not available in Windows" if inspec.os.windows? && opts[:as_os_user]
  @su_user = opts[:as_os_user]
  @db_role = opts[:as_db_role]

  # we prefer sqlci although it is way slower than sqlplus, but it understands csv properly
  @sqlcl_bin = 'sql' unless opts.key?(:sqlplus_bin) # don't use it if user specified sqlplus_bin option
  @sqlplus_bin = opts[:sqlplus_bin] || 'sqlplus'

  return fail_resource "Can't run Oracle checks without authentication" if @su_user.nil? && (@user.nil? || @password.nil?)
  return fail_resource 'You must provide a service name for the session' if @service.nil?
end