zm-ruby-client 0.18.5 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (250) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/Gemfile +2 -2
  4. data/README.md +7 -0
  5. data/lib/zm/client/account/account.rb +31 -308
  6. data/lib/zm/client/account/account_aliases_collection.rb +52 -0
  7. data/lib/zm/client/account/account_dls_membership_collection.rb +4 -1
  8. data/lib/zm/client/account/account_dls_owner_collection.rb +8 -1
  9. data/lib/zm/client/account/account_jsns_builder.rb +77 -0
  10. data/lib/zm/client/account/account_jsns_initializer.rb +9 -24
  11. data/lib/zm/client/account/accounts_builder.rb +0 -1
  12. data/lib/zm/client/account/accounts_collection.rb +32 -8
  13. data/lib/zm/client/account.rb +1 -0
  14. data/lib/zm/client/ace/ace.rb +6 -22
  15. data/lib/zm/client/ace/ace_jsns_builder.rb +15 -16
  16. data/lib/zm/client/ace/ace_jsns_initializer.rb +0 -1
  17. data/lib/zm/client/ace/aces_builder.rb +0 -1
  18. data/lib/zm/client/ace/aces_collection.rb +2 -18
  19. data/lib/zm/client/appointment/appointment.rb +38 -30
  20. data/lib/zm/client/appointment/appointment_jsns_builder.rb +22 -34
  21. data/lib/zm/client/appointment/appointment_jsns_initializer.rb +6 -3
  22. data/lib/zm/client/appointment/appointments_builder.rb +6 -18
  23. data/lib/zm/client/appointment/appointments_collection.rb +25 -4
  24. data/lib/zm/client/backup/backup.rb +4 -32
  25. data/lib/zm/client/backup/backup_jsns_initializer.rb +26 -0
  26. data/lib/zm/client/backup/backups_builder.rb +8 -13
  27. data/lib/zm/client/backup/backups_collection.rb +2 -1
  28. data/lib/zm/client/backup.rb +1 -0
  29. data/lib/zm/client/base/account_search_objects_collection.rb +34 -13
  30. data/lib/zm/client/base/admin_objects_collection.rb +82 -17
  31. data/lib/zm/client/base/base_account_jsns_builder.rb +98 -0
  32. data/lib/zm/client/base/base_jsns_builder.rb +47 -0
  33. data/lib/zm/client/base/base_jsns_initializer.rb +43 -12
  34. data/lib/zm/client/base/ldap_filter.rb +20 -5
  35. data/lib/zm/client/base/mailbox_infos_collection.rb +68 -0
  36. data/lib/zm/client/base/mailbox_object.rb +299 -0
  37. data/lib/zm/client/base/mailbox_prefs_collection.rb +75 -0
  38. data/lib/zm/client/base/object.rb +28 -62
  39. data/lib/zm/client/base/objects_builder.rb +4 -10
  40. data/lib/zm/client/base/objects_collection.rb +13 -10
  41. data/lib/zm/client/base/zimbra_attribute.rb +10 -8
  42. data/lib/zm/client/base/zimbra_attributes_collection.rb +154 -10
  43. data/lib/zm/client/base.rb +5 -5
  44. data/lib/zm/client/cluster/cluster.rb +43 -39
  45. data/lib/zm/client/cluster/cluster_config.rb +5 -5
  46. data/lib/zm/client/common/recipients.rb +3 -3
  47. data/lib/zm/client/common/token_metadata.rb +4 -1
  48. data/lib/zm/client/common/utils.rb +57 -0
  49. data/lib/zm/client/common.rb +2 -1
  50. data/lib/zm/client/connector/rest_account.rb +15 -28
  51. data/lib/zm/client/connector/soap_account.rb +38 -441
  52. data/lib/zm/client/connector/soap_admin.rb +16 -552
  53. data/lib/zm/client/connector/soap_base.rb +30 -21
  54. data/lib/zm/client/connector/soap_error.rb +1 -3
  55. data/lib/zm/client/constant.rb +21 -11
  56. data/lib/zm/client/contact/contact.rb +42 -83
  57. data/lib/zm/client/contact/contact_jsns_builder.rb +60 -0
  58. data/lib/zm/client/contact/contact_jsns_initializer.rb +78 -0
  59. data/lib/zm/client/contact/contact_member.rb +29 -28
  60. data/lib/zm/client/contact/contact_members_collection.rb +44 -0
  61. data/lib/zm/client/contact/contacts_builder.rb +8 -1
  62. data/lib/zm/client/contact/contacts_collection.rb +17 -1
  63. data/lib/zm/client/contact/group_contact_jsns_builder.rb +51 -0
  64. data/lib/zm/client/contact/mod_group_contact.rb +4 -67
  65. data/lib/zm/client/contact.rb +5 -1
  66. data/lib/zm/client/cos/cos.rb +35 -40
  67. data/lib/zm/client/cos/cos_accounts_collection.rb +19 -0
  68. data/lib/zm/client/cos/cos_domains_collection.rb +20 -0
  69. data/lib/zm/client/cos/cos_jsns_builder.rb +72 -0
  70. data/lib/zm/client/cos/cos_jsns_initializer.rb +29 -0
  71. data/lib/zm/client/cos/cos_servers_collection.rb +60 -0
  72. data/lib/zm/client/cos/coses_builder.rb +8 -1
  73. data/lib/zm/client/cos/coses_collection.rb +8 -5
  74. data/lib/zm/client/cos.rb +5 -0
  75. data/lib/zm/client/datasource/datasource.rb +69 -0
  76. data/lib/zm/client/datasource/datasource_jsns_builder.rb +32 -0
  77. data/lib/zm/client/datasource/datasource_jsns_initializer.rb +27 -0
  78. data/lib/zm/client/datasource/datasources_builder.rb +29 -0
  79. data/lib/zm/client/datasource/datasources_collection.rb +21 -0
  80. data/lib/zm/client/datasource.rb +7 -0
  81. data/lib/zm/client/distributionlist/distributionlist.rb +52 -118
  82. data/lib/zm/client/distributionlist/distributionlist_aces_collection.rb +31 -0
  83. data/lib/zm/client/distributionlist/distributionlist_aliases_collection.rb +53 -0
  84. data/lib/zm/client/distributionlist/distributionlist_jsns_builder.rb +82 -0
  85. data/lib/zm/client/distributionlist/distributionlist_jsns_initializer.rb +32 -0
  86. data/lib/zm/client/distributionlist/distributionlist_members_collection.rb +47 -0
  87. data/lib/zm/client/distributionlist/distributionlist_owners_collection.rb +52 -0
  88. data/lib/zm/client/distributionlist/distributionlists_builder.rb +8 -1
  89. data/lib/zm/client/distributionlist/distributionlists_collection.rb +8 -9
  90. data/lib/zm/client/distributionlist/dls_membership_collection.rb +4 -1
  91. data/lib/zm/client/distributionlist.rb +2 -0
  92. data/lib/zm/client/document/document.rb +27 -24
  93. data/lib/zm/client/document/document_jsns_builder.rb +18 -0
  94. data/lib/zm/client/document/document_jsns_initializer.rb +44 -0
  95. data/lib/zm/client/document/documents_builder.rb +6 -16
  96. data/lib/zm/client/document/documents_collection.rb +17 -67
  97. data/lib/zm/client/document.rb +2 -0
  98. data/lib/zm/client/domain/domain.rb +39 -55
  99. data/lib/zm/client/domain/domain_accounts_collection.rb +1 -1
  100. data/lib/zm/client/domain/domain_distributionlists_collection.rb +13 -0
  101. data/lib/zm/client/domain/domain_jsns_builder.rb +69 -0
  102. data/lib/zm/client/domain/domain_jsns_initializer.rb +25 -0
  103. data/lib/zm/client/domain/domain_resources_collection.rb +13 -0
  104. data/lib/zm/client/domain/domains_builder.rb +8 -1
  105. data/lib/zm/client/domain/domains_collection.rb +7 -7
  106. data/lib/zm/client/domain.rb +4 -0
  107. data/lib/zm/client/filter_rule.rb +7 -0
  108. data/lib/zm/client/filter_rules/filter_rule.rb +10 -0
  109. data/lib/zm/client/filter_rules/filter_rule_jsns_initializer.rb +24 -0
  110. data/lib/zm/client/filter_rules/filter_rules_builder.rb +21 -0
  111. data/lib/zm/client/filter_rules/filter_rules_collection.rb +21 -0
  112. data/lib/zm/client/filter_rules/outgoing_filter_rules_collection.rb +15 -0
  113. data/lib/zm/client/folder/folder.rb +77 -61
  114. data/lib/zm/client/folder/folder_grant.rb +34 -14
  115. data/lib/zm/client/folder/folder_grant_jsns_builder.rb +15 -4
  116. data/lib/zm/client/folder/folder_grants_collection.rb +36 -2
  117. data/lib/zm/client/folder/folder_jsns_builder.rb +22 -48
  118. data/lib/zm/client/folder/folder_jsns_initializer.rb +34 -17
  119. data/lib/zm/client/folder/folder_retention_policies_collection.rb +2 -3
  120. data/lib/zm/client/folder/folder_retention_policy.rb +0 -1
  121. data/lib/zm/client/folder/folders_builder.rb +7 -10
  122. data/lib/zm/client/folder/folders_collection.rb +5 -2
  123. data/lib/zm/client/folder/folders_jsns_builder.rb +3 -1
  124. data/lib/zm/client/folder/mod_document_folder.rb +10 -6
  125. data/lib/zm/client/folder.rb +1 -1
  126. data/lib/zm/client/identity/identities_builder.rb +8 -1
  127. data/lib/zm/client/identity/identities_collection.rb +2 -1
  128. data/lib/zm/client/identity/identity.rb +34 -42
  129. data/lib/zm/client/identity/identity_jsns_builder.rb +57 -0
  130. data/lib/zm/client/identity/identity_jsns_initializer.rb +29 -0
  131. data/lib/zm/client/identity.rb +3 -1
  132. data/lib/zm/client/license/license.rb +9 -22
  133. data/lib/zm/client/license/license_jsns_initializer.rb +20 -0
  134. data/lib/zm/client/license/licenses_collection.rb +3 -13
  135. data/lib/zm/client/license.rb +2 -1
  136. data/lib/zm/client/message/attachments_collection.rb +55 -0
  137. data/lib/zm/client/message/message.rb +36 -264
  138. data/lib/zm/client/message/message_flags.rb +107 -0
  139. data/lib/zm/client/message/message_jsns_builder.rb +85 -0
  140. data/lib/zm/client/message/message_jsns_initializer.rb +71 -0
  141. data/lib/zm/client/message/message_recipients.rb +59 -0
  142. data/lib/zm/client/message/messages_builder.rb +7 -18
  143. data/lib/zm/client/message/messages_collection.rb +17 -2
  144. data/lib/zm/client/message.rb +5 -0
  145. data/lib/zm/client/mountpoint/mountpoint.rb +43 -20
  146. data/lib/zm/client/mountpoint/mountpoint_jsns_builder.rb +8 -53
  147. data/lib/zm/client/mountpoint/mountpoint_jsns_initializer.rb +22 -13
  148. data/lib/zm/client/mountpoint/mountpoints_builder.rb +4 -5
  149. data/lib/zm/client/mountpoint/mountpoints_collection.rb +1 -2
  150. data/lib/zm/client/mta_queue/mta_queue.rb +13 -28
  151. data/lib/zm/client/mta_queue/mta_queue_jsns_builder.rb +41 -0
  152. data/lib/zm/client/mta_queue/mta_queue_jsns_initializer.rb +23 -0
  153. data/lib/zm/client/mta_queue/mta_queues_builder.rb +4 -8
  154. data/lib/zm/client/mta_queue/mta_queues_collection.rb +8 -27
  155. data/lib/zm/client/mta_queue.rb +2 -0
  156. data/lib/zm/client/mta_queue_item/mta_queue_item.rb +4 -31
  157. data/lib/zm/client/mta_queue_item/mta_queue_item_jsns_initializer.rb +33 -0
  158. data/lib/zm/client/mta_queue_item/mta_queue_items_builder.rb +4 -9
  159. data/lib/zm/client/mta_queue_item/mta_queue_items_collection.rb +7 -42
  160. data/lib/zm/client/mta_queue_item.rb +2 -1
  161. data/lib/zm/client/resource/resource.rb +24 -91
  162. data/lib/zm/client/resource/resource_jsns_builder.rb +79 -0
  163. data/lib/zm/client/resource/resource_jsns_initializer.rb +29 -0
  164. data/lib/zm/client/resource/resources_builder.rb +8 -1
  165. data/lib/zm/client/resource/resources_collection.rb +9 -7
  166. data/lib/zm/client/resource.rb +2 -0
  167. data/lib/zm/client/search_folder/search_folder.rb +38 -16
  168. data/lib/zm/client/search_folder/search_folder_jsns_builder.rb +38 -19
  169. data/lib/zm/client/search_folder/search_folder_jsns_initializer.rb +17 -13
  170. data/lib/zm/client/search_folder/search_folders_builder.rb +0 -1
  171. data/lib/zm/client/search_folder/search_folders_collection.rb +2 -1
  172. data/lib/zm/client/server/server.rb +16 -488
  173. data/lib/zm/client/server/server_jsns_initializer.rb +16 -0
  174. data/lib/zm/client/server/servers_builder.rb +8 -1
  175. data/lib/zm/client/server/servers_collection.rb +13 -5
  176. data/lib/zm/client/server.rb +1 -0
  177. data/lib/zm/client/share/share.rb +5 -43
  178. data/lib/zm/client/share/share_jsns_initializer.rb +32 -0
  179. data/lib/zm/client/share/share_mountpoints_collection.rb +38 -0
  180. data/lib/zm/client/share/shares_builder.rb +8 -1
  181. data/lib/zm/client/share/shares_collection.rb +11 -16
  182. data/lib/zm/client/share.rb +2 -0
  183. data/lib/zm/client/signature/signature.rb +25 -29
  184. data/lib/zm/client/signature/signature_jsns_builder.rb +31 -13
  185. data/lib/zm/client/signature/signature_jsns_initializer.rb +16 -12
  186. data/lib/zm/client/signature/signatures_builder.rb +1 -2
  187. data/lib/zm/client/signature/signatures_collection.rb +2 -1
  188. data/lib/zm/client/signature.rb +1 -1
  189. data/lib/zm/client/soap_request/account_soap_constants.rb +76 -0
  190. data/lib/zm/client/soap_request/admin_soap_constants.rb +214 -0
  191. data/lib/zm/client/soap_request/mail_soap_constants.rb +162 -0
  192. data/lib/zm/client/soap_request/soap_constants.rb +55 -0
  193. data/lib/zm/client/soap_request/soap_context.rb +38 -0
  194. data/lib/zm/client/soap_request/soap_element.rb +90 -0
  195. data/lib/zm/client/soap_request.rb +8 -0
  196. data/lib/zm/client/tag/account_object_tags_collection.rb +65 -0
  197. data/lib/zm/client/tag/tag.rb +34 -22
  198. data/lib/zm/client/tag/tag_jsns_builder.rb +14 -35
  199. data/lib/zm/client/tag/tag_jsns_initializer.rb +4 -6
  200. data/lib/zm/client/tag/tags_builder.rb +0 -1
  201. data/lib/zm/client/tag/tags_collection.rb +2 -1
  202. data/lib/zm/client/tag.rb +1 -0
  203. data/lib/zm/client/task/task.rb +18 -49
  204. data/lib/zm/client/task/task_jsns_initializer.rb +45 -0
  205. data/lib/zm/client/task/tasks_builder.rb +6 -16
  206. data/lib/zm/client/task/tasks_collection.rb +29 -0
  207. data/lib/zm/client/task.rb +1 -0
  208. data/lib/zm/client/upload/upload.rb +26 -30
  209. data/lib/zm/client/version.rb +3 -3
  210. data/lib/zm/client.rb +4 -1
  211. data/lib/zm/modules/base.rb +10 -0
  212. data/lib/zm/modules/belongs_to_folder.rb +37 -0
  213. data/lib/zm/modules/belongs_to_tag.rb +11 -0
  214. data/lib/zm/modules/common/zimbra-attrs.json +1 -1
  215. data/lib/zm/modules/has_soap_admin_connector.rb +12 -0
  216. data/lib/zm/modules/inspector.rb +24 -0
  217. data/lib/zm/modules/missing_method_static_collection.rb +13 -0
  218. data/lib/zm/modules/zm_logger.rb +3 -1
  219. data/lib/zm/modules/zm_model.rb +4 -2
  220. data/lib/zm/utils/thread_pool.rb +4 -2
  221. data/lib/zm-ruby-client.rb +2 -0
  222. data/zm-ruby-client.gemspec +12 -9
  223. metadata +93 -34
  224. data/lib/zm/client/base/account_object.rb +0 -51
  225. data/lib/zm/client/base/admin_object.rb +0 -51
  226. data/lib/zm/client/base/folder_object.rb +0 -41
  227. data/lib/zm/client/config.rb +0 -12
  228. data/lib/zm/client/data_source.rb +0 -5
  229. data/lib/zm/modules/common/account_common.rb +0 -71
  230. data/lib/zm/modules/common/cos_common.rb +0 -463
  231. data/lib/zm/modules/common/dl_common.rb +0 -38
  232. data/lib/zm/modules/common/identity_common.rb +0 -19
  233. data/lib/zm/modules/common/resource_common.rb +0 -59
  234. data/lib/zm/modules/common/signature_common.rb +0 -16
  235. data/lib/zm/modules/common/zimbra-attrs.json.bak +0 -1
  236. data/test/accounts.rb +0 -89
  237. data/test/ace.rb +0 -50
  238. data/test/cluster.rb +0 -41
  239. data/test/cluster_config.rb +0 -30
  240. data/test/cluster_zimbra_attributes.rb +0 -38
  241. data/test/coses.rb +0 -26
  242. data/test/domains.rb +0 -70
  243. data/test/folder.rb +0 -125
  244. data/test/folder_grant.rb +0 -51
  245. data/test/mountpoint.rb +0 -49
  246. data/test/retention_policies.rb +0 -40
  247. data/test/search_folder.rb +0 -67
  248. data/test/signature.rb +0 -53
  249. data/test/tag.rb +0 -65
  250. data/test/zimbra_attributes.rb +0 -35
