zm-ruby-client 2.2.7 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +6 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +10 -6
- data/Gemfile +1 -6
- data/README.md +10 -15
- data/VERSION +1 -1
- data/lib/zm/client/account/account.rb +35 -22
- data/lib/zm/client/account/account_aliases_collection.rb +14 -6
- data/lib/zm/client/account/account_dls_membership_collection.rb +10 -4
- data/lib/zm/client/account/account_dls_owner_collection.rb +8 -5
- data/lib/zm/client/account/account_jsns_builder.rb +31 -19
- data/lib/zm/client/account/account_jsns_initializer.rb +4 -14
- data/lib/zm/client/account/accounts_builder.rb +1 -1
- data/lib/zm/client/account/accounts_collection.rb +15 -8
- data/lib/zm/client/ace/ace.rb +5 -5
- data/lib/zm/client/ace/ace_jsns_builder.rb +8 -8
- data/lib/zm/client/ace/ace_jsns_initializer.rb +7 -7
- data/lib/zm/client/ace/aces_builder.rb +1 -1
- data/lib/zm/client/ace/aces_collection.rb +2 -2
- data/lib/zm/client/appointment/appointment.rb +27 -24
- data/lib/zm/client/appointment/appointment_jsns_builder.rb +29 -20
- data/lib/zm/client/appointment/appointment_jsns_initializer.rb +14 -13
- data/lib/zm/client/appointment/appointments_builder.rb +1 -1
- data/lib/zm/client/appointment/appointments_collection.rb +8 -7
- data/lib/zm/client/backup/backup.rb +6 -2
- data/lib/zm/client/backup/backup_jsns_initializer.rb +14 -12
- data/lib/zm/client/backup/backups_builder.rb +1 -1
- data/lib/zm/client/backup/backups_collection.rb +2 -1
- data/lib/zm/client/base/account_search_objects_collection.rb +46 -20
- data/lib/zm/client/base/admin_objects_collection.rb +22 -27
- data/lib/zm/client/base/base_account_jsns_builder.rb +1 -4
- data/lib/zm/client/base/base_jsns_initializer.rb +8 -8
- data/lib/zm/client/base/mailbox_infos_collection.rb +23 -15
- data/lib/zm/client/base/mailbox_object.rb +174 -69
- data/lib/zm/client/base/mailbox_prefs_collection.rb +4 -8
- data/lib/zm/client/base/object.rb +2 -2
- data/lib/zm/client/base/objects_builder.rb +7 -3
- data/lib/zm/client/base/objects_collection.rb +4 -13
- data/lib/zm/client/base/zimbra_attribute.rb +4 -17
- data/lib/zm/client/base/zimbra_attributes_collection.rb +16 -9
- data/lib/zm/client/base.rb +0 -1
- data/lib/zm/client/cluster/batch_request.rb +50 -0
- data/lib/zm/client/cluster/cluster.rb +49 -27
- data/lib/zm/client/cluster/cluster_config.rb +129 -40
- data/lib/zm/client/common/recipients.rb +2 -2
- data/lib/zm/client/common/utils.rb +1 -13
- data/lib/zm/client/common.rb +0 -1
- data/lib/zm/client/connector/{rest_account.rb → rest_connector.rb} +40 -50
- data/lib/zm/client/connector/soap_account.rb +19 -15
- data/lib/zm/client/connector/soap_admin.rb +9 -9
- data/lib/zm/client/connector/soap_base.rb +24 -17
- data/lib/zm/client/connector/soap_error.rb +3 -23
- data/lib/zm/client/constant.rb +18 -16
- data/lib/zm/client/contact/contact.rb +21 -40
- data/lib/zm/client/contact/contact_jsns_builder.rb +1 -1
- data/lib/zm/client/contact/contact_jsns_initializer.rb +4 -26
- data/lib/zm/client/contact/contacts_builder.rb +1 -1
- data/lib/zm/client/contact/contacts_collection.rb +4 -24
- data/lib/zm/client/contact/group_contact_jsns_builder.rb +18 -13
- data/lib/zm/client/contact/mod_group_contact.rb +6 -2
- data/lib/zm/client/cos/cos.rb +35 -11
- data/lib/zm/client/cos/cos_domains_collection.rb +1 -1
- data/lib/zm/client/cos/cos_jsns_builder.rb +22 -9
- data/lib/zm/client/cos/cos_jsns_initializer.rb +2 -6
- data/lib/zm/client/cos/cos_servers_collection.rb +5 -6
- data/lib/zm/client/cos/coses_builder.rb +1 -1
- data/lib/zm/client/cos/coses_collection.rb +6 -4
- data/lib/zm/client/datasource/datasource.rb +27 -34
- data/lib/zm/client/datasource/datasource_jsns_builder.rb +1 -1
- data/lib/zm/client/datasource/datasource_jsns_initializer.rb +5 -6
- data/lib/zm/client/datasource/datasources_builder.rb +6 -9
- data/lib/zm/client/datasource/datasources_collection.rb +6 -5
- data/lib/zm/client/distributionlist/distributionlist.rb +22 -42
- data/lib/zm/client/distributionlist/distributionlist_aliases_collection.rb +14 -6
- data/lib/zm/client/distributionlist/distributionlist_jsns_builder.rb +20 -16
- data/lib/zm/client/distributionlist/distributionlist_jsns_initializer.rb +2 -11
- data/lib/zm/client/distributionlist/distributionlist_members_collection.rb +20 -12
- data/lib/zm/client/distributionlist/distributionlist_owners_collection.rb +16 -5
- data/lib/zm/client/distributionlist/distributionlists_builder.rb +1 -1
- data/lib/zm/client/distributionlist/distributionlists_collection.rb +12 -6
- data/lib/zm/client/distributionlist/dls_membership_collection.rb +12 -6
- data/lib/zm/client/document/document.rb +16 -8
- data/lib/zm/client/document/document_jsns_builder.rb +1 -1
- data/lib/zm/client/document/document_jsns_initializer.rb +27 -26
- data/lib/zm/client/document/documents_builder.rb +1 -1
- data/lib/zm/client/document/documents_collection.rb +1 -1
- data/lib/zm/client/domain/domain.rb +18 -37
- data/lib/zm/client/domain/domain_accounts_collection.rb +1 -1
- data/lib/zm/client/domain/domain_distributionlists_collection.rb +1 -1
- data/lib/zm/client/domain/domain_jsns_builder.rb +18 -9
- data/lib/zm/client/domain/domain_jsns_initializer.rb +2 -6
- data/lib/zm/client/domain/domain_resources_collection.rb +1 -1
- data/lib/zm/client/domain/domains_builder.rb +1 -1
- data/lib/zm/client/domain/domains_collection.rb +12 -6
- data/lib/zm/client/filter_rules/filter_rule.rb +0 -9
- data/lib/zm/client/filter_rules/filter_rule_jsns_initializer.rb +7 -6
- data/lib/zm/client/filter_rules/filter_rules_builder.rb +1 -1
- data/lib/zm/client/filter_rules/filter_rules_collection.rb +5 -15
- data/lib/zm/client/filter_rules/outgoing_filter_rules_collection.rb +5 -2
- data/lib/zm/client/folder/folder.rb +73 -56
- data/lib/zm/client/folder/folder_grant.rb +7 -5
- data/lib/zm/client/folder/folder_grant_jsns_builder.rb +6 -3
- data/lib/zm/client/folder/folder_grants_collection.rb +2 -4
- data/lib/zm/client/folder/folder_jsns_builder.rb +14 -7
- data/lib/zm/client/folder/folder_jsns_initializer.rb +58 -40
- data/lib/zm/client/folder/folder_retention_policies_collection.rb +4 -2
- data/lib/zm/client/folder/folders_builder.rb +1 -1
- data/lib/zm/client/folder/folders_collection.rb +21 -18
- data/lib/zm/client/folder/folders_jsns_builder.rb +4 -2
- data/lib/zm/client/folder/mod_document_folder.rb +5 -4
- data/lib/zm/client/identity/identities_builder.rb +1 -1
- data/lib/zm/client/identity/identities_collection.rb +6 -5
- data/lib/zm/client/identity/identity.rb +9 -29
- data/lib/zm/client/identity/identity_jsns_builder.rb +8 -4
- data/lib/zm/client/identity/identity_jsns_initializer.rb +5 -4
- data/lib/zm/client/license/license.rb +7 -1
- data/lib/zm/client/license/license_jsns_initializer.rb +8 -5
- data/lib/zm/client/license/licenses_collection.rb +1 -1
- data/lib/zm/client/mailbox/mailbox_item_concern.rb +33 -0
- data/lib/zm/client/mailbox/mailbox_item_id.rb +7 -0
- data/lib/zm/client/message/attachments_collection.rb +2 -2
- data/lib/zm/client/message/message.rb +56 -52
- data/lib/zm/client/message/message_flags.rb +21 -13
- data/lib/zm/client/message/message_jsns_builder.rb +11 -6
- data/lib/zm/client/message/message_jsns_initializer.rb +24 -23
- data/lib/zm/client/message/messages_builder.rb +1 -1
- data/lib/zm/client/message/messages_collection.rb +1 -15
- data/lib/zm/client/mountpoint/mountpoint.rb +17 -25
- data/lib/zm/client/mountpoint/mountpoint_jsns_builder.rb +6 -3
- data/lib/zm/client/mountpoint/mountpoint_jsns_initializer.rb +25 -24
- data/lib/zm/client/mountpoint/mountpoints_builder.rb +1 -1
- data/lib/zm/client/mountpoint/mountpoints_collection.rb +13 -9
- data/lib/zm/client/mta_queue/mta_queue.rb +6 -2
- data/lib/zm/client/mta_queue/mta_queue_jsns_initializer.rb +3 -7
- data/lib/zm/client/mta_queue/mta_queues_builder.rb +3 -1
- data/lib/zm/client/mta_queue_item/mta_queue_item.rb +5 -3
- data/lib/zm/client/mta_queue_item/mta_queue_item_jsns_initializer.rb +1 -5
- data/lib/zm/client/mta_queue_item/mta_queue_items_builder.rb +3 -1
- data/lib/zm/client/mta_queue_item/mta_queue_items_collection.rb +3 -1
- data/lib/zm/client/resource/resource.rb +6 -18
- data/lib/zm/client/resource/resource_jsns_builder.rb +20 -13
- data/lib/zm/client/resource/resource_jsns_initializer.rb +4 -14
- data/lib/zm/client/resource/resources_builder.rb +1 -1
- data/lib/zm/client/resource/resources_collection.rb +12 -7
- data/lib/zm/client/search_folder/search_folder.rb +13 -29
- data/lib/zm/client/search_folder/search_folder_jsns_builder.rb +6 -6
- data/lib/zm/client/search_folder/search_folder_jsns_initializer.rb +19 -18
- data/lib/zm/client/search_folder/search_folders_builder.rb +1 -1
- data/lib/zm/client/search_folder/search_folders_collection.rb +6 -5
- data/lib/zm/client/server/server.rb +9 -3
- data/lib/zm/client/server/server_accounts_collection.rb +4 -2
- data/lib/zm/client/server/server_jsns_initializer.rb +1 -5
- data/lib/zm/client/server/servers_builder.rb +1 -1
- data/lib/zm/client/server/servers_collection.rb +17 -9
- data/lib/zm/client/share/share.rb +5 -3
- data/lib/zm/client/share/share_jsns_initializer.rb +15 -14
- data/lib/zm/client/share/share_mountpoints_collection.rb +3 -6
- data/lib/zm/client/share/shares_builder.rb +1 -1
- data/lib/zm/client/share/shares_collection.rb +6 -3
- data/lib/zm/client/signature/signature.rb +6 -21
- data/lib/zm/client/signature/signature_jsns_builder.rb +12 -7
- data/lib/zm/client/signature/signature_jsns_initializer.rb +5 -4
- data/lib/zm/client/signature/signatures_builder.rb +1 -1
- data/lib/zm/client/signature/signatures_collection.rb +6 -5
- data/lib/zm/client/soap_request/request_methods_admin.rb +56 -0
- data/lib/zm/client/soap_request/request_methods_mailbox.rb +60 -0
- data/lib/zm/client/soap_request/soap_constants.rb +7 -0
- data/lib/zm/client/soap_request/soap_context.rb +11 -2
- data/lib/zm/client/soap_request.rb +3 -0
- data/lib/zm/client/tag/account_object_tags_collection.rb +11 -9
- data/lib/zm/client/tag/tag.rb +8 -44
- data/lib/zm/client/tag/tag_jsns_builder.rb +4 -2
- data/lib/zm/client/tag/tag_jsns_initializer.rb +7 -6
- data/lib/zm/client/tag/tags_builder.rb +1 -1
- data/lib/zm/client/tag/tags_collection.rb +6 -5
- data/lib/zm/client/task/task.rb +6 -5
- data/lib/zm/client/task/task_jsns_initializer.rb +28 -27
- data/lib/zm/client/task/tasks_builder.rb +1 -1
- data/lib/zm/client/task/tasks_collection.rb +2 -2
- data/lib/zm/client/token.rb +52 -0
- data/lib/zm/client/upload/upload.rb +101 -95
- data/lib/zm/client/zm_logger.rb +83 -0
- data/lib/zm/client.rb +6 -1
- data/lib/zm/modules/base.rb +0 -1
- data/lib/zm/modules/belongs_to_folder.rb +6 -7
- data/lib/zm/modules/belongs_to_tag.rb +3 -1
- data/lib/zm/modules/common/zimbra-attrs.csv +3 -4
- data/lib/zm/modules/inspector.rb +2 -2
- data/lib/zm/modules/missing_method_static_collection.rb +2 -2
- data/lib/zm/support/cache/entry.rb +63 -0
- data/lib/zm/support/cache/file_store.rb +141 -0
- data/lib/zm/support/cache/null_store.rb +43 -0
- data/lib/zm/support/cache/request_strategy.rb +10 -0
- data/lib/zm/support/cache/store.rb +197 -0
- data/lib/zm/support/cache/strategy.rb +13 -0
- data/lib/zm/support/cache.rb +26 -0
- data/lib/zm-ruby-client.rb +2 -2
- data/zm-ruby-client.gemspec +10 -15
- metadata +37 -36
- data/lib/zm/client/common/token_metadata.rb +0 -44
- data/lib/zm/modules/zm_logger.rb +0 -26
|
@@ -14,8 +14,15 @@ module Zm
|
|
|
14
14
|
def initialize(parent)
|
|
15
15
|
@parent = parent
|
|
16
16
|
|
|
17
|
-
@all = CSV.open(
|
|
18
|
-
|
|
17
|
+
@all = CSV.open(
|
|
18
|
+
File.expand_path(@parent.config.zimbra_attributes_path),
|
|
19
|
+
headers: true,
|
|
20
|
+
skip_blanks: true,
|
|
21
|
+
strip: true,
|
|
22
|
+
header_converters: lambda { |header| header.to_sym }
|
|
23
|
+
).map do |attr|
|
|
24
|
+
attr_h = attr.to_h
|
|
25
|
+
attr_h.compact!
|
|
19
26
|
ZimbraAttribute.new(**attr_h)
|
|
20
27
|
end.freeze
|
|
21
28
|
end
|
|
@@ -46,7 +53,7 @@ module Zm
|
|
|
46
53
|
end
|
|
47
54
|
|
|
48
55
|
def all_cos_attr_types_h
|
|
49
|
-
@all_cos_attr_types_h ||=
|
|
56
|
+
@all_cos_attr_types_h ||= all_cos_attrs.map { |attr| [attr.name, attr.type] }.to_h.freeze
|
|
50
57
|
end
|
|
51
58
|
|
|
52
59
|
def set_cos_methods
|
|
@@ -70,7 +77,7 @@ module Zm
|
|
|
70
77
|
end
|
|
71
78
|
|
|
72
79
|
def all_server_attr_types_h
|
|
73
|
-
@all_server_attr_types_h ||=
|
|
80
|
+
@all_server_attr_types_h ||= all_server_attrs.map { |attr| [attr.name, attr.type] }.to_h.freeze
|
|
74
81
|
end
|
|
75
82
|
|
|
76
83
|
def set_server_methods
|
|
@@ -94,7 +101,7 @@ module Zm
|
|
|
94
101
|
end
|
|
95
102
|
|
|
96
103
|
def all_domain_attr_types_h
|
|
97
|
-
@all_domain_attr_types_h ||=
|
|
104
|
+
@all_domain_attr_types_h ||= all_domain_attrs.map { |attr| [attr.name, attr.type] }.to_h.freeze
|
|
98
105
|
end
|
|
99
106
|
|
|
100
107
|
def set_domain_methods
|
|
@@ -118,7 +125,7 @@ module Zm
|
|
|
118
125
|
end
|
|
119
126
|
|
|
120
127
|
def all_account_attr_types_h
|
|
121
|
-
@all_account_attr_types_h ||=
|
|
128
|
+
@all_account_attr_types_h ||= all_account_attrs.map { |attr| [attr.name, attr.type] }.to_h.freeze
|
|
122
129
|
end
|
|
123
130
|
|
|
124
131
|
def set_account_methods
|
|
@@ -144,9 +151,9 @@ module Zm
|
|
|
144
151
|
end
|
|
145
152
|
|
|
146
153
|
def all_distributionlist_attrs_types_h
|
|
147
|
-
@all_distributionlist_attrs_types_h ||=
|
|
154
|
+
@all_distributionlist_attrs_types_h ||= all_distributionlist_attrs.map do |attr|
|
|
148
155
|
[attr.name, attr.type]
|
|
149
|
-
end
|
|
156
|
+
end.to_h.freeze
|
|
150
157
|
end
|
|
151
158
|
|
|
152
159
|
def set_distributionlist_methods
|
|
@@ -170,7 +177,7 @@ module Zm
|
|
|
170
177
|
end
|
|
171
178
|
|
|
172
179
|
def all_resource_attrs_types_h
|
|
173
|
-
@all_resource_attrs_types_h ||=
|
|
180
|
+
@all_resource_attrs_types_h ||= all_resource_attrs.map { |attr| [attr.name, attr.type] }.to_h.freeze
|
|
174
181
|
end
|
|
175
182
|
|
|
176
183
|
def set_resource_methods
|
data/lib/zm/client/base.rb
CHANGED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Zm
|
|
4
|
+
module Client
|
|
5
|
+
class BatchRequest
|
|
6
|
+
ONERRORS = %w[continue stop].freeze
|
|
7
|
+
|
|
8
|
+
attr_reader :requests
|
|
9
|
+
|
|
10
|
+
def initialize(connector)
|
|
11
|
+
@connector = connector
|
|
12
|
+
@requests = []
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def invoke(onerror: ONERRORS.first)
|
|
16
|
+
return [] if @requests.empty?
|
|
17
|
+
|
|
18
|
+
onerror = ONERRORS.first unless ONERRORS.include?(onerror)
|
|
19
|
+
|
|
20
|
+
soap_resp = @connector.invoke(build(onerror))[:BatchResponse]
|
|
21
|
+
@requests.clear
|
|
22
|
+
format_response(soap_resp)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def build(onerror)
|
|
28
|
+
soap_request = SoapElement.new(SoapConstants::BATCH_REQUEST, SoapConstants::NAMESPACE_STR)
|
|
29
|
+
soap_request.add_attribute(:onerror, onerror)
|
|
30
|
+
|
|
31
|
+
@requests.each_with_index do |request, index|
|
|
32
|
+
request.add_attribute(:requestId, index + 1)
|
|
33
|
+
soap_request.add_node(request)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
soap_request
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def format_response(soap_resp)
|
|
40
|
+
soap_resp.delete(:_jsns)
|
|
41
|
+
responses = soap_resp.values
|
|
42
|
+
responses.flatten!
|
|
43
|
+
responses.each do |response|
|
|
44
|
+
response[:requestId] = response[:requestId].to_i
|
|
45
|
+
end
|
|
46
|
+
responses
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -10,6 +10,7 @@ require 'zm/client/domain'
|
|
|
10
10
|
require 'zm/client/server'
|
|
11
11
|
require 'zm/client/cos'
|
|
12
12
|
require 'zm/client/license'
|
|
13
|
+
require 'zm/client/cluster/batch_request'
|
|
13
14
|
|
|
14
15
|
module Zm
|
|
15
16
|
module Client
|
|
@@ -19,8 +20,6 @@ module Zm
|
|
|
19
20
|
:majorversion, :minorversion, :microversion
|
|
20
21
|
|
|
21
22
|
def initialize(config)
|
|
22
|
-
# extend(ZmLogger)
|
|
23
|
-
|
|
24
23
|
@config = config
|
|
25
24
|
@version = config.zimbra_version
|
|
26
25
|
|
|
@@ -35,11 +34,13 @@ module Zm
|
|
|
35
34
|
end
|
|
36
35
|
|
|
37
36
|
def token
|
|
38
|
-
@
|
|
37
|
+
return @token if defined? @token
|
|
38
|
+
|
|
39
|
+
@token = (Token.new(@soap_admin_connector.token) if @soap_admin_connector.token)
|
|
39
40
|
end
|
|
40
41
|
|
|
41
42
|
def token=(value)
|
|
42
|
-
@soap_admin_connector.token= value
|
|
43
|
+
@token = Token.new(@soap_admin_connector.token = value)
|
|
43
44
|
end
|
|
44
45
|
|
|
45
46
|
def login
|
|
@@ -52,11 +53,12 @@ module Zm
|
|
|
52
53
|
soap_request = SoapElement.admin(SoapAdminConstants::AUTH_REQUEST)
|
|
53
54
|
soap_request.add_attributes(name: @config.zimbra_admin_login, password: @config.zimbra_admin_password)
|
|
54
55
|
soap_resp = @soap_admin_connector.invoke(soap_request, Zm::Client::AuthError)
|
|
55
|
-
|
|
56
|
+
soap_resp_token = soap_resp[:AuthResponse][:authToken].first[:_content]
|
|
57
|
+
self.token = soap_resp_token
|
|
56
58
|
end
|
|
57
59
|
|
|
58
60
|
def logged?
|
|
59
|
-
|
|
61
|
+
!token.nil? && !token.expired?
|
|
60
62
|
end
|
|
61
63
|
|
|
62
64
|
def alive?
|
|
@@ -68,39 +70,53 @@ module Zm
|
|
|
68
70
|
false
|
|
69
71
|
end
|
|
70
72
|
|
|
71
|
-
def
|
|
72
|
-
|
|
73
|
+
def logged_and_alive?
|
|
74
|
+
logged? && alive?
|
|
73
75
|
end
|
|
74
76
|
|
|
75
77
|
def license
|
|
76
|
-
@license
|
|
78
|
+
return @license if defined? @license
|
|
79
|
+
|
|
80
|
+
@license = LicensesCollection.new(self).find
|
|
77
81
|
rescue Zm::Client::SoapError => e
|
|
78
82
|
logger.error "Get License info #{e.message}"
|
|
79
83
|
nil
|
|
80
84
|
end
|
|
81
85
|
|
|
82
86
|
def domains
|
|
83
|
-
@domains
|
|
87
|
+
return @domains if defined? @domains
|
|
88
|
+
|
|
89
|
+
@domains = DomainsCollection.new self
|
|
84
90
|
end
|
|
85
91
|
|
|
86
92
|
def accounts
|
|
87
|
-
@accounts
|
|
93
|
+
return @accounts if defined? @accounts
|
|
94
|
+
|
|
95
|
+
@accounts = AccountsCollection.new self
|
|
88
96
|
end
|
|
89
97
|
|
|
90
98
|
def resources
|
|
91
|
-
@resources
|
|
99
|
+
return @resources if defined? @resources
|
|
100
|
+
|
|
101
|
+
@resources = ResourcesCollection.new self
|
|
92
102
|
end
|
|
93
103
|
|
|
94
104
|
def servers
|
|
95
|
-
@servers
|
|
105
|
+
return @servers if defined? @servers
|
|
106
|
+
|
|
107
|
+
@servers = ServersCollection.new self
|
|
96
108
|
end
|
|
97
109
|
|
|
98
110
|
def coses
|
|
99
|
-
@coses
|
|
111
|
+
return @coses if defined? @coses
|
|
112
|
+
|
|
113
|
+
@coses = CosesCollection.new self
|
|
100
114
|
end
|
|
101
115
|
|
|
102
116
|
def distributionlists
|
|
103
|
-
@distributionlists
|
|
117
|
+
return @distributionlists if defined? @distributionlists
|
|
118
|
+
|
|
119
|
+
@distributionlists = DistributionListsCollection.new self
|
|
104
120
|
end
|
|
105
121
|
|
|
106
122
|
alias distribution_lists distributionlists
|
|
@@ -141,14 +157,24 @@ module Zm
|
|
|
141
157
|
|
|
142
158
|
json = soap_response[:GetVersionInfoResponse][:info].first
|
|
143
159
|
|
|
144
|
-
instance_variable_set(:@type, json
|
|
145
|
-
instance_variable_set(:@version, json
|
|
146
|
-
instance_variable_set(:@release, json
|
|
147
|
-
instance_variable_set(:@buildDate, json
|
|
148
|
-
instance_variable_set(:@host, json
|
|
149
|
-
instance_variable_set(:@majorversion, json
|
|
150
|
-
instance_variable_set(:@minorversion, json
|
|
151
|
-
instance_variable_set(:@microversion, json
|
|
160
|
+
instance_variable_set(:@type, json.delete(:type))
|
|
161
|
+
instance_variable_set(:@version, json.delete(:version))
|
|
162
|
+
instance_variable_set(:@release, json.delete(:release))
|
|
163
|
+
instance_variable_set(:@buildDate, json.delete(:buildDate))
|
|
164
|
+
instance_variable_set(:@host, json.delete(:host))
|
|
165
|
+
instance_variable_set(:@majorversion, json.delete(:majorversion))
|
|
166
|
+
instance_variable_set(:@minorversion, json.delete(:minorversion))
|
|
167
|
+
instance_variable_set(:@microversion, json.delete(:microversion))
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def logger
|
|
171
|
+
@config.logger
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def batch
|
|
175
|
+
return @batch if defined? @batch
|
|
176
|
+
|
|
177
|
+
@batch = BatchRequest.new(@soap_admin_connector)
|
|
152
178
|
end
|
|
153
179
|
|
|
154
180
|
private
|
|
@@ -156,10 +182,6 @@ module Zm
|
|
|
156
182
|
def find_domain_key(domain_name)
|
|
157
183
|
domains.attrs('zimbraPreAuthKey').find_by(name: domain_name).zimbraPreAuthKey
|
|
158
184
|
end
|
|
159
|
-
|
|
160
|
-
def logger
|
|
161
|
-
@config.logger
|
|
162
|
-
end
|
|
163
185
|
end
|
|
164
186
|
end
|
|
165
187
|
end
|
|
@@ -6,30 +6,65 @@ module Zm
|
|
|
6
6
|
module Client
|
|
7
7
|
# class config for cluster connection
|
|
8
8
|
class ClusterConfig
|
|
9
|
-
|
|
9
|
+
BASE_URL_REGEX = %r{\A(https?://[^/?#]+).*}
|
|
10
10
|
|
|
11
|
-
attr_reader :
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
:domains, :zimbra_version
|
|
11
|
+
attr_reader :zimbra_admin_url, :zimbra_public_url
|
|
12
|
+
attr_writer :logger, :colorize_logging
|
|
13
|
+
attr_accessor :zimbra_admin_login, :zimbra_admin_password,
|
|
14
|
+
:domains, :zimbra_version, :log_path, :timeout
|
|
15
15
|
|
|
16
16
|
def initialize(parameters = nil)
|
|
17
17
|
@domains = []
|
|
18
18
|
@zimbra_version = '8.8.15'
|
|
19
|
+
@log_path = $stdout
|
|
20
|
+
@log_level = Logger::INFO
|
|
21
|
+
@colorize_logging = false
|
|
22
|
+
@timeout = 300
|
|
19
23
|
|
|
24
|
+
init_from_parameters(parameters)
|
|
25
|
+
|
|
26
|
+
yield(self) if block_given?
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def cache
|
|
30
|
+
@cache = Zm::Support::Cache.registered_storage[cache_store_key]
|
|
31
|
+
.new(**cache_store_options)
|
|
32
|
+
.tap do |store|
|
|
33
|
+
store.logger = logger
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def cache_store_key
|
|
38
|
+
cache_store.first
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def cache_store_options
|
|
42
|
+
cache_store.last
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def cache_store
|
|
46
|
+
@cache_store ||= [:null_store, {}]
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def cache_store=(options)
|
|
50
|
+
store_key = options.shift
|
|
51
|
+
store_options = options.last
|
|
52
|
+
store_class = Zm::Support::Cache.registered_storage[store_key]
|
|
53
|
+
|
|
54
|
+
unless store_class || store_class.test_required_options(store_options)
|
|
55
|
+
raise ClusterConfigError, 'invalid cache_store'
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
@cache_store = [store_key, store_options]
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def init_from_parameters(parameters)
|
|
20
62
|
case parameters
|
|
21
63
|
when String
|
|
22
|
-
init_from_file(parameters)
|
|
64
|
+
init_from_h(init_from_file(parameters))
|
|
23
65
|
when Hash
|
|
24
|
-
|
|
66
|
+
init_from_h(parameters)
|
|
25
67
|
end
|
|
26
|
-
|
|
27
|
-
unless @to_h.nil?
|
|
28
|
-
init_from_h
|
|
29
|
-
make_config_domain
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
yield(self) if block_given?
|
|
33
68
|
end
|
|
34
69
|
|
|
35
70
|
def init_from_file(file_config_path)
|
|
@@ -42,34 +77,80 @@ module Zm
|
|
|
42
77
|
end
|
|
43
78
|
end
|
|
44
79
|
|
|
45
|
-
def init_from_h
|
|
46
|
-
@zimbra_admin_host = @to_h.fetch(:zimbra_admin_host, nil)
|
|
47
|
-
@zimbra_admin_scheme = @to_h.fetch(:zimbra_admin_scheme, 'https')
|
|
48
|
-
@zimbra_admin_port = @to_h.fetch(:zimbra_admin_port, 7071)
|
|
49
|
-
@zimbra_admin_login = @to_h.fetch(:zimbra_admin_login, nil)
|
|
50
|
-
@zimbra_admin_password = @to_h.fetch(:zimbra_admin_password, nil)
|
|
51
|
-
@zimbra_public_host = @to_h.fetch(:zimbra_public_host, nil)
|
|
52
|
-
@zimbra_public_scheme = @to_h.fetch(:zimbra_public_scheme, 'https')
|
|
53
|
-
@zimbra_public_port = @to_h.fetch(:zimbra_public_port, 443)
|
|
54
|
-
@zimbra_version = @to_h.fetch(:zimbra_version, @zimbra_version)
|
|
55
|
-
end
|
|
56
|
-
|
|
57
80
|
def init_from_yml(file_config_path)
|
|
58
|
-
|
|
81
|
+
YAML.safe_load_file(file_config_path, symbolize_names: true)
|
|
59
82
|
end
|
|
60
83
|
|
|
61
84
|
def init_from_json(file_config_path)
|
|
62
|
-
|
|
85
|
+
JSON.parse(File.read(file_config_path), symbolize_names: true)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def init_from_h(parameters)
|
|
89
|
+
@zimbra_admin_login = parameters.delete(:zimbra_admin_login)
|
|
90
|
+
@zimbra_admin_password = parameters.delete(:zimbra_admin_password)
|
|
91
|
+
|
|
92
|
+
init_admin_url_from_parameters(parameters)
|
|
93
|
+
|
|
94
|
+
init_public_url_from_parameters(parameters)
|
|
95
|
+
|
|
96
|
+
if (version = parameters.delete(:zimbra_version))
|
|
97
|
+
@zimbra_version = version
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
if (p_timeout = parameters.delete(:timeout))
|
|
101
|
+
@timeout = p_timeout.to_i
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
init_domains_from_parameters(parameters)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def init_domains_from_parameters(parameters)
|
|
108
|
+
if (config_domains = parameters.delete(:domains))
|
|
109
|
+
@domains = config_domains.map do |h|
|
|
110
|
+
ClusterConfigDomain.new(h[:name], h[:key])
|
|
111
|
+
end
|
|
112
|
+
end
|
|
63
113
|
end
|
|
64
114
|
|
|
65
|
-
def
|
|
66
|
-
|
|
115
|
+
def init_public_url_from_parameters(parameters)
|
|
116
|
+
if (url = parameters.delete(:zimbra_public_url))
|
|
117
|
+
self.zimbra_public_url = url
|
|
118
|
+
elsif (host = parameters.delete(:zimbra_public_host))
|
|
119
|
+
scheme = parameters.delete(:zimbra_public_scheme) || 'https'
|
|
120
|
+
port = parameters.delete(:zimbra_public_port) || 443
|
|
67
121
|
|
|
68
|
-
|
|
69
|
-
ClusterConfigDomain.new(h[:name], h[:key])
|
|
122
|
+
self.zimbra_public_url = "#{scheme}://#{host}:#{port}"
|
|
70
123
|
end
|
|
71
124
|
end
|
|
72
125
|
|
|
126
|
+
def init_admin_url_from_parameters(parameters)
|
|
127
|
+
if (url = parameters.delete(:zimbra_admin_url))
|
|
128
|
+
self.zimbra_admin_url = url
|
|
129
|
+
else
|
|
130
|
+
scheme = parameters.delete(:zimbra_admin_scheme) || 'https'
|
|
131
|
+
host = parameters.delete(:zimbra_admin_host)
|
|
132
|
+
port = parameters.delete(:zimbra_admin_port) || 7071
|
|
133
|
+
|
|
134
|
+
self.zimbra_admin_url = "#{scheme}://#{host}:#{port}"
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def zimbra_admin_url=(url)
|
|
139
|
+
match_data = BASE_URL_REGEX.match(url)
|
|
140
|
+
|
|
141
|
+
raise ClusterConfigError, 'no valid zimbra_admin_url configuration' unless match_data
|
|
142
|
+
|
|
143
|
+
@zimbra_admin_url = match_data[1]
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def zimbra_public_url=(url)
|
|
147
|
+
match_data = BASE_URL_REGEX.match(url)
|
|
148
|
+
|
|
149
|
+
raise ClusterConfigError, 'no valid zimbra_public_url configuration' unless match_data
|
|
150
|
+
|
|
151
|
+
@zimbra_public_url = match_data[1]
|
|
152
|
+
end
|
|
153
|
+
|
|
73
154
|
def find_domain(domain_name)
|
|
74
155
|
@domains.find { |d| d.name == domain_name }
|
|
75
156
|
end
|
|
@@ -82,7 +163,7 @@ module Zm
|
|
|
82
163
|
end
|
|
83
164
|
|
|
84
165
|
def has_admin_credentials?
|
|
85
|
-
!@
|
|
166
|
+
!@zimbra_admin_url.nil? && !@zimbra_admin_login.nil? && !@zimbra_admin_password.nil?
|
|
86
167
|
end
|
|
87
168
|
|
|
88
169
|
def zimbra_attributes_path
|
|
@@ -94,18 +175,26 @@ module Zm
|
|
|
94
175
|
|
|
95
176
|
@zimbra_attributes_path = path
|
|
96
177
|
end
|
|
97
|
-
end
|
|
98
178
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
attr_reader :name, :key
|
|
179
|
+
def logger
|
|
180
|
+
return @logger if defined? @logger
|
|
102
181
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
182
|
+
@logger = ZmLogger.new(@log_path).tap do |log|
|
|
183
|
+
log.level = @log_level
|
|
184
|
+
log.colorize! if @colorize_logging
|
|
185
|
+
end
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
def log_level=(level)
|
|
189
|
+
return if level == @log_level
|
|
190
|
+
|
|
191
|
+
logger.level = @log_level = level
|
|
106
192
|
end
|
|
107
193
|
end
|
|
108
194
|
|
|
195
|
+
# class config for connection
|
|
196
|
+
ClusterConfigDomain = Data.define(:name, :key)
|
|
197
|
+
|
|
109
198
|
# class error for config
|
|
110
199
|
class ClusterConfigError < StandardError; end
|
|
111
200
|
end
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'addressable/uri'
|
|
4
|
-
|
|
5
3
|
module Zm
|
|
6
4
|
module Client
|
|
7
5
|
module Utils
|
|
@@ -17,17 +15,7 @@ module Zm
|
|
|
17
15
|
email
|
|
18
16
|
end
|
|
19
17
|
|
|
20
|
-
|
|
21
|
-
Addressable::URI.escape path
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def format_url_params(hash)
|
|
25
|
-
uri = Addressable::URI.new
|
|
26
|
-
uri.query_values = hash
|
|
27
|
-
uri.query
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
# TODO: chercher - remplacer toutes les occurences dans le code
|
|
18
|
+
# TODO: chercher - remplacer toutes les occurrences dans le code
|
|
31
19
|
def arrow_name(name)
|
|
32
20
|
return name if name.to_s.start_with?(ARROW)
|
|
33
21
|
|
data/lib/zm/client/common.rb
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'faraday/multipart'
|
|
4
|
+
require 'uri'
|
|
4
5
|
|
|
5
6
|
module Zm
|
|
6
7
|
module Client
|
|
7
|
-
class
|
|
8
|
-
attr_reader :verbose, :
|
|
8
|
+
class RestConnector
|
|
9
|
+
attr_reader :verbose, :timeout
|
|
10
|
+
attr_writer :cookies
|
|
9
11
|
|
|
10
|
-
def initialize
|
|
11
|
-
@verbose =
|
|
12
|
-
@timeout =
|
|
12
|
+
def initialize(verbose: false, timeout: 300)
|
|
13
|
+
@verbose = verbose
|
|
14
|
+
@timeout = timeout
|
|
13
15
|
|
|
14
16
|
@ssl_options = {
|
|
15
17
|
verify: false,
|
|
@@ -18,14 +20,29 @@ module Zm
|
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
@cookies = nil
|
|
21
|
-
end
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
@verbose = true
|
|
24
|
+
yield(self) if block_given?
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
-
def
|
|
28
|
-
|
|
27
|
+
def download(download_url, dest_file_path)
|
|
28
|
+
url, path = split_url(download_url)
|
|
29
|
+
|
|
30
|
+
conn = conn_get(url)
|
|
31
|
+
|
|
32
|
+
response = nil
|
|
33
|
+
|
|
34
|
+
File.open(dest_file_path, 'wb') do |f|
|
|
35
|
+
response = conn.get(path) do |request|
|
|
36
|
+
request.options.on_data = proc do |chunk, _, _|
|
|
37
|
+
f.write chunk
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
return unless response.status >= 400
|
|
43
|
+
|
|
44
|
+
FileUtils.rm_f(dest_file_path)
|
|
45
|
+
raise RestError, "Download failure: #{response.body} (status=#{response.status})"
|
|
29
46
|
end
|
|
30
47
|
|
|
31
48
|
def read(download_url)
|
|
@@ -48,32 +65,18 @@ module Zm
|
|
|
48
65
|
data
|
|
49
66
|
end
|
|
50
67
|
|
|
51
|
-
def download(download_url, dest_file_path)
|
|
52
|
-
url, path = split_url(download_url)
|
|
53
|
-
|
|
54
|
-
conn = conn_get(url)
|
|
55
|
-
|
|
56
|
-
write_downloaded_file(dest_file_path, conn, path)
|
|
57
|
-
end
|
|
58
|
-
|
|
59
68
|
def upload(upload_url, src_file_path)
|
|
60
69
|
url, path = split_url(upload_url)
|
|
61
70
|
|
|
62
|
-
conn =
|
|
71
|
+
conn = Faraday.new(**http_options(url)) do |faraday|
|
|
72
|
+
faraday.request :multipart
|
|
73
|
+
faraday.response :logger, nil, { headers: true, bodies: true, errors: true } if @verbose
|
|
74
|
+
end
|
|
63
75
|
|
|
64
76
|
payload = { file: Faraday::Multipart::FilePart.new(src_file_path, nil) }
|
|
65
77
|
response = conn.post(path, payload)
|
|
66
78
|
|
|
67
|
-
|
|
68
|
-
messages = [
|
|
69
|
-
"Upload failure ! #{src_file_path}",
|
|
70
|
-
extract_title(response.body)
|
|
71
|
-
].compact
|
|
72
|
-
|
|
73
|
-
raise RestError, messages.join("\n")
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
response.body
|
|
79
|
+
upload_return(response, failure_message: "Upload failure ! #{src_file_path}")
|
|
77
80
|
end
|
|
78
81
|
|
|
79
82
|
private
|
|
@@ -84,30 +87,17 @@ module Zm
|
|
|
84
87
|
end
|
|
85
88
|
end
|
|
86
89
|
|
|
87
|
-
def
|
|
88
|
-
Faraday.new(**http_options(url)) do |faraday|
|
|
89
|
-
faraday.request :multipart
|
|
90
|
-
faraday.response :logger, nil, { headers: true, bodies: true, errors: true } if @verbose
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
def write_downloaded_file(dest_file_path, conn, path)
|
|
95
|
-
response = nil
|
|
96
|
-
|
|
97
|
-
File.open(dest_file_path, 'wb') do |f|
|
|
98
|
-
response = conn.get(path) do |request|
|
|
99
|
-
request.options.on_data = Proc.new do |chunk, _, _|
|
|
100
|
-
f.write chunk
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
|
|
90
|
+
def upload_return(response, failure_message: 'Upload failure')
|
|
105
91
|
if response.status >= 400
|
|
106
|
-
|
|
107
|
-
|
|
92
|
+
messages = [
|
|
93
|
+
failure_message,
|
|
94
|
+
extract_title(response.body)
|
|
95
|
+
].compact
|
|
96
|
+
|
|
97
|
+
raise RestError, messages.join("\n")
|
|
108
98
|
end
|
|
109
99
|
|
|
110
|
-
response
|
|
100
|
+
response.body
|
|
111
101
|
end
|
|
112
102
|
|
|
113
103
|
def split_url(url)
|