1 /*
2 * #%L
3 * wcm.io
4 * %%
5 * Copyright (C) 2017 wcm.io
6 * %%
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * #L%
19 */
20 package io.wcm.tooling.commons.packmgr;
21
22 import java.util.Collections;
23 import java.util.List;
24 import java.util.Objects;
25 import java.util.regex.Pattern;
26 import java.util.stream.Collectors;
27
28 /**
29 * Configuration properties for {@link PackageManagerHelper}.
30 */
31 public final class PackageManagerProperties {
32
33 private String packageManagerUrl;
34 private String userId;
35 private String password;
36 private String oauth2AccessToken;
37 private String consoleUserId;
38 private String consolePassword;
39 private String consoleOauth2AccessToken;
40 private int retryCount = 24;
41 private int retryDelaySec = 5;
42 private String bundleStatusUrl;
43 private int bundleStatusWaitLimitSec = 360;
44 private List<Pattern> bundleStatusBlacklistBundleNames = Collections.emptyList();
45 private List<Pattern> bundleStatusWhitelistBundleNames = Collections.emptyList();
46 private String packageManagerInstallStatusURL;
47 private int packageManagerInstallStatusWaitLimitSec = 360;
48 private boolean relaxedSSLCheck;
49 private int httpConnectTimeoutSec = 10;
50 private int httpSocketTimeoutSec = 60;
51 private List<Proxy> proxies;
52 private String packageManagerOutputLogLevel = "INFO";
53
54 /**
55 * The URL of the HTTP service API of the CRX package manager.
56 * See <a href=
57 * "https://docs.adobe.com/content/docs/en/crx/2-3/how_to/package_manager.html#Managing%20Packages%20on%20the%20Command%20Line">CRX
58 * HTTP service Interface</a> for details on this interface.
59 * @return URL
60 */
61 public String getPackageManagerUrl() {
62 return this.packageManagerUrl;
63 }
64
65 /**
66 * @param packageManagerUrl The URL of the HTTP service API of the CRX package manager.
67 */
68 public void setPackageManagerUrl(String packageManagerUrl) {
69 this.packageManagerUrl = packageManagerUrl;
70 }
71
72 /**
73 * The user name to authenticate as against the remote CRX system (package manager).
74 * @return User ID
75 */
76 public String getUserId() {
77 return this.userId;
78 }
79
80 /**
81 * @param userId The user name to authenticate as against the remote CRX system (package manager).
82 */
83 public void setUserId(String userId) {
84 this.userId = userId;
85 }
86
87 /**
88 * The password to authenticate against the remote CRX system (package manager).
89 * @return Password
90 */
91 public String getPassword() {
92 return this.password;
93 }
94
95 /**
96 * @param password The password to authenticate against the remote CRX system (package manager).
97 */
98 public void setPassword(String password) {
99 this.password = password;
100 }
101
102 /**
103 * OAuth 2 access token to authenticate against the remote CRX system (package manager).
104 * If this is configured, username and password are ignored.
105 * @return OAuth 2 access token.
106 */
107 public String getOAuth2AccessToken() {
108 return this.oauth2AccessToken;
109 }
110
111 /**
112 * @param value OAuth 2 access token to authenticate against the remote CRX system (package manager).
113 */
114 public void setOAuth2AccessToken(String value) {
115 this.oauth2AccessToken = value;
116 }
117
118 /**
119 * The user name to authenticate as against the remote CRX system (Felix console).
120 * Fallback to {@link #getUserId()} if not set.
121 * @return User ID
122 */
123 public String getConsoleUserId() {
124 return Objects.toString(this.consoleUserId, this.userId);
125 }
126
127 /**
128 * @param consoleUserId The user name to authenticate as against the remote CRX system (Felix console).
129 */
130 public void setConsoleUserId(String consoleUserId) {
131 this.consoleUserId = consoleUserId;
132 }
133
134 /**
135 * The password to authenticate against the remote CRX system (Felix console).
136 * Fallback to {@link #getPassword()} if not set.
137 * @return Password
138 */
139 public String getConsolePassword() {
140 return Objects.toString(this.consolePassword, this.password);
141 }
142
143 /**
144 * @param consolePassword The password to authenticate against the remote CRX system (Felix console).
145 */
146 public void setConsolePassword(String consolePassword) {
147 this.consolePassword = consolePassword;
148 }
149
150 /**
151 * OAuth 2 access token to authenticate against the remote CRX system (Felix console).
152 * If this is configured, username and password are ignored.
153 * Fallback to {@link #getOAuth2AccessToken()} if not set.
154 * @return OAuth 2 access token.
155 */
156 public String getConsoleOAuth2AccessToken() {
157 return Objects.toString(this.consoleOauth2AccessToken, this.oauth2AccessToken);
158 }
159
160 /**
161 * @param value OAuth 2 access token to authenticate against the remote CRX system (Felix console).
162 */
163 public void setConsoleOAuth2AccessToken(String value) {
164 this.consoleOauth2AccessToken = value;
165 }
166
167 /**
168 * Number of times to retry upload and install via CRX HTTP interface if it fails.
169 * @return Retry count
170 */
171 public int getRetryCount() {
172 return this.retryCount;
173 }
174
175 /**
176 * @param retryCount Number of times to retry upload and install via CRX HTTP interface if it fails.
177 */
178 public void setRetryCount(int retryCount) {
179 this.retryCount = retryCount;
180 }
181
182 /**
183 * Number of seconds between retry attempts.
184 * @return Retry delay
185 */
186 public int getRetryDelaySec() {
187 return this.retryDelaySec;
188 }
189
190 /**
191 * @param retryDelaySec Number of seconds between retry attempts.
192 */
193 public void setRetryDelaySec(int retryDelaySec) {
194 this.retryDelaySec = retryDelaySec;
195 }
196
197 /**
198 * Bundle status JSON URL. If an URL is configured the activation status of all bundles in the system is checked
199 * before it is tried to upload and install a new package and after each upload.
200 * If not all bundles are activated the upload is delayed up to {link #getBundleStatusWaitLimitSec()} seconds, every 5
201 * seconds the activation status is checked anew.
202 * Expected is an URL like: http://localhost:4502/system/console/bundles/.json
203 * @return URL
204 */
205 public String getBundleStatusUrl() {
206 return this.bundleStatusUrl;
207 }
208
209 /**
210 * @param bundleStatusUrl Bundle status JSON URL
211 */
212 public void setBundleStatusUrl(String bundleStatusUrl) {
213 this.bundleStatusUrl = bundleStatusUrl;
214 }
215
216 /**
217 * Number of seconds to wait as maximum for a positive bundle status check.
218 * If this limit is reached and the bundle status is still not positive the install of the package proceeds anyway.
219 * @return Limit in seconds
220 */
221 public int getBundleStatusWaitLimitSec() {
222 return this.bundleStatusWaitLimitSec;
223 }
224
225 /**
226 * @param bundleStatusWaitLimitSec Number of seconds to wait as maximum for a positive bundle status
227 */
228 public void setBundleStatusWaitLimitSec(int bundleStatusWaitLimitSec) {
229 this.bundleStatusWaitLimitSec = bundleStatusWaitLimitSec;
230 }
231
232 /**
233 * Patterns for symbolic names of bundles that are expected to be not present in bundle list.
234 * If any of these bundles are found in the bundle list, this system is assumed as not ready for installing further
235 * packages because a previous installation (e.g. of AEM service pack) is still in progress.
236 * @return List of regular expressions for symbolic bundle names.
237 */
238 public List<Pattern> getBundleStatusBlacklistBundleNames() {
239 return this.bundleStatusBlacklistBundleNames;
240 }
241
242 /**
243 * @param bundleStatusBlacklistBundleNames Patterns for symbolic names of bundles that are expected to be not present
244 * in bundle list
245 */
246 public void setBundleStatusBlacklistBundleNames(List<String> bundleStatusBlacklistBundleNames) {
247 this.bundleStatusBlacklistBundleNames = bundleStatusBlacklistBundleNames.stream()
248 .map(Pattern::compile)
249 .collect(Collectors.toList());
250 }
251
252 /**
253 * Patterns for symbolic names of bundles that are ignored in bundle list.
254 * The state of these bundles has no effect on the bundle status check.
255 * @return List of regular expressions for symbolic bundle names.
256 */
257 public List<Pattern> getBundleStatusWhitelistBundleNames() {
258 return this.bundleStatusWhitelistBundleNames;
259 }
260
261 /**
262 * @param bundleStatusWhitelistBundleNames Patterns for symbolic names of bundles that are ignored in bundle list
263 */
264 public void setBundleStatusWhitelistBundleNames(List<String> bundleStatusWhitelistBundleNames) {
265 this.bundleStatusWhitelistBundleNames = bundleStatusWhitelistBundleNames.stream()
266 .map(Pattern::compile)
267 .collect(Collectors.toList());
268 }
269
270 /**
271 * Package Manager installation status JSON URL. If an URL is configured the installation status of packages and
272 * embedded packages is checked before it is tried to upload and install a new package and after each upload.
273 * If not all packages are installed the upload is delayed up to {link #getPackageManagerInstallStatusWaitLimit()}
274 * seconds, every 5 seconds the activation status is checked anew.
275 * Expected is an URL like: http://localhost:4502/crx/packmgr/installstatus.jsp
276 * @return URL
277 */
278 public String getPackageManagerInstallStatusURL() {
279 return this.packageManagerInstallStatusURL;
280 }
281
282 /**
283 * @param packageManagerInstallStatusURL Package Manager installation status JSON URL
284 */
285 public void setPackageManagerInstallStatusURL(String packageManagerInstallStatusURL) {
286 this.packageManagerInstallStatusURL = packageManagerInstallStatusURL;
287 }
288
289 /**
290 * Number of seconds to wait as maximum for a positive package manager install status check.
291 * If this limit is reached and the packager manager install status is still not positive the install of the package
292 * proceeds anyway.
293 * @return Limit in seconds
294 */
295 public int getPackageManagerInstallStatusWaitLimitSec() {
296 return this.packageManagerInstallStatusWaitLimitSec;
297 }
298
299 /**
300 * @param packageManagerInstallStatusWaitLimitSec Number of seconds to wait as maximum for a positive package manager
301 * install status check
302 */
303 public void setPackageManagerInstallStatusWaitLimitSec(int packageManagerInstallStatusWaitLimitSec) {
304 this.packageManagerInstallStatusWaitLimitSec = packageManagerInstallStatusWaitLimitSec;
305 }
306
307 /**
308 * If set to true also self-signed certificates are accepted.
309 * @return Relaced SSL check
310 */
311 public boolean isRelaxedSSLCheck() {
312 return this.relaxedSSLCheck;
313 }
314
315 /**
316 * @param relaxedSSLCheck If set to true also self-signed certificates are accepted
317 */
318 public void setRelaxedSSLCheck(boolean relaxedSSLCheck) {
319 this.relaxedSSLCheck = relaxedSSLCheck;
320 }
321
322 /**
323 * HTTP connection timeout (in seconds).
324 * @return Timeout
325 */
326 public int getHttpConnectTimeoutSec() {
327 return this.httpConnectTimeoutSec;
328 }
329
330 /**
331 * @param httpConnectTimeoutSec HTTP connection timeout (in seconds)
332 */
333 public void setHttpConnectTimeoutSec(int httpConnectTimeoutSec) {
334 this.httpConnectTimeoutSec = httpConnectTimeoutSec;
335 }
336
337 /**
338 * HTTP socket timeout (in seconds).
339 * @return Timeout
340 */
341 public int getHttpSocketTimeoutSec() {
342 return this.httpSocketTimeoutSec;
343 }
344
345 /**
346 * @param httpSocketTimeoutSec HTTP socket timeout (in seconds)
347 */
348 public void setHttpSocketTimeoutSec(int httpSocketTimeoutSec) {
349 this.httpSocketTimeoutSec = httpSocketTimeoutSec;
350 }
351
352 /**
353 * HTTP proxies from maven settings
354 * @return List of proxies
355 */
356 public List<Proxy> getProxies() {
357 return this.proxies;
358 }
359
360 /**
361 * @param proxies HTTP proxies from maven settings
362 */
363 public void setProxies(List<Proxy> proxies) {
364 this.proxies = proxies;
365 }
366
367 /**
368 * Log level to be used to log responses from package manager (which may get huge for large packages).
369 * @return Log level (DEBUG or INFO). Default is INFO.
370 */
371 public String getPackageManagerOutputLogLevel() {
372 return this.packageManagerOutputLogLevel;
373 }
374
375 /**
376 * @param packageManagerOutputLogLevel Log level to be used to log responses from package manager
377 */
378 public void setPackageManagerOutputLogLevel(String packageManagerOutputLogLevel) {
379 this.packageManagerOutputLogLevel = packageManagerOutputLogLevel;
380 }
381
382 }