@@ -6,564 +6,28 @@ require_relative 'soap_error'
6
6
  module Zm
7
7
  module Client
8
8
  class SoapAdminConnector < SoapBaseConnector
9
- ADMINSPACE = 'urn:zimbraAdmin'
10
- A_NODE_PROC = ->(n) { { n: n.first, _content: n.last } }
11
-
12
- attr_accessor :token
13
-
14
- def initialize(scheme, host, port)
15
- super(scheme, host, port, '/service/admin/soap/')
16
- end
17
-
18
- def auth(mail, password)
19
- body = { Body: { AuthRequest: { _jsns: ADMINSPACE, name: mail, password: password } } }
20
- res = curl_request(body, AuthError)
21
- @token = res[BODY][:AuthResponse][:authToken][0][:_content]
22
- end
23
-
24
- def noop
25
- body = init_hash_request(:NoOpRequest)
26
- curl_request(body)
27
- end
28
-
29
- def delegate_auth(name, by = :name, duration = nil)
30
- req = { duration: duration, account: { by: by, _content: name } }.reject { |_, v| v.nil? }
31
- body = init_hash_request(:DelegateAuthRequest)
32
- body[:Body][:DelegateAuthRequest].merge!(req)
33
- res = curl_request(body)
34
- res[BODY][:DelegateAuthResponse][:authToken][0][:_content]
35
- end
36
-
37
- def get_license
38
- body = init_hash_request(:GetLicenseRequest)
39
- curl_request(body)
40
- end
41
-
42
- def count_object(type)
43
- soap_name = :CountObjectsRequest
44
- body = init_hash_request(soap_name)
45
- req = { type: type }
46
- body[:Body][soap_name].merge!(req)
47
- curl_request(body)
48
- end
49
-
50
- def create_gal_sync_account(name, domain_name, type, server_name, folder_name, account_name, attrs = {})
51
- req = {
52
- name: name,
53
- domain: domain_name,
54
- type: type,
55
- server: server_name,
56
- folder: folder_name,
57
- account: { by: :name, _content: account_name },
58
- a: attrs.to_a.map(&A_NODE_PROC)
59
- # a: attrs.to_a.map { |n| { n: n.first, _content: n.last } }
60
- }.reject { |_, v| v.nil? }
61
- body = init_hash_request(:CreateGalSyncAccountRequest)
62
- body[:Body][:CreateGalSyncAccountRequest].merge!(req)
63
- curl_request(body)
64
- end
65
-
66
- def sync_gal_account(gal_account_id, data_source, by = :name, full_sync = 1, reset = 1)
67
- req = {
68
- account: {
69
- id: gal_account_id,
70
- datasource: {
71
- by: by,
72
- fullSync: full_sync,
73
- reset: reset,
74
- _content: data_source
75
- }
76
- }
77
- }
78
- body = init_hash_request(:SyncGalAccountRequest)
79
- body[:Body][:SyncGalAccountRequest].merge!(req)
80
- curl_request(body)
81
- end
82
-
83
- def get_all_domains
84
- body = init_hash_request(:GetAllDomainsRequest)
85
- curl_request(body)
86
- end
87
-
88
- def create_data_source(name, account_id, type, attrs = {})
89
- req = {
90
- id: account_id,
91
- dataSource: {
92
- type: type,
93
- name: name,
94
- a: attrs.to_a.map(&A_NODE_PROC)
95
- # a: attrs.to_a.map { |n| { n: n.first, _content: n.last } }
96
- }
97
- }
98
- body = init_hash_request(:CreateDataSourceRequest)
99
- body[:Body][:CreateDataSourceRequest].merge!(req)
100
- curl_request(body)
101
- end
102
-
103
- def get_data_sources(id)
104
- req = { id: id }
105
- body = init_hash_request(:GetDataSourcesRequest)
106
- body[:Body][:GetDataSourcesRequest].merge!(req)
107
- curl_request(body)
108
- end
109
-
110
- def delete_data_source(account_id, data_source_id)
111
- req = { id: account_id, dataSource: { id: data_source_id } }
112
- body = init_hash_request(:DeleteDataSourceRequest)
113
- body[:Body][:DeleteDataSourceRequest].merge!(req)
114
- curl_request(body)
115
- end
116
-
117
- def get_all_servers(services = nil)
118
- req = { service: services }.reject { |_, v| v.nil? }
119
- body = init_hash_request(:GetAllServersRequest)
120
- body[:Body][:GetAllServersRequest].merge!(req)
121
- curl_request(body)
122
- end
123
-
124
- def get_server(name, by = :name, attrs = nil)
125
- req = { server: { by: by, _content: name }, attrs: attrs }
126
- body = init_hash_request(:GetServerRequest)
127
- body[:Body][:GetServerRequest].merge!(req)
128
- curl_request(body)
129
- end
130
-
131
- def get_cos(name, by = :name, attrs = nil)
132
- req = { cos: { by: by, _content: name } }
133
- req[:attrs] = attrs unless attrs.nil? || attrs.empty?
134
- body = init_hash_request(:GetCosRequest)
135
- body[:Body][:GetCosRequest].merge!(req)
136
- curl_request(body)
137
- end
138
-
139
- def create_cos(name, attrs = [])
140
- req = { name: { _content: name } }
141
- req[:a] = attrs.map do |i|
142
- if i.last.is_a?(Array)
143
- i.last.map do |j|
144
- [i.first, j]
145
- end
146
- else
147
- [i]
148
- end
149
- end.flatten(1).map(&A_NODE_PROC)
150
-
151
- body = init_hash_request(:CreateCosRequest)
152
- body[:Body][:CreateCosRequest].merge!(req)
153
- curl_request(body)
9
+ class << self
10
+ def create(config)
11
+ trans = new(
12
+ config.zimbra_admin_scheme,
13
+ config.zimbra_admin_host,
14
+ config.zimbra_admin_port
15
+ )
16
+ trans.logger = config.logger
17
+ trans
18
+ end
154
19
  end
