Class: Racf::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/racf/client.rb

Overview

That class is intended to be “the” API for clients of the RACF gem. You can use it to open a connection with a mainframe run some RACF commands and then close the connection.

Constant Summary collapse

COMMANDS =
%w(listgrp listuser rlist search)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings = {}) ⇒ Client

Returns a new instance of Client.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/racf/client.rb', line 17

def initialize(settings={})
  settings = Racf.config.merge(settings)

  @user_id         = settings[:user_id]
  @password        = settings[:password]
  @server_address  = settings[:server_address]
  @server_port     = settings[:server_port]
  @script_port     = settings[:script_port]
  @telnet_timeout  = settings[:telnet_timeout]
  @caching         = settings[:caching].nil? ? true : settings[:caching]
  @verbose         = settings[:verbose].nil? ? false : settings[:verbose]

  @session         = settings[:session] || create_session

  load_pagers
end

Instance Attribute Details

#cachingObject

Returns the value of attribute caching.



14
15
16
# File 'lib/racf/client.rb', line 14

def caching
  @caching
end

#passwordObject

Returns the value of attribute password.



14
15
16
# File 'lib/racf/client.rb', line 14

def password
  @password
end

#script_portObject

Returns the value of attribute script_port.



14
15
16
# File 'lib/racf/client.rb', line 14

def script_port
  @script_port
end

#server_addressObject

Returns the value of attribute server_address.



14
15
16
# File 'lib/racf/client.rb', line 14

def server_address
  @server_address
end

#server_portObject

Returns the value of attribute server_port.



14
15
16
# File 'lib/racf/client.rb', line 14

def server_port
  @server_port
end

#sessionObject

Returns the value of attribute session.



14
15
16
# File 'lib/racf/client.rb', line 14

def session
  @session
end

#telnet_timeoutObject

Returns the value of attribute telnet_timeout.



14
15
16
# File 'lib/racf/client.rb', line 14

def telnet_timeout
  @telnet_timeout
end

#user_idObject

Returns the value of attribute user_id.



14
15
16
# File 'lib/racf/client.rb', line 14

def user_id
  @user_id
end

#verboseObject

Returns the value of attribute verbose.



14
15
16
# File 'lib/racf/client.rb', line 14

def verbose
  @verbose
end

Instance Method Details

#cacheObject



90
91
92
93
94
95
96
97
98
99
100
# File 'lib/racf/client.rb', line 90

def cache
  cache_dump = {}

  @pagers.each do |command_class, pager|
    if pager.respond_to? :cache
      cache_dump[command_class.to_s] = pager.cache
    end
  end

  cache_dump
end

#cache=(serialized_cache) ⇒ Object



82
83
84
85
86
87
88
# File 'lib/racf/client.rb', line 82

def cache=(serialized_cache)
  @pagers.each do |command_class, pager|
    if pager.respond_to? :cache=
      pager.cache = serialized_cache[command_class.to_s]
    end
  end
end

#dump_cacheObject



72
73
74
# File 'lib/racf/client.rb', line 72

def dump_cache
  File.open(Racf.dump_file_path, "w") { |f| YAML.dump(cache, f) }
end

#finish_sessionObject



50
51
52
# File 'lib/racf/client.rb', line 50

def finish_session
  session.finish
end

#load_cacheObject



76
77
78
79
80
# File 'lib/racf/client.rb', line 76

def load_cache
  self.cache = YAML.load_file(Racf.dump_file_path)
rescue StandardError
  Racf.logger.warn "Could not load cache file! Running with empty cache."
end

#logger=(logger) ⇒ Object

we should deprecate this api, in favor to config it globally



55
56
57
# File 'lib/racf/client.rb', line 55

def logger=(logger)
  Racf.logger = logger
end

#start_sessionObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/racf/client.rb', line 34

def start_session
  session.start

  if block_given?
    begin
      yield self
    rescue Exception => exception
      Racf.logger.error exception.message
      Racf.logger.error exception.backtrace.join("\n")
      raise
    ensure
      finish_session
    end
  end
end