Class: Zm::Client::ClusterConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/zm/client/cluster/cluster_config.rb

Overview

class config for cluster connection

Constant Summary collapse

BASE_URL_REGEX =
%r{\A(https?://[^/?#]+).*}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parameters = nil) {|_self| ... } ⇒ ClusterConfig

Returns a new instance of ClusterConfig.

Yields:

  • (_self)

Yield Parameters:



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/zm/client/cluster/cluster_config.rb', line 16

def initialize(parameters = nil)
  @domains = []
  @zimbra_version = '8.8.15'
  @log_path = $stdout
  @log_level = Logger::INFO
  @colorize_logging = false
  @timeout = 300

  init_from_parameters(parameters)

  yield(self) if block_given?
end

Instance Attribute Details

#colorize_logging=(value) ⇒ Object (writeonly)

Sets the attribute colorize_logging

Parameters:

  • value

    the value to set the attribute colorize_logging to.



12
13
14
# File 'lib/zm/client/cluster/cluster_config.rb', line 12

def colorize_logging=(value)
  @colorize_logging = value
end

#domainsObject

Returns the value of attribute domains.



13
14
15
# File 'lib/zm/client/cluster/cluster_config.rb', line 13

def domains
  @domains
end

#log_pathObject

Returns the value of attribute log_path.



13
14
15
# File 'lib/zm/client/cluster/cluster_config.rb', line 13

def log_path
  @log_path
end

#loggerObject



179
180
181
182
183
184
185
186
# File 'lib/zm/client/cluster/cluster_config.rb', line 179

def logger
  return @logger if defined? @logger

  @logger = ZmLogger.new(@log_path).tap do |log|
    log.level = @log_level
    log.colorize! if @colorize_logging
  end
end

#timeoutObject

Returns the value of attribute timeout.



13
14
15
# File 'lib/zm/client/cluster/cluster_config.rb', line 13

def timeout
  @timeout
end

#zimbra_admin_loginObject

Returns the value of attribute zimbra_admin_login.



13
14
15
# File 'lib/zm/client/cluster/cluster_config.rb', line 13

def 
  
end

#zimbra_admin_passwordObject

Returns the value of attribute zimbra_admin_password.



13
14
15
# File 'lib/zm/client/cluster/cluster_config.rb', line 13

def zimbra_admin_password
  @zimbra_admin_password
end

#zimbra_admin_urlObject

Returns the value of attribute zimbra_admin_url.



11
12
13
# File 'lib/zm/client/cluster/cluster_config.rb', line 11

def zimbra_admin_url
  @zimbra_admin_url
end

#zimbra_public_urlObject

Returns the value of attribute zimbra_public_url.



11
12
13
# File 'lib/zm/client/cluster/cluster_config.rb', line 11

def zimbra_public_url
  @zimbra_public_url
end

#zimbra_versionObject

Returns the value of attribute zimbra_version.



13
14
15
# File 'lib/zm/client/cluster/cluster_config.rb', line 13

def zimbra_version
  @zimbra_version
end

Instance Method Details

#cacheObject



29
30
31
32
33
34
35
# File 'lib/zm/client/cluster/cluster_config.rb', line 29

def cache
  @cache = Zm::Support::Cache.registered_storage[cache_store_key]
                             .new(**cache_store_options)
                             .tap do |store|
                               store.logger = logger
                             end
end

#cache_storeObject



45
46
47
# File 'lib/zm/client/cluster/cluster_config.rb', line 45

def cache_store
  @cache_store ||= [:null_store, {}]
end

#cache_store=(options) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/zm/client/cluster/cluster_config.rb', line 49

def cache_store=(options)
  store_key = options.shift
  store_options = options.last
  store_class = Zm::Support::Cache.registered_storage[store_key]

  unless store_class || store_class.test_required_options(store_options)
    raise ClusterConfigError, 'invalid cache_store'
  end

  @cache_store = [store_key, store_options]
end

#cache_store_keyObject



37
38
39
# File 'lib/zm/client/cluster/cluster_config.rb', line 37

def cache_store_key
  cache_store.first
end

#cache_store_optionsObject



41
42
43
# File 'lib/zm/client/cluster/cluster_config.rb', line 41

def cache_store_options
  cache_store.last
end

#domain_key(domain_name) ⇒ Object



158
159
160
161
162
163
# File 'lib/zm/client/cluster/cluster_config.rb', line 158

def domain_key(domain_name)
  domain = find_domain(domain_name)
  return nil if domain.nil?

  domain.key
end

#find_domain(domain_name) ⇒ Object



154
155
156
# File 'lib/zm/client/cluster/cluster_config.rb', line 154

def find_domain(domain_name)
  @domains.find { |d| d.name == domain_name }
end

#has_admin_credentials?Boolean

Returns:

  • (Boolean)


165
166
167
# File 'lib/zm/client/cluster/cluster_config.rb', line 165

def has_admin_credentials?
  !@zimbra_admin_url.nil? && !.nil? && !@zimbra_admin_password.nil?
end

#init_admin_url_from_parameters(parameters) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
# File 'lib/zm/client/cluster/cluster_config.rb', line 126

def init_admin_url_from_parameters(parameters)
  if (url = parameters.delete(:zimbra_admin_url))
    self.zimbra_admin_url = url
  else
    scheme = parameters.delete(:zimbra_admin_scheme) || 'https'
    host = parameters.delete(:zimbra_admin_host)
    port = parameters.delete(:zimbra_admin_port) || 7071

    self.zimbra_admin_url = "#{scheme}://#{host}:#{port}"
  end
end

#init_domains_from_parameters(parameters) ⇒ Object



107
108
109
110
111
112
113
# File 'lib/zm/client/cluster/cluster_config.rb', line 107

def init_domains_from_parameters(parameters)
  if (config_domains = parameters.delete(:domains))
    @domains = config_domains.map do |h|
      ClusterConfigDomain.new(h[:name], h[:key])
    end
  end
end

#init_from_file(file_config_path) ⇒ Object



70
71
72
73
74
75
76
77
78
# File 'lib/zm/client/cluster/cluster_config.rb', line 70

def init_from_file(file_config_path)
  if file_config_path.end_with?('.json')
    init_from_json(file_config_path)
  elsif file_config_path.end_with?('.yml', '.yaml')
    init_from_yml(file_config_path)
  else
    raise ClusterConfigError, 'no valid config file extension'
  end
end

#init_from_h(parameters) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/zm/client/cluster/cluster_config.rb', line 88

def init_from_h(parameters)
   = parameters.delete(:zimbra_admin_login)
  @zimbra_admin_password = parameters.delete(:zimbra_admin_password)

  init_admin_url_from_parameters(parameters)

  init_public_url_from_parameters(parameters)

  if (version = parameters.delete(:zimbra_version))
    @zimbra_version = version
  end

  if (p_timeout = parameters.delete(:timeout))
    @timeout = p_timeout.to_i
  end

  init_domains_from_parameters(parameters)
end

#init_from_json(file_config_path) ⇒ Object



84
85
86
# File 'lib/zm/client/cluster/cluster_config.rb', line 84

def init_from_json(file_config_path)
  JSON.parse(File.read(file_config_path), symbolize_names: true)
end

#init_from_parameters(parameters) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/zm/client/cluster/cluster_config.rb', line 61

def init_from_parameters(parameters)
  case parameters
  when String
    init_from_h(init_from_file(parameters))
  when Hash
    init_from_h(parameters)
  end
end

#init_from_yml(file_config_path) ⇒ Object



80
81
82
# File 'lib/zm/client/cluster/cluster_config.rb', line 80

def init_from_yml(file_config_path)
  YAML.safe_load_file(file_config_path, symbolize_names: true)
end

#init_public_url_from_parameters(parameters) ⇒ Object



115
116
117
118
119
120
121
122
123
124
# File 'lib/zm/client/cluster/cluster_config.rb', line 115

def init_public_url_from_parameters(parameters)
  if (url = parameters.delete(:zimbra_public_url))
    self.zimbra_public_url = url
  elsif (host = parameters.delete(:zimbra_public_host))
    scheme = parameters.delete(:zimbra_public_scheme) || 'https'
    port = parameters.delete(:zimbra_public_port) || 443

    self.zimbra_public_url = "#{scheme}://#{host}:#{port}"
  end
end

#log_level=(level) ⇒ Object



188
189
190
191
192
# File 'lib/zm/client/cluster/cluster_config.rb', line 188

def log_level=(level)
  return if level == @log_level

  logger.level = @log_level = level
end

#zimbra_attributes_pathObject



169
170
171
# File 'lib/zm/client/cluster/cluster_config.rb', line 169

def zimbra_attributes_path
  @zimbra_attributes_path ||= "#{File.dirname(__FILE__)}../../../modules/common/zimbra-attrs.csv"
end

#zimbra_attributes_path=(path) ⇒ Object

Raises:



173
174
175
176
177
# File 'lib/zm/client/cluster/cluster_config.rb', line 173

def zimbra_attributes_path=(path)
  raise ClusterConfigError, 'no valid attributes file' unless File.exist?(path)

  @zimbra_attributes_path = path
end