155
20
 
156
- def modify_cos(id, attrs = nil)
157
- req = { _jsns: ADMINSPACE, id: [{ _content: id }], a: attrs.to_a.map{ |n| { n: n.first, _content: n.last } } }
158
- body = { Body: { ModifyCosRequest: req } }.merge(hash_header(@token))
159
- curl_request(body)
21
+ def token
22
+ context.to_hash[:authToken]
160
23
  end
161
24
 
162
- def delete_cos(id)
163
- req = { _jsns: ADMINSPACE, id: [{ _content: id }] }
164
- body = { Body: { DeleteCosRequest: req } }.merge(hash_header(@token))
165
- curl_request(body)
25
+ def token=(value)
26
+ context.token(value)
166
27
  end
167
28
 
168
- def create_account(name, password = nil, attrs = [])
169
- soap_name = :CreateAccountRequest
170
- req = { name: name, password: password }.reject { |_, v| v.nil? }
171
- req[:a] = attrs.map do |i|
172
- if i.last.is_a?(Array)
173
- i.last.map do |j|
174
- [i.first, j]
175
- end
176
- else
177
- [i]
178
- end
179
- end.flatten(1).map(&A_NODE_PROC)
180
- # req[:a] = attrs.map{|i|i.last.is_a?(Array) ? i.last.map{|j|[i.first, j]} : [i]}.flatten(1).map { |n| { n: n.first, _content: n.last } }
181
- body = init_hash_request(soap_name)
182
- body[:Body][soap_name].merge!(req)
183
- curl_request(body)
184
- end
185
-
186
- def create_resource(name, password = nil, attrs = [])
187
- soap_name = :CreateCalendarResourceRequest
188
- req = { name: name, password: password }
189
- req.reject! { |_, v| v.nil? }
190
- req[:a] = attrs.map do |i|
191
- if i.last.is_a?(Array)
192
- i.last.map do |j|
193
- [i.first, j]
194
- end
195
- else
196
- [i]
197
- end
198
- end.flatten(1).map(&A_NODE_PROC)
199
- body = init_hash_request(soap_name)
200
- body[:Body][soap_name].merge!(req)
201
- curl_request(body)
202
- end
203
-
204
- def rename_resource(id, email)
205
- generic_rename(:RenameCalendarResourceRequest, id, email)
206
- end
207
-
208
- def create_distribution_list(name, attrs = [])
209
- soap_name = :CreateDistributionListRequest
210
- req = { name: name }
211
- req[:a] = attrs.map do |i|
212
- if i.last.is_a?(Array)
213
- i.last.map do |j|
214
- [i.first, j]
215
- end
216
- else
217
- [i]
218
- end
219
- end.flatten(1).map(&A_NODE_PROC)
220
- body = init_hash_request(soap_name)
221
- body[:Body][soap_name].merge!(req)
222
- curl_request(body)
223
- end
224
-
225
- def modify_account(id, attrs = [])
226
- generic_modify(:ModifyAccountRequest, id, attrs)
227
- end
228
-
229
- def modify_resource(id, attrs = [])
230
- generic_modify(:ModifyCalendarResourceRequest, id, attrs)
231
- end
232
-
233
- def modify_distribution_list(id, attrs = [])
234
- generic_modify(:ModifyDistributionListRequest, id, attrs)
235
- end
236
-
237
- def generic_modify(soap_name, id, attrs)
238
- req = {
239
- id: id,
240
- a: attrs.map(&A_NODE_PROC)
241
- }
242
- body = init_hash_request(soap_name)
243
- body[:Body][soap_name].merge!(req)
244
- curl_request(body)
245
- end
246
-
247
- def add_account_alias(id, email)
248
- generic_alias(:AddAccountAliasRequest, id, email)
249
- end
250
-
251
- def remove_account_alias(id, email)
252
- generic_alias(:RemoveAccountAliasRequest, id, email)
253
- end
254
-
255
- def rename_account(id, email)
256
- generic_rename(:RenameAccountRequest, id, email)
257
- end
258
-
259
- def add_distribution_list_members(id, emails)
260
- generic_members(:AddDistributionListMemberRequest, id, emails)
261
- end
262
-
263
- def remove_distribution_list_members(id, emails)
264
- generic_members(:RemoveDistributionListMemberRequest, id, emails)
265
- end
266
-
267
- def generic_members(soap_name, id, emails)
268
- req = { id: id, dlm: emails.map { |email| { _content: email } } }
269
- body = init_hash_request(soap_name)
270
- body[:Body][soap_name].merge!(req)
271
- curl_request(body)
272
- end
273
-
274
- def add_distribution_list_alias(id, email)
275
- generic_alias(:AddDistributionListAliasRequest, id, email)
276
- end
277
-
278
- def remove_distribution_list_alias(id, email)
279
- generic_alias(:RemoveDistributionListAliasRequest, id, email)
280
- end
281
-
282
- def generic_alias(soap_name, id, email)
283
- req = { id: id, alias: email }
284
- body = init_hash_request(soap_name)
285
- body[:Body][soap_name].merge!(req)
286
- curl_request(body)
287
- end
288
-
289
- def rename_distribution_list(id, email)
290
- generic_rename(:RenameDistributionListRequest, id, email)
291
- end
292
-
293
- def generic_rename(soap_name, id, email)
294
- req = { id: id, newName: email }
295
- body = init_hash_request(soap_name)
296
- body[:Body][soap_name].merge!(req)
297
- curl_request(body)
298
- end
299
-
300
- def get_domain(name, by = :name, attrs = nil)
301
- req = { domain: { by: by, _content: name } }
302
- req[:_attrs] = attrs unless attrs.nil?
303
- body = init_hash_request(:GetDomainRequest)
304
- body[:Body][:GetDomainRequest].merge!(req)
305
- # TODO: tester param attrs
306
- curl_request(body)
307
- end
308
-
309
- def create_domain(name, attrs = [])
310
- soap_name = :CreateDomainRequest
311
- req = {
312
- name: name,
313
- a: attrs.map(&A_NODE_PROC)
314
- }
315
- body = init_hash_request(soap_name)
316
- body[:Body][soap_name].merge!(req)
317
- curl_request(body)
318
- end
319
-
320
- def modify_domain(id, attrs = [])
321
- generic_modify(:ModifyDomainRequest, id, attrs)
322
- end
323
-
324
- def get_account(name, by = :name, attrs = nil, applyCos = 1)
325
- soap_name = :GetAccountRequest
326
- req = { account: { by: by, _content: name }, applyCos: applyCos }
327
- req[:attrs] = attrs unless attrs.nil? || attrs.empty?
328
- body = init_hash_request(soap_name)
329
- body[:Body][soap_name].merge!(req)
330
- curl_request(body)
331
- end
332
-
333
- def get_account_membership(name, by = :name)
334
- soap_name = :GetAccountMembershipRequest
335
- req = { account: { by: by, _content: name } }
336
- body = init_hash_request(soap_name)
337
- body[:Body][soap_name].merge!(req)
338
- curl_request(body)
339
- end
340
-
341
- def get_resource(name, by = :name, attrs = nil)
342
- soap_name = :GetCalendarResourceRequest
343
- req = { calresource: { by: by, _content: name } }
344
- req[:attrs] = attrs unless attrs.nil?
345
- body = init_hash_request(soap_name)
346
- body[:Body][soap_name].merge!(req)
347
- # p body
348
- curl_request(body)
349
- end
350
-
351
- def get_distribution_list(name, by = :name, attrs = nil)
352
- soap_name = :GetDistributionListRequest
353
- req = { dl: { by: by, _content: name } }
354
- req[:attrs] = attrs unless attrs.nil?
355
- body = init_hash_request(soap_name)
356
- body[:Body][soap_name].merge!(req)
357
- # p body
358
- curl_request(body)
359
- end
360
-
361
- def get_distribution_list_membership(by_key, by = 'name', limit = nil, offset = nil)
362
- soap_name = :GetDistributionListMembershipRequest
363
- req = { dl: { by: by, _content: by_key }, limit: limit, offset: offset }
364
- req.reject! { |_, v| v.nil? }
365
- body = init_hash_request(soap_name)
366
- body[:Body][soap_name].merge!(req)
367
-
368
- curl_request(body)
369
- end
370
-
371
- def delete_account(id)
372
- generic_delete(:DeleteAccountRequest, id)
373
- end
374
-
375
- def delete_resource(id)
376
- generic_delete(:DeleteCalendarResourceRequest, id)
377
- end
378
-
379
- def delete_distribution_list(id)
380
- generic_delete(:DeleteDistributionListRequest, id)
381
- end
382
-
383
- def distribution_list_action(name, by = :name, action = {})
384
- soap_name = :DistributionListActionRequest
385
- req = { dl: { by: by, _content: name }, action: action }
386
- body = init_hash_request(soap_name)
387
- body[:Body][soap_name][:_jsns] = Zm::Client::SoapAccountConnector::ACCOUNTSPACE
388
- body[:Body][soap_name].merge!(req)
389
- # p body
390
- curl_request(body)
391
- end
392
-
393
- def generic_delete(soap_name, id)
394
- body = init_hash_request(soap_name)
395
- body[:Body][soap_name][:id] = id
396
- curl_request(body)
397
- end
398
-
399
- def search_directory(query = nil, maxResults = nil, limit = nil, offset = nil, domain = nil, applyCos = nil,
400
- applyConfig = nil, sortBy = nil, types = nil, sortAscending = nil, countOnly = nil, attrs = nil)
401
- # Désactivé car moins performant !
402
- # req = Hash[method(__method__).parameters.map{ |p|[p.last, (eval p.last.to_s)] }].select!{ |k,v|!v.nil? }
403
-
404
- soap_name = :SearchDirectoryRequest
405
-
406
- req = {
407
- query: query,
408
- maxResults: maxResults,
409
- limit: limit,
410
- offset: offset,
411
- domain: domain,
412
- applyCos: applyCos,
413
- applyConfig: applyConfig,
414
- sortBy: sortBy,
415
- types: types,
416
- sortAscending: sortAscending,
417
- countOnly: countOnly,
418
- attrs: attrs
419
- }.reject { |_, v| v.nil? }
420
-
421
- # body = { Body: { SearchDirectoryRequest: { _jsns: ADMINSPACE } } }.merge(hash_header(@token))
422
- body = init_hash_request(soap_name)
423
- body[:Body][soap_name].merge!(req)
424
-
425
- curl_request(body)
426
- end
427
-
428
- def get_quota_usage(domain = nil, allServers = nil, limit = nil, offset = nil, sortBy = nil, sortAscending = nil,
429
- refresh = nil, target_server_id = nil)
430
- soap_name = :GetQuotaUsageRequest
431
- req = {
432
- domain: domain,
433
- allServers: allServers,
434
- limit: limit,
435
- offset: offset,
436
- sortBy: sortBy,
437
- sortAscending: sortAscending,
438
- refresh: refresh
439
- }.reject { |_, v| v.nil? }
440
-
441
- # body = { Body: { GetQuotaUsageRequest: { _jsns: ADMINSPACE } } }.merge(hash_header(@token))
442
- body = init_hash_request(soap_name, target_server_id)
443
- body[:Body][soap_name].merge!(req)
444
- curl_request(body)
445
- end
446
-
447
- def get_mailbox(id)
448
- soap_name = :GetMailboxRequest
449
- req = {
450
- mbox: {
451
- id: id
452
- }
453
- }
454
- body = init_hash_request(soap_name)
455
- body[:Body][soap_name].merge!(req)
456
- curl_request(body)
457
- end
458
-
459
- def flush_cache(type, all_servers, id = nil, target_server_id = nil)
460
- soap_name = :FlushCacheRequest
461
- req = { cache: { type: type, allServers: all_servers } }
462
- req[:cache].merge!({ entry: { by: :id, _content: id } }) unless id.nil?
463
- body = init_hash_request(soap_name, target_server_id)
464
- body[:Body][soap_name].merge!(req)
465
- curl_request(body)
466
- end
467
-
468
- def get_share_info(id)
469
- soap_name = :GetShareInfoRequest
470
- req = { owner: { by: :id, _content: id } }
471
- body = init_hash_request(soap_name)
472
- body[:Body][soap_name].merge!(req)
473
- curl_request(body)
474
- end
475
-
476
- def move_mailbox(name, src, dest, dest_id)
477
- soap_name = :MoveMailboxRequest
478
- req = { account: { name: name, dest: dest, src: src } }
479
- body = init_hash_request(soap_name, dest_id)
480
- body[:Body][soap_name].merge!(req)
481
- curl_request(body)
482
- end
483
-
484
- def query_mailbox_move(name, dest_id)
485
- soap_name = :QueryMailboxMoveRequest
486
- req = { account: { name: name } }
487
- body = init_hash_request(soap_name, dest_id)
488
- body[:Body][soap_name].merge!(req)
489
- curl_request(body)
490
- end
491
-
492
- def get_mail_queue_info(server_name)
493
- soap_name = :GetMailQueueInfoRequest
494
- body = init_hash_request(soap_name)
495
- req = { server: { name: server_name } }
496
- body[:Body][soap_name].merge!(req)
497
- curl_request(body)
498
- end
499
-
500
- def get_mail_queue(server_name, queue_name, offset = 0, limit = 1000, fields = {})
501
- # fields = { fromdomain: 'domain.tld', todomain: 'domain.tld' }
502
- # AND operator
503
-
504
- query = {
505
- offset: offset,
506
- limit: limit
507
- }
508
- query[:field] = fields.map { |k, v| { name: k, match: { value: v } } } unless fields.empty?
509
- query.reject! { |_, v| v.nil? || v.empty? }
510
-
511
- soap_name = :GetMailQueueRequest
512
- body = init_hash_request(soap_name)
513
- req = {
514
- server: {
515
- name: server_name,
516
- queue: {
517
- name: queue_name,
518
- scan: 1,
519
- query: query
520
- }
521
- }
522
- }
523
- body[:Body][soap_name].merge!(req)
524
- curl_request(body)
525
- end
526
-
527
- def mail_queue_action(server_name, queue_name, op, value, by = :id)
528
- # op: hold|release|delete|requeue
529
- # by: id|query
530
- soap_name = :MailQueueActionRequest
531
- value = [value] unless value.is_a?(Array)
532
- body = init_hash_request(soap_name)
533
- req = { server: { name: server_name,
534
- queue: { name: queue_name, action: { op: op, by: by, _content: value.join(',') } } } }
535
- body[:Body][soap_name].merge!(req)
536
- curl_request(body)
537
- end
538
-
539
- def backup_query(dest_id)
540
- soap_name = :BackupQueryRequest
541
- body = init_hash_request(soap_name, dest_id)
542
- req = { query: {} }
543
- body[:Body][soap_name].merge!(req)
544
- curl_request(body)
545
- end
546
-
547
- def set_password(id, new_password)
548
- soap_name = :SetPasswordRequest
549
- body = init_hash_request(soap_name)
550
- req = { id: id, newPassword: new_password }
551
- body[:Body][soap_name].merge!(req)
552
- curl_request(body)
553
- end
554
-
555
- def get_version_info
556
- soap_name = :GetVersionInfoRequest
557
- body = init_hash_request(soap_name)
558
- curl_request(body)
559
- end
560
-
561
- def init_hash_request(soap_name, target_server = nil)
562
- {
563
- Body: {
564
- soap_name => { _jsns: ADMINSPACE }
565
- }
566
- }.merge(hash_header(@token, target_server))
29
+ def initialize(scheme, host, port)
30
+ super(scheme, host, port, SoapAdminConstants::ADMIN_SERVICE_URI)
567
31
  end
