Method: Inspec::Resources::MssqlSession#initialize

Defined in:
lib/resources/mssql_session.rb

#initialize(opts = {}) ⇒ MssqlSession

Returns a new instance of MssqlSession.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/resources/mssql_session.rb', line 33

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
  @local_mode = opts[:local_mode]
  unless local_mode?
    @host = opts[:host] || 'localhost'
    if opts.key?(:port)
      @port = opts[:port]
    else
      @port = '1433'
    end
  end
  @instance = opts[:instance]
  @db_name = opts[:db_name]

  # check if sqlcmd is available
  raise Inspec::Exceptions::ResourceSkipped, 'sqlcmd is missing' unless inspec.command('sqlcmd').exist?
  # check that database is reachable
  raise Inspec::Exceptions::ResourceSkipped, "Can't connect to the MS SQL Server." unless test_connection
end