ruby_aem 0.9.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.
@@ -0,0 +1,187 @@
1
+ =begin
2
+ Copyright 2016 Shine Solutions
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ =end
16
+
17
+ module RubyAem
18
+ # Package class contains API calls related to managing an AEM package.
19
+ class Package
20
+
21
+ # Initialise a package.
22
+ # Package name and version will then be used to construct the package file in the filesystem.
23
+ # E.g. package name 'somepackage' with version '1.2.3' will translate to somepackage-1.2.3.zip in the filesystem.
24
+ #
25
+ # @param client RubyAem::Client
26
+ # @param group_name the group name of the package, e.g. somepackagegroup
27
+ # @param package_name the name of the package, e.g. somepackage
28
+ # @param package_version the version of the package, e.g. 1.2.3
29
+ # @return new RubyAem::Package instance
30
+ def initialize(client, group_name, package_name, package_version)
31
+ @client = client
32
+ @info = {
33
+ group_name: group_name,
34
+ package_name: package_name,
35
+ package_version: package_version
36
+ }
37
+ end
38
+
39
+ # Create the package.
40
+ #
41
+ # @return RubyAem::Result
42
+ def create()
43
+ @client.call(self.class, __callee__.to_s, @info)
44
+ end
45
+
46
+ # Update the package with specific filter.
47
+ #
48
+ # @param filter package filter JSON string
49
+ # @return RubyAem::Result
50
+ def update(filter)
51
+ @info[:filter] = filter
52
+ @client.call(self.class, __callee__.to_s, @info)
53
+ end
54
+
55
+ # Delete the package.
56
+ #
57
+ # @return RubyAem::Result
58
+ def delete()
59
+ @client.call(self.class, __callee__.to_s, @info)
60
+ end
61
+
62
+ # Build the package.
63
+ #
64
+ # @return RubyAem::Result
65
+ def build()
66
+ @client.call(self.class, __callee__.to_s, @info)
67
+ end
68
+
69
+ # Install the package.
70
+ #
71
+ # @return RubyAem::Result
72
+ def install()
73
+ @client.call(self.class, __callee__.to_s, @info)
74
+ end
75
+
76
+ # Replicate the package.
77
+ # Package will then be added to replication agents.
78
+ #
79
+ # @return RubyAem::Result
80
+ def replicate()
81
+ @client.call(self.class, __callee__.to_s, @info)
82
+ end
83
+
84
+ # Download the package to a specified directory.
85
+ #
86
+ # @param file_path the directory where the package will be downloaded to
87
+ # @return RubyAem::Result
88
+ def download(file_path)
89
+ @info[:file_path] = file_path
90
+ @client.call(self.class, __callee__.to_s, @info)
91
+ end
92
+
93
+ # Upload the package.
94
+ #
95
+ # @param file_path the directory where the package file to be uploaded is
96
+ # @param force if true, then overwrite if the package already exists
97
+ # @return RubyAem::Result
98
+ def upload(file_path, force)
99
+ @info[:file_path] = file_path
100
+ @info[:force] = force
101
+ @client.call(self.class, __callee__.to_s, @info)
102
+ end
103
+
104
+ # Get the package filter value.
105
+ # Filter value is stored in result's data.
106
+ #
107
+ # @return RubyAem::Result
108
+ def get_filter()
109
+ @client.call(self.class, __callee__.to_s, @info)
110
+ end
111
+
112
+ # Activate all paths within a package filter.
113
+ #
114
+ # @param ignore_deactivated if true, then deactivated items in the path will not be activated
115
+ # @param modified_only if true, then only modified items in the path will be activated
116
+ # @return RubyAem::Result
117
+ def activate_filter(ignore_deactivated, modified_only)
118
+ result = get_filter()
119
+
120
+ results = [result]
121
+ result.data.each { |filter_path|
122
+ path = RubyAem::Path.new(@client, filter_path)
123
+ results.push(path.activate(ignore_deactivated, modified_only))
124
+ }
125
+ results
126
+ end
127
+
128
+ # List all packages available in AEM instance.
129
+ #
130
+ # @return RubyAem::Result
131
+ def list_all()
132
+ @client.call(self.class, __callee__.to_s, @info)
133
+ end
134
+
135
+ # Check if this package is uploaded.
136
+ # Success result indicates that the package is uploaded.
137
+ # Otherwise a failure result indicates that package is not uploaded.
138
+ #
139
+ # @return RubyAem::Result
140
+ def is_uploaded()
141
+ result = list_all()
142
+
143
+ if result.is_success?
144
+ packages = result.data
145
+ package = packages.xpath("//packages/package[group=\"#{@info[:group_name]}\" and name=\"#{@info[:package_name]}\" and version=\"#{@info[:package_version]}\"]")
146
+
147
+ if package.to_s != ''
148
+ status = 'success'
149
+ message = "Package #{@info[:group_name]}/#{@info[:package_name]}-#{@info[:package_version]} is uploaded"
150
+ else
151
+ status = 'failure'
152
+ message = "Package #{@info[:group_name]}/#{@info[:package_name]}-#{@info[:package_version]} is not uploaded"
153
+ end
154
+ result = RubyAem::Result.new(status, message)
155
+ result.data = package
156
+ end
157
+
158
+ result
159
+ end
160
+
161
+ # Check if this package is installed.
162
+ # Success result indicates that the package is installed.
163
+ # Otherwise a failure result indicates that package is not installed.
164
+ #
165
+ # @return RubyAem::Result
166
+ def is_installed()
167
+ result = is_uploaded()
168
+
169
+ if result.is_success?
170
+ package = result.data
171
+ last_unpacked_by = package.xpath('lastUnpackedBy')
172
+
173
+ if not ['<lastUnpackedBy/>', '<lastUnpackedBy>null</lastUnpackedBy>'].include? last_unpacked_by.to_s
174
+ status = 'success'
175
+ message = "Package #{@info[:group_name]}/#{@info[:package_name]}-#{@info[:package_version]} is installed"
176
+ else
177
+ status = 'failure'
178
+ message = "Package #{@info[:group_name]}/#{@info[:package_name]}-#{@info[:package_version]} is not installed"
179
+ end
180
+ result = RubyAem::Result.new(status, message)
181
+ end
182
+
183
+ result
184
+ end
185
+
186
+ end
187
+ end
@@ -0,0 +1,46 @@
1
+ =begin
2
+ Copyright 2016 Shine Solutions
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ =end
16
+
17
+ module RubyAem
18
+ # Path class contains API calls related to managing an AEM path.
19
+ class Path
20
+
21
+ # Initialise a path.
22
+ #
23
+ # @param client RubyAem::Client
24
+ # @param name the name of the path, e.g. /etc/designs
25
+ # @return new RubyAem::Path instance
26
+ def initialize(client, name)
27
+ @client = client
28
+ @info = {
29
+ name: name
30
+ }
31
+ end
32
+
33
+ # Activate a path.
34
+ #
35
+ # @param ignore_deactivated if true, then deactivated items in the path will not be activated
36
+ # @param only_modified if true, then only modified items in the path will be activated
37
+ # @return RubyAem::Result
38
+ def activate(ignore_deactivated, only_modified)
39
+ @info[:ignoredeactivated] = ignore_deactivated
40
+ @info[:onlymodified] = only_modified
41
+
42
+ @client.call(self.class, __callee__.to_s, @info)
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,65 @@
1
+ =begin
2
+ Copyright 2016 Shine Solutions
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ =end
16
+
17
+ module RubyAem
18
+ # ReplicationAgent class contains API calls related to managing an AEM replication agent.
19
+ class ReplicationAgent
20
+
21
+ # Initialise a replication agent.
22
+ #
23
+ # @param client RubyAem::Client
24
+ # @param run_mode AEM run mode: author or publish
25
+ # @param name the replication agent's name, e.g. some-replication-agent
26
+ # @return new RubyAem::ReplicationAgent instance
27
+ def initialize(client, run_mode, name)
28
+ @client = client
29
+ @info = {
30
+ run_mode: run_mode,
31
+ name: name
32
+ }
33
+ end
34
+
35
+ # Create or update a replication agent.
36
+ #
37
+ # @param title replication agent title
38
+ # @param description replication agent description
39
+ # @param dest_base_url base URL of the agent target destination, e.g. https://somepublisher:4503
40
+ # @return RubyAem::Result
41
+ def create_update(title, description, dest_base_url)
42
+ @info[:title] = title
43
+ @info[:description] = description
44
+ @info[:dest_base_url] = dest_base_url
45
+ @client.call(self.class, __callee__.to_s, @info)
46
+ end
47
+
48
+ # Delete the replication agent.
49
+ #
50
+ # @return RubyAem::Result
51
+ def delete()
52
+ @client.call(self.class, __callee__.to_s, @info)
53
+ end
54
+
55
+ # Check whether the replication agent exists or not.
56
+ # If the replication agent exists, this method returns a success result.
57
+ # Otherwise it returns a failure result.
58
+ #
59
+ # @return RubyAem::Result
60
+ def exists()
61
+ @client.call(self.class, __callee__.to_s, @info)
62
+ end
63
+
64
+ end
65
+ end
@@ -0,0 +1,45 @@
1
+ =begin
2
+ Copyright 2016 Shine Solutions
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ =end
16
+
17
+ module RubyAem
18
+ # Repository class contains API calls related to managing an AEM repository.
19
+ class Repository
20
+
21
+ # Initialise repository.
22
+ #
23
+ # @param client RubyAem::Client
24
+ # @return new RubyAem::Repository instance
25
+ def initialize(client)
26
+ @client = client
27
+ @info = {}
28
+ end
29
+
30
+ # Block repository writes.
31
+ #
32
+ # @return RubyAem::Result
33
+ def block_writes
34
+ @client.call(self.class, __callee__.to_s, @info)
35
+ end
36
+
37
+ # Unblock repository writes.
38
+ #
39
+ # @return RubyAem::Result
40
+ def unblock_writes
41
+ @client.call(self.class, __callee__.to_s, @info)
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,66 @@
1
+ =begin
2
+ Copyright 2016 Shine Solutions
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ =end
16
+
17
+ module RubyAem
18
+ # Result represents the result of a client call.
19
+ #
20
+ # It has 3 statuses: success, warning, and failure.
21
+ # A success indicates that the client call was completed successfully.
22
+ # A failure indicates that the client call was completed but it failed with error.
23
+ # A warning indicates that the client call was completed but with warnings.
24
+ #
25
+ # Result message is stored in message attribute.
26
+ #
27
+ # Some client calls respond with data payload, which is stored in data attribute.
28
+ class Result
29
+
30
+ attr_reader :message
31
+ attr_accessor :data
32
+
33
+ # Initialise a result.
34
+ #
35
+ # @param status the result status: success, warning, or failure
36
+ # @param message the result message
37
+ # @return new RubyAem::Result instance
38
+ def initialize(status, message)
39
+ @status = status
40
+ @message = message
41
+ end
42
+
43
+ # Check whether the client call was successful.
44
+ #
45
+ # @return true when the status is success
46
+ def is_success?
47
+ return @status == 'success'
48
+ end
49
+
50
+ # Check whether the client call was completed
51
+ # with warnings.
52
+ #
53
+ # @return true when the status is warning
54
+ def is_warning?
55
+ return @status == 'warning'
56
+ end
57
+
58
+ # Check whether the client call failed.
59
+ #
60
+ # @return true when the status is failure
61
+ def is_failure?
62
+ return @status == 'failure'
63
+ end
64
+
65
+ end
66
+ end
@@ -0,0 +1,51 @@
1
+ =begin
2
+ Copyright 2016 Shine Solutions
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ =end
16
+
17
+ module RubyAem
18
+ # Swagger module contains logic related to swagger_aem.
19
+ module Swagger
20
+
21
+ # Convert ruby_aem spec's operation (consistent with Swagger spec's operationId)
22
+ # into swagger_aem's generated method name.
23
+ #
24
+ # @param operation operation ID
25
+ # @return swagger_aem method name
26
+ def Swagger.operation_to_method(operation)
27
+ operation.gsub(/[A-Z]/) { |char|
28
+ '_' + char.downcase
29
+ }
30
+ end
31
+
32
+ # Convert ruby_aem spec's property name (by replacing dots with underscores)
33
+ # into swagger_aem's generated parameter name.
34
+ #
35
+ # @param property property name
36
+ # @return swagger_aem parameter name
37
+ def Swagger.property_to_parameter(property)
38
+ property.gsub(/\./, '_')
39
+ end
40
+
41
+ # Sanitise path value by removing leading and trailing slashes
42
+ # swagger_aem accepts paths without those slashes.
43
+ #
44
+ # @param path path name
45
+ # @return sanitised path name
46
+ def Swagger.path(path)
47
+ path.gsub(/^\//, '').gsub(/\/$/, '')
48
+ end
49
+
50
+ end
51
+ end
@@ -0,0 +1,110 @@
1
+ =begin
2
+ Copyright 2016 Shine Solutions
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ =end
16
+
17
+ module RubyAem
18
+ # User class contains API calls related to managing an AEM user.
19
+ class User
20
+
21
+ # Initialise a user.
22
+ #
23
+ # @param client RubyAem::Client
24
+ # @param path the path to user node, e.g. /home/users/s/
25
+ # @param name the username of the AEM user, e.g. someuser, admin, johncitizen
26
+ # @return new RubyAem::User instance
27
+ def initialize(client, path, name)
28
+ @client = client
29
+ @info = {
30
+ path: path,
31
+ name: name
32
+ }
33
+ end
34
+
35
+ # Create a new user.
36
+ #
37
+ # @param password the password of the AEM user
38
+ # @return RubyAem::Result
39
+ def create(password)
40
+ @info[:password] = password
41
+ if !@info[:path].match(/^\//)
42
+ @info[:path] = "/#{@info[:path]}"
43
+ end
44
+ @client.call(self.class, __callee__.to_s, @info)
45
+ end
46
+
47
+ # Delete the user.
48
+ #
49
+ # @return RubyAem::Result
50
+ def delete()
51
+ result = find_authorizable_id
52
+ if result.data
53
+ @info[:path] = RubyAem::Swagger.path(@info[:path])
54
+ @client.call(self.class, __callee__.to_s, @info)
55
+ else
56
+ result
57
+ end
58
+ end
59
+
60
+ # Check whether the user exists or not.
61
+ # If the user exists, this method returns a success result.
62
+ # Otherwise it returns a failure result.
63
+ #
64
+ # @return RubyAem::Result
65
+ def exists()
66
+ @info[:path] = RubyAem::Swagger.path(@info[:path])
67
+ @client.call(self.class, __callee__.to_s, @info)
68
+ end
69
+
70
+ # Set the user's permission.
71
+ #
72
+ # @param permission_path the path that the user's permission is to be set against, e.g. /etc/replication
73
+ # @param permission_csv comma-separated-values of the user's permission, e.g. read:true,modify:true
74
+ # @return RubyAem::Result
75
+ def set_permission(permission_path, permission_csv)
76
+ @info[:permission_path] = permission_path
77
+ @info[:permission_csv] = permission_csv
78
+ @client.call(self.class, __callee__.to_s, @info)
79
+ end
80
+
81
+ # Add user to a group.
82
+ #
83
+ # @param group_path the path to group node, e.g. /home/groups/s/
84
+ # @param group_name the name of the AEM group, e.g. somegroup
85
+ # @return RubyAem::Result
86
+ def add_to_group(group_path, group_name)
87
+ group = RubyAem::Group.new(@client, group_path, group_name)
88
+ group.add_member(@info[:name])
89
+ end
90
+
91
+ # Change the user's password.
92
+ #
93
+ # @param old_password the user's old password to be changed from
94
+ # @param new_password the user's new password to be changed to
95
+ # @return RubyAem::Result
96
+ def change_password(old_password, new_password)
97
+ @info[:old_password] = old_password
98
+ @info[:new_password] = new_password
99
+ @client.call(self.class, __callee__.to_s, @info)
100
+ end
101
+
102
+ # Find the user's authorizable ID.
103
+ #
104
+ # @return RubyAem::Result
105
+ def find_authorizable_id()
106
+ @client.call(self.class, __callee__.to_s, @info)
107
+ end
108
+
109
+ end
110
+ end