Class: XClarityClient::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/xclarity_client/configuration.rb

Constant Summary collapse

HEADER_MESSAGE =
'XClarityClient::Configuration initialize'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Configuration

Returns a new instance of Configuration.



9
10
11
12
13
14
15
16
17
# File 'lib/xclarity_client/configuration.rb', line 9

def initialize(args)
  args.each { |key, value| send("#{key}=", value) }
  validate_required_params
  validate_auth_type
  validate_port
  validate_timeout

  $lxca_log.info(HEADER_MESSAGE, 'Configuration built successfully')
end

Instance Attribute Details

#auth_typeObject

Returns the value of attribute auth_type.



4
5
6
# File 'lib/xclarity_client/configuration.rb', line 4

def auth_type
  @auth_type
end

#hostObject

Returns the value of attribute host.



4
5
6
# File 'lib/xclarity_client/configuration.rb', line 4

def host
  @host
end

#passwordObject

Returns the value of attribute password.



4
5
6
# File 'lib/xclarity_client/configuration.rb', line 4

def password
  @password
end

#portObject

Returns the value of attribute port.



4
5
6
# File 'lib/xclarity_client/configuration.rb', line 4

def port
  @port
end

#timeoutObject

Returns the value of attribute timeout.



4
5
6
# File 'lib/xclarity_client/configuration.rb', line 4

def timeout
  @timeout
end

#user_agent_labelObject

Returns the value of attribute user_agent_label.



4
5
6
# File 'lib/xclarity_client/configuration.rb', line 4

def user_agent_label
  @user_agent_label
end

#usernameObject

Returns the value of attribute username.



4
5
6
# File 'lib/xclarity_client/configuration.rb', line 4

def username
  @username
end

#verify_sslObject

Returns the value of attribute verify_ssl.



4
5
6
# File 'lib/xclarity_client/configuration.rb', line 4

def verify_ssl
  @verify_ssl
end

Class Method Details

.defaultObject



42
43
44
45
46
47
48
49
50
51
# File 'lib/xclarity_client/configuration.rb', line 42

def self.default
  data = {
    :username   => ENV['LXCA_USERNAME'],
    :password   => ENV['LXCA_PASSWORD'],
    :host       => ENV['LXCA_HOST'],
    :port       => ENV['LXCA_PORT'],
    :verify_ssl => ENV['LXCA_VERIFY_SSL'] != 'NONE'
  }
  new(data)
end

Instance Method Details

#validate_auth_typeObject



36
37
38
39
40
# File 'lib/xclarity_client/configuration.rb', line 36

def validate_auth_type
  msg = 'The auth_type must be a String'
  raise_exception(msg) unless auth_type.kind_of?(String)
  self.auth_type = 'basic_auth' if auth_type.strip.empty?
end

#validate_portObject



19
20
21
22
# File 'lib/xclarity_client/configuration.rb', line 19

def validate_port
  msg = 'The port number and host must be valid'
  raise_exception(msg) unless valid_port?(port) || !host.empty?
end

#validate_required_paramsObject



29
30
31
32
33
34
# File 'lib/xclarity_client/configuration.rb', line 29

def validate_required_params
  required_params = [username, password, host, port, verify_ssl]
  msg = 'The follow params: username, password, host, port and ' \
        'verify_ssl must all be specified'
  raise_exception(msg) if required_params.any?(&:nil?)
end

#validate_timeoutObject



24
25
26
27
# File 'lib/xclarity_client/configuration.rb', line 24

def validate_timeout
  msg = 'the timeout must be in seconds and an Integer'
  raise_exception(msg) unless timeout.kind_of?(Integer) || timeout.nil?
end