Class: EquitracUtilities::Connection

Inherits:
Object
  • Object
show all
Includes:
UserActions
Defined in:
lib/equitrac_utilities/connection.rb

Overview

Note:

You should use environment variables to initialize your server.

The EquitracUtilities, makes it east to work with Equitac EQCmd.exe commands

Since:

  • 0.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from UserActions

#check_atrribs, #process_user_exists?, #user_add, #user_adjust_set, #user_delete, #user_exists?, #user_lock, #user_modify, #user_query, #user_unlock

Constructor Details

#initialize(params = {}) ⇒ Connection

Note:

Hostname, Username and Servicename are required

Make connection to the Equitrac server

Parameters:

  • params (Hash) (defaults to: {})

    The server configuration parameters. Options available ‘:hostname`, `:username`, `:servicename`, `:eqcmd_path`, `:ssh_options`

Raises:

  • (ArgumentError)

Since:

  • 0.1.0



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/equitrac_utilities/connection.rb', line 20

def initialize(params={})
  config = defaults.merge(params)
  @hostname    = config[:hostname]
  @username    = config[:username]
  @servicename = config[:servicename]
  @eqcmd_path  = config[:eqcmd_path]
  @ssh_options = config[:ssh_options]

  raise ArgumentError, 'hostname missing'    if hostname.nil? or hostname.empty?
  raise ArgumentError, 'username missing'    if username.nil? or username.empty?
  raise ArgumentError, 'servicename missing' if servicename.nil? or servicename.empty?
end

Instance Attribute Details

#eqcmd_pathObject (readonly)

Since:

  • 0.1.0



13
14
15
# File 'lib/equitrac_utilities/connection.rb', line 13

def eqcmd_path
  @eqcmd_path
end

#hostnameObject (readonly)

Since:

  • 0.1.0



13
14
15
# File 'lib/equitrac_utilities/connection.rb', line 13

def hostname
  @hostname
end

#servicenameObject (readonly)

Since:

  • 0.1.0



13
14
15
# File 'lib/equitrac_utilities/connection.rb', line 13

def servicename
  @servicename
end

#ssh_optionsObject (readonly)

Since:

  • 0.1.0



13
14
15
# File 'lib/equitrac_utilities/connection.rb', line 13

def ssh_options
  @ssh_options
end

#usernameObject (readonly)

Since:

  • 0.1.0



13
14
15
# File 'lib/equitrac_utilities/connection.rb', line 13

def username
  @username
end

Instance Method Details

#run(command:, attributes:) ⇒ String

Note:

Run a command against the Equitrac server

Returns the restult from the ssh command.

Parameters:

  • command (Symbol)

    choose command to perform these include: :user_query, :user_exists? (t/f), :user_add, :user_delete, :user_lock, :user_unlock, :user_modify

  • attributes (Hash)

    attributes needed to perform command

Returns:

  • (String)

    the restult from the ssh command

Since:

  • 0.1.0



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/equitrac_utilities/connection.rb', line 38

def run(command:, attributes:)
  result = ''
  begin
    action   = send(command, attributes)
    # action   = send(:check_user_id, command, attributes)
    ssh_cmd  = build_full_command(action)
    response = send_eqcmd(ssh_cmd)
    result   = post_processing(command, response)
  rescue ArgumentError, NoMethodError => error
    result   = "#{error.message} -- :#{command} using #{attributes}"
  end
  return result
end