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