568
32
  end
569
33
  end
@@ -10,66 +10,75 @@ require_relative 'soap_error'
10
10
  module Zm
11
11
  module Client
12
12
  class SoapBaseConnector
13
+ include ZmLogger
14
+
13
15
  BASESPACE = 'urn:zimbra'
14
16
  HTTP_HEADERS = {
15
17
  'Content-Type' => 'application/json; charset=utf-8'
16
18
  }.freeze
17
- BODY = :Body
19
+
20
+ attr_reader :context
18
21
 
19
22
  def initialize(scheme, host, port, soap_path)
20
- extend(ZmLogger)
21
23
  @verbose = false
22
24
  @uri = URI::HTTP.new(scheme, nil, host, port, nil, soap_path, nil, nil, nil)
25
+ @context = SoapContext.new
26
+ init_curl_client
23
27
  end
24
28
 
25
29
  def verbose!
26
30
  @verbose = true
31
+ @curl.verbose = @verbose
32
+ end
33
+
34
+ def invoke(soap_element, error_handler = SoapError)
35
+ curl_request(envelope(soap_element), error_handler)[:Body]
36
+ end
37
+
38
+ def target_invoke(soap_element, target_id, error_handler = SoapError)
39
+ @context.target_server(target_id)
40
+ resp = invoke(soap_element, error_handler)
41
+ @context.target_server(nil)
42
+ resp
27
43
  end
