Class: Zm::Client::ClusterConfig
- Inherits:
-
Object
- Object
- Zm::Client::ClusterConfig
- Includes:
- ZmLogger
- Defined in:
- lib/zm/client/cluster/cluster_config.rb
Overview
class config for cluster connection
Instance Attribute Summary collapse
-
#domains ⇒ Object
Returns the value of attribute domains.
-
#to_h ⇒ Object
readonly
Returns the value of attribute to_h.
-
#zimbra_admin_host ⇒ Object
Returns the value of attribute zimbra_admin_host.
-
#zimbra_admin_login ⇒ Object
Returns the value of attribute zimbra_admin_login.
-
#zimbra_admin_password ⇒ Object
Returns the value of attribute zimbra_admin_password.
-
#zimbra_admin_port ⇒ Object
Returns the value of attribute zimbra_admin_port.
-
#zimbra_admin_scheme ⇒ Object
Returns the value of attribute zimbra_admin_scheme.
-
#zimbra_public_host ⇒ Object
Returns the value of attribute zimbra_public_host.
-
#zimbra_public_port ⇒ Object
Returns the value of attribute zimbra_public_port.
-
#zimbra_public_scheme ⇒ Object
Returns the value of attribute zimbra_public_scheme.
-
#zimbra_version ⇒ Object
Returns the value of attribute zimbra_version.
Attributes included from ZmLogger
#logger, #logger_file_path, #logger_level
Instance Method Summary collapse
- #domain_key(domain_name) ⇒ Object
- #find_domain(domain_name) ⇒ Object
- #has_admin_credentials? ⇒ Boolean
- #init_from_file(file_config_path) ⇒ Object
- #init_from_h ⇒ Object
- #init_from_json(file_config_path) ⇒ Object
- #init_from_yml(file_config_path) ⇒ Object
-
#initialize(parameters = nil) {|_self| ... } ⇒ ClusterConfig
constructor
A new instance of ClusterConfig.
- #make_config_domain ⇒ Object
- #zimbra_attributes_path ⇒ Object
- #zimbra_attributes_path=(path) ⇒ Object
Methods included from ZmLogger
Constructor Details
#initialize(parameters = nil) {|_self| ... } ⇒ ClusterConfig
Returns a new instance of ClusterConfig.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/zm/client/cluster/cluster_config.rb', line 16 def initialize(parameters = nil) @domains = [] @zimbra_version = '8.8.15' case parameters when String init_from_file(parameters) when Hash @to_h = parameters end unless @to_h.nil? init_from_h make_config_domain end yield(self) if block_given? end |
Instance Attribute Details
#domains ⇒ Object
Returns the value of attribute domains.
12 13 14 |
# File 'lib/zm/client/cluster/cluster_config.rb', line 12 def domains @domains end |
#to_h ⇒ Object (readonly)
Returns the value of attribute to_h.
11 12 13 |
# File 'lib/zm/client/cluster/cluster_config.rb', line 11 def to_h @to_h end |
#zimbra_admin_host ⇒ Object
Returns the value of attribute zimbra_admin_host.
12 13 14 |
# File 'lib/zm/client/cluster/cluster_config.rb', line 12 def zimbra_admin_host @zimbra_admin_host end |
#zimbra_admin_login ⇒ Object
Returns the value of attribute zimbra_admin_login.
12 13 14 |
# File 'lib/zm/client/cluster/cluster_config.rb', line 12 def zimbra_admin_login @zimbra_admin_login end |
#zimbra_admin_password ⇒ Object
Returns the value of attribute zimbra_admin_password.
12 13 14 |
# File 'lib/zm/client/cluster/cluster_config.rb', line 12 def zimbra_admin_password @zimbra_admin_password end |
#zimbra_admin_port ⇒ Object
Returns the value of attribute zimbra_admin_port.
12 13 14 |
# File 'lib/zm/client/cluster/cluster_config.rb', line 12 def zimbra_admin_port @zimbra_admin_port end |
#zimbra_admin_scheme ⇒ Object
Returns the value of attribute zimbra_admin_scheme.
12 13 14 |
# File 'lib/zm/client/cluster/cluster_config.rb', line 12 def zimbra_admin_scheme @zimbra_admin_scheme end |
#zimbra_public_host ⇒ Object
Returns the value of attribute zimbra_public_host.
12 13 14 |
# File 'lib/zm/client/cluster/cluster_config.rb', line 12 def zimbra_public_host @zimbra_public_host end |
#zimbra_public_port ⇒ Object
Returns the value of attribute zimbra_public_port.
12 13 14 |
# File 'lib/zm/client/cluster/cluster_config.rb', line 12 def zimbra_public_port @zimbra_public_port end |
#zimbra_public_scheme ⇒ Object
Returns the value of attribute zimbra_public_scheme.
12 13 14 |
# File 'lib/zm/client/cluster/cluster_config.rb', line 12 def zimbra_public_scheme @zimbra_public_scheme end |
#zimbra_version ⇒ Object
Returns the value of attribute zimbra_version.
12 13 14 |
# File 'lib/zm/client/cluster/cluster_config.rb', line 12 def zimbra_version @zimbra_version end |
Instance Method Details
#domain_key(domain_name) ⇒ Object
77 78 79 80 81 82 |
# File 'lib/zm/client/cluster/cluster_config.rb', line 77 def domain_key(domain_name) domain = find_domain(domain_name) return nil if domain.nil? domain.key end |
#find_domain(domain_name) ⇒ Object
73 74 75 |
# File 'lib/zm/client/cluster/cluster_config.rb', line 73 def find_domain(domain_name) @domains.find { |d| d.name == domain_name } end |
#has_admin_credentials? ⇒ Boolean
84 85 86 |
# File 'lib/zm/client/cluster/cluster_config.rb', line 84 def has_admin_credentials? !@zimbra_admin_host.nil? && !@zimbra_admin_login.nil? && !@zimbra_admin_password.nil? end |
#init_from_file(file_config_path) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/zm/client/cluster/cluster_config.rb', line 35 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 ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/zm/client/cluster/cluster_config.rb', line 45 def init_from_h @zimbra_admin_host = @to_h.fetch(:zimbra_admin_host, nil) @zimbra_admin_scheme = @to_h.fetch(:zimbra_admin_scheme, 'https') @zimbra_admin_port = @to_h.fetch(:zimbra_admin_port, 7071) @zimbra_admin_login = @to_h.fetch(:zimbra_admin_login, nil) @zimbra_admin_password = @to_h.fetch(:zimbra_admin_password, nil) @zimbra_public_host = @to_h.fetch(:zimbra_public_host, nil) @zimbra_public_scheme = @to_h.fetch(:zimbra_public_scheme, 'https') @zimbra_public_port = @to_h.fetch(:zimbra_public_port, 443) @zimbra_version = @to_h.fetch(:zimbra_version, @zimbra_version) end |
#init_from_json(file_config_path) ⇒ Object
61 62 63 |
# File 'lib/zm/client/cluster/cluster_config.rb', line 61 def init_from_json(file_config_path) @to_h = JSON.parse(File.read(file_config_path), symbolize_names: true) end |
#init_from_yml(file_config_path) ⇒ Object
57 58 59 |
# File 'lib/zm/client/cluster/cluster_config.rb', line 57 def init_from_yml(file_config_path) @to_h = YAML.safe_load(File.read(file_config_path), symbolize_names: true) end |
#make_config_domain ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/zm/client/cluster/cluster_config.rb', line 65 def make_config_domain return if @to_h[:domains].nil? @domains = @to_h[:domains].map do |h| ClusterConfigDomain.new(h[:name], h[:key]) end end |
#zimbra_attributes_path ⇒ Object
88 89 90 |
# File 'lib/zm/client/cluster/cluster_config.rb', line 88 def zimbra_attributes_path @zimbra_attributes_path ||= "#{File.dirname(__FILE__)}../../../modules/common/zimbra-attrs.csv" end |
#zimbra_attributes_path=(path) ⇒ Object
92 93 94 95 96 |
# File 'lib/zm/client/cluster/cluster_config.rb', line 92 def zimbra_attributes_path=(path) raise ClusterConfigError, 'no valid attributes file' unless File.exist?(path) @zimbra_attributes_path = path end |