zm-ruby-client 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +58 -0
- data/Gemfile +8 -0
- data/LICENSE +674 -0
- data/README.md +47 -0
- data/SECURITY.md +21 -0
- data/lib/zm/client/account/account.rb +345 -0
- data/lib/zm/client/account/account_dls_membership_collection.rb +22 -0
- data/lib/zm/client/account/account_dls_owner_collection.rb +22 -0
- data/lib/zm/client/account/accounts_builder.rb +19 -0
- data/lib/zm/client/account/accounts_collection.rb +48 -0
- data/lib/zm/client/account.rb +7 -0
- data/lib/zm/client/ace/ace.rb +32 -0
- data/lib/zm/client/ace/aces_builder.rb +25 -0
- data/lib/zm/client/ace/aces_collection.rb +36 -0
- data/lib/zm/client/ace.rb +5 -0
- data/lib/zm/client/appointment/appointment.rb +143 -0
- data/lib/zm/client/appointment/appointment_jsns_builder.rb +125 -0
- data/lib/zm/client/appointment/appointment_jsns_initializer.rb +129 -0
- data/lib/zm/client/appointment/appointments_builder.rb +33 -0
- data/lib/zm/client/appointment/appointments_collection.rb +106 -0
- data/lib/zm/client/appointment.rb +7 -0
- data/lib/zm/client/backup/backup.rb +59 -0
- data/lib/zm/client/backup/backups_builder.rb +26 -0
- data/lib/zm/client/backup/backups_collection.rb +22 -0
- data/lib/zm/client/backup.rb +5 -0
- data/lib/zm/client/base/account_object.rb +17 -0
- data/lib/zm/client/base/admin_object.rb +45 -0
- data/lib/zm/client/base/object.rb +80 -0
- data/lib/zm/client/base/objects_builder.rb +31 -0
- data/lib/zm/client/base/objects_collection.rb +135 -0
- data/lib/zm/client/base.rb +7 -0
- data/lib/zm/client/cluster/cluster.rb +121 -0
- data/lib/zm/client/cluster/cluster_config.rb +100 -0
- data/lib/zm/client/cluster.rb +4 -0
- data/lib/zm/client/common/message.rb +10 -0
- data/lib/zm/client/common/recipients.rb +67 -0
- data/lib/zm/client/common/token_metadata.rb +44 -0
- data/lib/zm/client/common.rb +5 -0
- data/lib/zm/client/config.rb +12 -0
- data/lib/zm/client/connector/rest_account.rb +74 -0
- data/lib/zm/client/connector/soap_account.rb +563 -0
- data/lib/zm/client/connector/soap_admin.rb +532 -0
- data/lib/zm/client/connector/soap_base.rb +65 -0
- data/lib/zm/client/connector/soap_error.rb +26 -0
- data/lib/zm/client/connector/soap_xml_builder.rb +68 -0
- data/lib/zm/client/constant.rb +217 -0
- data/lib/zm/client/contact/contact.rb +124 -0
- data/lib/zm/client/contact/contact_member.rb +73 -0
- data/lib/zm/client/contact/contacts_builder.rb +24 -0
- data/lib/zm/client/contact/contacts_collection.rb +26 -0
- data/lib/zm/client/contact/mod_group_contact.rb +74 -0
- data/lib/zm/client/contact.rb +7 -0
- data/lib/zm/client/cos/cos.rb +59 -0
- data/lib/zm/client/cos/coses_builder.rb +29 -0
- data/lib/zm/client/cos/coses_collection.rb +33 -0
- data/lib/zm/client/cos.rb +5 -0
- data/lib/zm/client/data_source.rb +5 -0
- data/lib/zm/client/distributionlist/distributionlist.rb +125 -0
- data/lib/zm/client/distributionlist/distributionlists_builder.rb +29 -0
- data/lib/zm/client/distributionlist/distributionlists_collection.rb +41 -0
- data/lib/zm/client/distributionlist.rb +5 -0
- data/lib/zm/client/document/document.rb +51 -0
- data/lib/zm/client/document/documents_builder.rb +31 -0
- data/lib/zm/client/document/documents_collection.rb +93 -0
- data/lib/zm/client/document.rb +5 -0
- data/lib/zm/client/domain/domain.rb +85 -0
- data/lib/zm/client/domain/domains_builder.rb +32 -0
- data/lib/zm/client/domain/domains_collection.rb +36 -0
- data/lib/zm/client/domain.rb +5 -0
- data/lib/zm/client/folder/folder.rb +215 -0
- data/lib/zm/client/folder/folder_grant.rb +58 -0
- data/lib/zm/client/folder/folder_retention_policy.rb +48 -0
- data/lib/zm/client/folder/folders_builder.rb +58 -0
- data/lib/zm/client/folder/folders_collection.rb +95 -0
- data/lib/zm/client/folder/mod_document_folder.rb +17 -0
- data/lib/zm/client/folder.rb +8 -0
- data/lib/zm/client/identity/identities_builder.rb +25 -0
- data/lib/zm/client/identity/identities_collection.rb +26 -0
- data/lib/zm/client/identity/identity.rb +75 -0
- data/lib/zm/client/identity.rb +5 -0
- data/lib/zm/client/license/license.rb +29 -0
- data/lib/zm/client/license/licenses_collection.rb +28 -0
- data/lib/zm/client/license.rb +4 -0
- data/lib/zm/client/message/message.rb +225 -0
- data/lib/zm/client/message/messages_builder.rb +31 -0
- data/lib/zm/client/message/messages_collection.rb +111 -0
- data/lib/zm/client/message.rb +5 -0
- data/lib/zm/client/mountpoint/mountpoint.rb +95 -0
- data/lib/zm/client/mountpoint/mountpoints_builder.rb +38 -0
- data/lib/zm/client/mountpoint/mountpoints_collection.rb +61 -0
- data/lib/zm/client/mountpoint.rb +5 -0
- data/lib/zm/client/mta_queue/mta_queue.rb +60 -0
- data/lib/zm/client/mta_queue/mta_queues_builder.rb +26 -0
- data/lib/zm/client/mta_queue/mta_queues_collection.rb +95 -0
- data/lib/zm/client/mta_queue.rb +5 -0
- data/lib/zm/client/mta_queue_item/mta_queue_item.rb +51 -0
- data/lib/zm/client/mta_queue_item/mta_queue_items_builder.rb +27 -0
- data/lib/zm/client/mta_queue_item/mta_queue_items_collection.rb +99 -0
- data/lib/zm/client/mta_queue_item.rb +5 -0
- data/lib/zm/client/resource/resource.rb +149 -0
- data/lib/zm/client/resource/resources_builder.rb +29 -0
- data/lib/zm/client/resource/resources_collection.rb +41 -0
- data/lib/zm/client/resource.rb +5 -0
- data/lib/zm/client/search_folder/search_folder.rb +63 -0
- data/lib/zm/client/search_folder/search_folders_builder.rb +26 -0
- data/lib/zm/client/search_folder/search_folders_collection.rb +28 -0
- data/lib/zm/client/search_folder.rb +5 -0
- data/lib/zm/client/server/server.rb +516 -0
- data/lib/zm/client/server/servers_builder.rb +26 -0
- data/lib/zm/client/server/servers_collection.rb +37 -0
- data/lib/zm/client/server.rb +5 -0
- data/lib/zm/client/share/share.rb +60 -0
- data/lib/zm/client/share/shares_builder.rb +23 -0
- data/lib/zm/client/share/shares_collection.rb +48 -0
- data/lib/zm/client/share.rb +5 -0
- data/lib/zm/client/signature/signature.rb +62 -0
- data/lib/zm/client/signature/signature_jsns_builder.rb +29 -0
- data/lib/zm/client/signature/signatures_builder.rb +26 -0
- data/lib/zm/client/signature/signatures_collection.rb +28 -0
- data/lib/zm/client/signature.rb +6 -0
- data/lib/zm/client/tag/tag.rb +45 -0
- data/lib/zm/client/tag/tags_builder.rb +25 -0
- data/lib/zm/client/tag/tags_collection.rb +26 -0
- data/lib/zm/client/tag.rb +5 -0
- data/lib/zm/client/task/task.rb +74 -0
- data/lib/zm/client/task/tasks_builder.rb +31 -0
- data/lib/zm/client/task/tasks_collection.rb +100 -0
- data/lib/zm/client/task.rb +5 -0
- data/lib/zm/client/upload/upload.rb +154 -0
- data/lib/zm/client/upload.rb +3 -0
- data/lib/zm/client/version.rb +18 -0
- data/lib/zm/client.rb +5 -0
- data/lib/zm/modules/common/account_common.rb +71 -0
- data/lib/zm/modules/common/cos_common.rb +463 -0
- data/lib/zm/modules/common/dl_common.rb +36 -0
- data/lib/zm/modules/common/identity_common.rb +19 -0
- data/lib/zm/modules/common/resource_common.rb +59 -0
- data/lib/zm/modules/common/signature_common.rb +16 -0
- data/lib/zm/modules/common/zimbra-attrs.json +1 -0
- data/lib/zm/utils/thread_pool.rb +72 -0
- data/lib/zm-ruby-client.rb +1 -0
- data/test/accounts.rb +62 -0
- data/test/cluster_config.rb +30 -0
- data/test/coses.rb +26 -0
- data/test/domains.rb +70 -0
- data/zm-ruby-client.gemspec +24 -0
- metadata +244 -0
@@ -0,0 +1,125 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'zm/modules/common/dl_common'
|
4
|
+
module Zm
|
5
|
+
module Client
|
6
|
+
# objectClass: zimbraDistributionList
|
7
|
+
class DistributionList < Base::AdminObject
|
8
|
+
attr_accessor :members
|
9
|
+
attr_reader :owners
|
10
|
+
|
11
|
+
def initialize(parent)
|
12
|
+
extend(DistributionListCommon)
|
13
|
+
super(parent)
|
14
|
+
@members = []
|
15
|
+
@owners = []
|
16
|
+
@grantee_type = 'grp'.freeze
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_h
|
20
|
+
hashmap = Hash[all_instance_variable_keys.map { |key| [key, instance_variable_get(arrow_name(key))] }]
|
21
|
+
hashmap.delete_if { |_, v| v.nil? }
|
22
|
+
hashmap
|
23
|
+
end
|
24
|
+
|
25
|
+
def all_instance_variable_keys
|
26
|
+
DistributionListCommon::ALL_ATTRS
|
27
|
+
end
|
28
|
+
|
29
|
+
def init_from_json(json)
|
30
|
+
# puts json
|
31
|
+
# @members = json[:a].select { |a| a[:n] == 'zimbraMailForwardingAddress' }.map { |a| a[:_content] }.compact
|
32
|
+
@members = json[:dlm].map { |a| a[:_content] }.compact if json[:dlm].is_a?(Array)
|
33
|
+
@owners = json[:owners].first[:owner].map { |a| a[:name] }.compact if json[:owners].is_a?(Array)
|
34
|
+
super(json)
|
35
|
+
@zimbraMailAlias = [@zimbraMailAlias].compact unless @zimbraMailAlias.is_a?(Array)
|
36
|
+
@zimbraMailAlias.delete(@name)
|
37
|
+
@aliases = @zimbraMailAlias
|
38
|
+
end
|
39
|
+
|
40
|
+
def create!
|
41
|
+
rep = sac.create_distribution_list(
|
42
|
+
@name,
|
43
|
+
instance_variables_array(attrs_write)
|
44
|
+
)
|
45
|
+
@id = rep[:Body][:CreateDistributionListResponse][:dl].first[:id]
|
46
|
+
end
|
47
|
+
|
48
|
+
def modify!
|
49
|
+
attrs_to_modify = instance_variables_array(attrs_write)
|
50
|
+
return if attrs_to_modify.empty?
|
51
|
+
|
52
|
+
sac.modify_distribution_list(@id, attrs_to_modify)
|
53
|
+
end
|
54
|
+
|
55
|
+
def update!(hash)
|
56
|
+
sac.modify_distribution_list(@id, hash)
|
57
|
+
|
58
|
+
hash.each do |k, v|
|
59
|
+
arrow_attr_sym = "@#{k}".to_sym
|
60
|
+
|
61
|
+
if v.respond_to?(:empty?) && v.empty?
|
62
|
+
self.remove_instance_variable(arrow_attr_sym) if self.instance_variable_get(arrow_attr_sym)
|
63
|
+
else
|
64
|
+
self.instance_variable_set(arrow_attr_sym, v)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def aliases
|
70
|
+
@aliases ||= []
|
71
|
+
end
|
72
|
+
|
73
|
+
def add_alias!(email)
|
74
|
+
sac.add_distribution_list_alias(@id, email)
|
75
|
+
aliases.push(email)
|
76
|
+
end
|
77
|
+
|
78
|
+
def remove_alias!(email)
|
79
|
+
sac.remove_distribution_list_alias(@id, email)
|
80
|
+
aliases.delete(email)
|
81
|
+
end
|
82
|
+
|
83
|
+
def rename!(email)
|
84
|
+
sac.rename_distribution_list(@id, email)
|
85
|
+
@name = email
|
86
|
+
end
|
87
|
+
|
88
|
+
def delete!
|
89
|
+
sac.delete_distribution_list(@id)
|
90
|
+
end
|
91
|
+
|
92
|
+
def add_members!(*emails)
|
93
|
+
sac.add_distribution_list_members(@id, emails)
|
94
|
+
@members += emails
|
95
|
+
end
|
96
|
+
|
97
|
+
def remove_members!(*emails)
|
98
|
+
sac.remove_distribution_list_members(@id, emails)
|
99
|
+
@members -= emails
|
100
|
+
end
|
101
|
+
|
102
|
+
def local_transport
|
103
|
+
raise Zm::Client::SoapError, 'zimbraMailHost is null' if zimbraMailHost.nil?
|
104
|
+
|
105
|
+
"lmtp:#{zimbraMailHost}:7025"
|
106
|
+
end
|
107
|
+
|
108
|
+
def local_transport!
|
109
|
+
update!(zimbraMailTransport: local_transport)
|
110
|
+
end
|
111
|
+
|
112
|
+
def is_local_transport?
|
113
|
+
return nil unless zimbraMailTransport
|
114
|
+
|
115
|
+
zimbraMailTransport.start_with?('lmtp')
|
116
|
+
end
|
117
|
+
|
118
|
+
def is_external_transport?
|
119
|
+
return nil unless zimbraMailTransport
|
120
|
+
|
121
|
+
zimbraMailTransport.start_with?('smtp')
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Zm
|
4
|
+
module Client
|
5
|
+
# class factory [resources]
|
6
|
+
class DistributionListsBuilder < Base::ObjectsBuilder
|
7
|
+
def initialize(parent, json)
|
8
|
+
super(parent, json)
|
9
|
+
@child_class = DistributionList
|
10
|
+
end
|
11
|
+
|
12
|
+
# def make
|
13
|
+
# return [] if json_items.nil?
|
14
|
+
#
|
15
|
+
# json_items.map do |entry|
|
16
|
+
# dl = DistributionList.new(@parent)
|
17
|
+
# dl.init_from_json(entry)
|
18
|
+
# dl
|
19
|
+
# end
|
20
|
+
# end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def json_items
|
25
|
+
@json_items ||= @json[:Body][json_key][:dl]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Zm
|
4
|
+
module Client
|
5
|
+
# Collection Resources
|
6
|
+
class DistributionListsCollection < Base::ObjectsCollection
|
7
|
+
def initialize(parent)
|
8
|
+
@child_class = DistributionList
|
9
|
+
@parent = parent
|
10
|
+
reset_query_params
|
11
|
+
end
|
12
|
+
|
13
|
+
def ldap
|
14
|
+
@apply_cos = 0
|
15
|
+
self
|
16
|
+
end
|
17
|
+
|
18
|
+
def find_by(hash)
|
19
|
+
rep = sac.get_distribution_list(hash.values.first, hash.keys.first, attrs_comma)
|
20
|
+
entry = rep[:Body][:GetDistributionListResponse][:dl].first
|
21
|
+
|
22
|
+
build_from_entry(entry)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def build_response
|
28
|
+
DistributionListsBuilder.new(@parent, make_query).make
|
29
|
+
end
|
30
|
+
|
31
|
+
def reset_query_params
|
32
|
+
super
|
33
|
+
@search_type = SearchType::DL
|
34
|
+
@attrs = SearchType::Attributes::DL.dup
|
35
|
+
@all_servers = 1
|
36
|
+
@refresh = 0
|
37
|
+
@apply_cos = 1
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Zm
|
4
|
+
module Client
|
5
|
+
# class for account document
|
6
|
+
class Document < Base::AccountObject
|
7
|
+
|
8
|
+
INSTANCE_VARIABLE_KEYS = %i[id uuid name s d l luuid ms mdver md rev f tn t meta ct descEnabled ver leb cr cd acl loid sf tn]
|
9
|
+
|
10
|
+
attr_accessor *INSTANCE_VARIABLE_KEYS
|
11
|
+
attr_writer :folder
|
12
|
+
attr_reader :json
|
13
|
+
|
14
|
+
alias parent_id l
|
15
|
+
|
16
|
+
def initialize(parent, json = nil)
|
17
|
+
@parent = parent
|
18
|
+
init_from_json(json) if json.is_a?(Hash)
|
19
|
+
yield(self) if block_given?
|
20
|
+
end
|
21
|
+
|
22
|
+
def concat
|
23
|
+
INSTANCE_VARIABLE_KEYS.map { |key| instance_variable_get(arrow_name(key)) }
|
24
|
+
end
|
25
|
+
|
26
|
+
def folder
|
27
|
+
@folder ||= @parent.folders.all.find { |folder| folder.id == l }
|
28
|
+
end
|
29
|
+
|
30
|
+
def tag!(tag_name)
|
31
|
+
@parent.sacc.item_action(@parent.token, :tag, @id, tn: tag_name)
|
32
|
+
end
|
33
|
+
|
34
|
+
def delete!
|
35
|
+
@parent.sacc.item_action(@parent.token, :delete, @id)
|
36
|
+
end
|
37
|
+
|
38
|
+
def download(dest_file_path)
|
39
|
+
uploader = Upload.new(@parent, RestAccountConnector.new)
|
40
|
+
uploader.download_file(folder.absFolderPath, nil, nil, [id], dest_file_path)
|
41
|
+
end
|
42
|
+
|
43
|
+
def init_from_json(json)
|
44
|
+
INSTANCE_VARIABLE_KEYS.each do |key|
|
45
|
+
var_name = "@#{key}"
|
46
|
+
instance_variable_set(var_name, json[key])
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Zm
|
4
|
+
module Client
|
5
|
+
# class factory [documents]
|
6
|
+
class DocumentsBuilder < Base::ObjectsBuilder
|
7
|
+
def initialize(parent, json)
|
8
|
+
@parent = parent
|
9
|
+
@json = json
|
10
|
+
end
|
11
|
+
|
12
|
+
def make
|
13
|
+
root.map do |s|
|
14
|
+
Document.new(@parent, s)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def ids
|
19
|
+
root.map { |s| s[:id] }
|
20
|
+
end
|
21
|
+
|
22
|
+
def root
|
23
|
+
root = @json[:Body][:SearchResponse][:doc]
|
24
|
+
return [] if root.nil?
|
25
|
+
|
26
|
+
root = [root] unless root.is_a?(Array)
|
27
|
+
root
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Zm
|
4
|
+
module Client
|
5
|
+
# collection of documents
|
6
|
+
class DocumentsCollection < Base::ObjectsCollection
|
7
|
+
DEFAULT_QUERY = 'in:briefcase'
|
8
|
+
|
9
|
+
attr_accessor :more
|
10
|
+
|
11
|
+
def initialize(parent)
|
12
|
+
@parent = parent
|
13
|
+
@more = true
|
14
|
+
reset_query_params
|
15
|
+
end
|
16
|
+
|
17
|
+
def new
|
18
|
+
document = Document.new(@parent)
|
19
|
+
yield(document) if block_given?
|
20
|
+
document
|
21
|
+
end
|
22
|
+
|
23
|
+
def start_at(start_at)
|
24
|
+
@start_at = start_at
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
28
|
+
def end_at(end_at)
|
29
|
+
@end_at = end_at
|
30
|
+
self
|
31
|
+
end
|
32
|
+
|
33
|
+
def folders(folders)
|
34
|
+
@folders = folders
|
35
|
+
@folder_ids = @folders.map(&:id)
|
36
|
+
self
|
37
|
+
end
|
38
|
+
|
39
|
+
def folder_ids(folder_ids)
|
40
|
+
@folder_ids = folder_ids
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
def where(query)
|
45
|
+
@query = query
|
46
|
+
self
|
47
|
+
end
|
48
|
+
|
49
|
+
def ids
|
50
|
+
@options = { resultMode: 1 }
|
51
|
+
search_builder.ids
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def search_response
|
57
|
+
rep = @parent.sacc.search(@parent.token, 'document', @offset, @limit, 'subjAsc', query, @options)
|
58
|
+
@more = rep[:Body][:SearchResponse][:more]
|
59
|
+
rep
|
60
|
+
end
|
61
|
+
|
62
|
+
def search_builder
|
63
|
+
DocumentsBuilder.new(@parent, search_response)
|
64
|
+
end
|
65
|
+
|
66
|
+
def build_response
|
67
|
+
documents = search_builder.make
|
68
|
+
documents.each { |appo| appo.folder = find_folder(appo) } unless @folders.empty?
|
69
|
+
documents
|
70
|
+
end
|
71
|
+
|
72
|
+
def query
|
73
|
+
return @query unless @query.nil?
|
74
|
+
|
75
|
+
return DEFAULT_QUERY if @folder_ids.empty?
|
76
|
+
|
77
|
+
@folder_ids.map { |id| %Q{inid:"#{id}"} }.join(' OR ')
|
78
|
+
end
|
79
|
+
|
80
|
+
def find_folder(document)
|
81
|
+
@folders.find { |folder| folder.id == document.l }
|
82
|
+
end
|
83
|
+
|
84
|
+
def reset_query_params
|
85
|
+
super
|
86
|
+
@query = nil
|
87
|
+
@folder_ids = []
|
88
|
+
@folders = []
|
89
|
+
@options = {}
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Zm
|
4
|
+
module Client
|
5
|
+
# objectClass: zimbraDomain
|
6
|
+
class Domain < Base::AdminObject
|
7
|
+
INSTANCE_VARIABLE_KEYS = %i[name description zimbraDomainName zimbraDomainStatus zimbraId zimbraDomainType
|
8
|
+
zimbraDomainDefaultCOSId zimbraGalAccountId zimbraPreAuthKey zimbraGalLdapBindDn zimbraGalLdapBindPassword
|
9
|
+
zimbraGalLdapFilter zimbraGalLdapSearchBase zimbraGalLdapURL zimbraGalMode zimbraMailTransport]
|
10
|
+
|
11
|
+
attr_accessor *INSTANCE_VARIABLE_KEYS
|
12
|
+
|
13
|
+
def initialize(parent)
|
14
|
+
super(parent)
|
15
|
+
@grantee_type = 'dom'.freeze
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_h
|
19
|
+
hashmap = Hash[all_instance_variable_keys.map { |key| [key, instance_variable_get(arrow_name(key))] }]
|
20
|
+
hashmap.delete_if { |_, v| v.nil? }
|
21
|
+
hashmap
|
22
|
+
end
|
23
|
+
|
24
|
+
def all_instance_variable_keys
|
25
|
+
INSTANCE_VARIABLE_KEYS
|
26
|
+
end
|
27
|
+
|
28
|
+
def create!
|
29
|
+
attrs_write = INSTANCE_VARIABLE_KEYS.dup
|
30
|
+
attrs_write.delete(:name)
|
31
|
+
|
32
|
+
rep = sac.create_domain(
|
33
|
+
@name,
|
34
|
+
instance_variables_array(attrs_write)
|
35
|
+
)
|
36
|
+
@id = rep[:Body][:CreateDomainResponse][:domain].first[:id]
|
37
|
+
end
|
38
|
+
|
39
|
+
def update!(hash)
|
40
|
+
sac.modify_domain(@id, hash)
|
41
|
+
|
42
|
+
hash.each do |k, v|
|
43
|
+
arrow_attr_sym = "@#{k}".to_sym
|
44
|
+
|
45
|
+
if v.respond_to?(:empty?) && v.empty?
|
46
|
+
self.remove_instance_variable(arrow_attr_sym) if self.instance_variable_get(arrow_attr_sym)
|
47
|
+
else
|
48
|
+
self.instance_variable_set(arrow_attr_sym, v)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def accounts
|
54
|
+
@accounts ||= AccountsCollection.new(self)
|
55
|
+
end
|
56
|
+
|
57
|
+
def init_from_json(json)
|
58
|
+
super(json)
|
59
|
+
return unless json[:a].is_a? Array
|
60
|
+
|
61
|
+
n_key = :n
|
62
|
+
c_key = :_content
|
63
|
+
at_key = '@'
|
64
|
+
|
65
|
+
attrs = {}
|
66
|
+
|
67
|
+
# TODO: definir ici le typage fort des attributs pour ne pas avoir
|
68
|
+
# a faire des cases sur les class des attributs dans le code.
|
69
|
+
|
70
|
+
json[:a].each do |a|
|
71
|
+
k = "#{at_key}#{a[n_key]}".to_sym
|
72
|
+
v = a[c_key]
|
73
|
+
if !attrs[k].nil?
|
74
|
+
attrs[k] = [attrs[k]] unless attrs[k].is_a?(Array)
|
75
|
+
attrs[k].push(v)
|
76
|
+
else
|
77
|
+
attrs[k] = v
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
attrs.each { |k, v| instance_variable_set(k, v) }
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Zm
|
4
|
+
module Client
|
5
|
+
# Class Builder [Domain]
|
6
|
+
class DomainsBuilder < Base::ObjectsBuilder
|
7
|
+
def initialize(parent, json)
|
8
|
+
super(parent, json)
|
9
|
+
@child_class = Domain
|
10
|
+
end
|
11
|
+
|
12
|
+
# def make
|
13
|
+
# records = []
|
14
|
+
# return records if json_items.nil?
|
15
|
+
#
|
16
|
+
# json_items.each do |entry|
|
17
|
+
# domain = Domain.new(@parent)
|
18
|
+
# domain.init_from_json(entry)
|
19
|
+
# records << domain
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# records
|
23
|
+
# end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def json_items
|
28
|
+
@json_items ||= @json[:Body][json_key][:domain]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Zm
|
4
|
+
module Client
|
5
|
+
# Class Collection [Domain]
|
6
|
+
class DomainsCollection < Base::ObjectsCollection
|
7
|
+
def initialize(parent)
|
8
|
+
@child_class = Domain
|
9
|
+
@parent = parent
|
10
|
+
reset_query_params
|
11
|
+
end
|
12
|
+
|
13
|
+
def find_by(hash, *attrs)
|
14
|
+
rep = sac.get_domain(hash.values.first, hash.keys.first, attrs.join(COMMA))
|
15
|
+
entry = rep[:Body][:GetDomainResponse][:domain].first
|
16
|
+
|
17
|
+
build_from_entry(entry)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def build_response
|
23
|
+
DomainsBuilder.new(@parent, make_query).make
|
24
|
+
end
|
25
|
+
|
26
|
+
def reset_query_params
|
27
|
+
super
|
28
|
+
@search_type = SearchType::DOMAIN
|
29
|
+
@attrs = SearchType::Attributes::DOMAIN.dup
|
30
|
+
@all_servers = 1
|
31
|
+
@refresh = 0
|
32
|
+
@apply_cos = 1
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|