28
44
 
29
45
  private
30
46
 
31
47
  def init_curl_client
32
- ::Curl::Easy.new(@uri.to_s) do |curl|
48
+ @curl = ::Curl::Easy.new(@uri.to_s) do |curl|
33
49
  curl.timeout = 300
34
50
  curl.enable_cookies = false
35
51
  curl.encoding = ''
36
52
  curl.headers = HTTP_HEADERS
37
53
  curl.ssl_verify_peer = false
38
54
  curl.ssl_verify_host = 0
39
- curl.verbose = @verbose
40
55
  end
41
56
  end
42
57
 
43
58
  def curl_request(body, error_handler = SoapError)
44
- curl = init_curl_client
45
59
  logger.debug body.to_json
46
- curl.http_post(body.to_json)
47
-
48
- logger.debug curl.body_str
60
+ @curl.http_post(body.to_json)
49
61
 
50
- soapbody = JSON.parse(curl.body_str, symbolize_names: true)
51
-
52
- if curl.status.to_i >= 400
53
- close_curl(curl)
54
- raise(error_handler, soapbody)
55
- end
62
+ logger.debug @curl.body_str
56
63
 
57
- close_curl(curl)
64
+ soapbody = JSON.parse(@curl.body_str, symbolize_names: true)
65
+ raise(error_handler, soapbody) if @curl.status.to_i >= 400
58
66
 
59
67
  soapbody
60
68
  end
61
69
 
62
- def close_curl(curl)
63
- curl.close
64
- # force process to kill socket
65
- GC.start
70
+ def envelope(soap_element)
71
+ {
72
+ Body: soap_element.to_hash,
73
+ Header: { context: context.to_hash, _jsns: BASESPACE }
74
+ }
66
75
  end
67
76
 
68
77
  def hash_header(token, target_server = nil)
69
- context = { authToken: token, userAgent: { name: :zmsoap }, targetServer: target_server }.delete_if do |_, v|
78
+ h_context = { authToken: token, userAgent: { name: :zmsoap }, targetServer: target_server }.delete_if do |_, v|
70
79
  v.nil?
71
80
  end
72
- { Header: { context: context, _jsns: BASESPACE } }
81
+ { Header: { context: h_context, _jsns: BASESPACE } }
73
82
  end
74
83
  end
75
84
  end
@@ -7,6 +7,7 @@ module Zm
7
7
 
8
8
  class SoapError < StandardError
9
9
  attr_reader :reason, :code
10
+
10
11
  def initialize(soapbody)
11
12
  @reason = soapbody[:Body][:Fault][:Reason][:Text]
12
13
  @code = soapbody[:Body][:Fault][:Detail][:Error][:Code]
@@ -18,9 +19,6 @@ module Zm
18
19
  end
19
20
 
20
21
  class RestError < StandardError
21
- def initialize(restbody)
22
- super(restbody)
23
- end
24
22
  end
25
23
  end
26
24
  end