PackageManagerProperties.java

  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. import java.util.Collections;
  22. import java.util.List;
  23. import java.util.regex.Pattern;
  24. import java.util.stream.Collectors;

  25. import org.apache.commons.lang3.StringUtils;

  26. /**
  27.  * Configuration properties for {@link PackageManagerHelper}.
  28.  */
  29. public final class PackageManagerProperties {

  30.   private String packageManagerUrl;
  31.   private String userId;
  32.   private String password;
  33.   private String oauth2AccessToken;
  34.   private String consoleUserId;
  35.   private String consolePassword;
  36.   private String consoleOauth2AccessToken;
  37.   private int retryCount = 24;
  38.   private int retryDelaySec = 5;
  39.   private String bundleStatusUrl;
  40.   private int bundleStatusWaitLimitSec = 360;
  41.   private List<Pattern> bundleStatusBlacklistBundleNames = Collections.emptyList();
  42.   private List<Pattern> bundleStatusWhitelistBundleNames = Collections.emptyList();
  43.   private String packageManagerInstallStatusURL;
  44.   private int packageManagerInstallStatusWaitLimitSec = 360;
  45.   private boolean relaxedSSLCheck;
  46.   private int httpConnectTimeoutSec = 10;
  47.   private int httpSocketTimeoutSec = 60;
  48.   private List<Proxy> proxies;
  49.   private String packageManagerOutputLogLevel = "INFO";

  50.   /**
  51.    * The URL of the HTTP service API of the CRX package manager.
  52.    * See <a href=
  53.    * "https://docs.adobe.com/content/docs/en/crx/2-3/how_to/package_manager.html#Managing%20Packages%20on%20the%20Command%20Line">CRX
  54.    * HTTP service Interface</a> for details on this interface.
  55.    * @return URL
  56.    */
  57.   public String getPackageManagerUrl() {
  58.     return this.packageManagerUrl;
  59.   }

  60.   public void setPackageManagerUrl(String packageManagerUrl) {
  61.     this.packageManagerUrl = packageManagerUrl;
  62.   }

  63.   /**
  64.    * The user name to authenticate as against the remote CRX system (package manager).
  65.    * @return User ID
  66.    */
  67.   public String getUserId() {
  68.     return this.userId;
  69.   }

  70.   public void setUserId(String userId) {
  71.     this.userId = userId;
  72.   }

  73.   /**
  74.    * The password to authenticate against the remote CRX system (package manager).
  75.    * @return Password
  76.    */
  77.   public String getPassword() {
  78.     return this.password;
  79.   }

  80.   public void setPassword(String password) {
  81.     this.password = password;
  82.   }

  83.   /**
  84.    * OAuth 2 access token to authenticate against the remote CRX system (package manager).
  85.    * If this is configured, username and password are ignored.
  86.    * @return OAuth 2 access token.
  87.    */
  88.   public String getOAuth2AccessToken() {
  89.     return this.oauth2AccessToken;
  90.   }


  91.   public void setOAuth2AccessToken(String value) {
  92.     this.oauth2AccessToken = value;
  93.   }

  94.   /**
  95.    * The user name to authenticate as against the remote CRX system (Felix console).
  96.    * Fallback to {@link #getUserId()} if not set.
  97.    * @return User ID
  98.    */
  99.   public String getConsoleUserId() {
  100.     return StringUtils.defaultString(this.consoleUserId, this.userId);
  101.   }

  102.   public void setConsoleUserId(String consoleUserId) {
  103.     this.consoleUserId = consoleUserId;
  104.   }

  105.   /**
  106.    * The password to authenticate against the remote CRX system (Felix console).
  107.    * Fallback to {@link #getPassword()} if not set.
  108.    * @return Password
  109.    */
  110.   public String getConsolePassword() {
  111.     return StringUtils.defaultString(this.consolePassword, this.password);
  112.   }

  113.   public void setConsolePassword(String consolePassword) {
  114.     this.consolePassword = consolePassword;
  115.   }

  116.   /**
  117.    * OAuth 2 access token to authenticate against the remote CRX system (Felix console).
  118.    * If this is configured, username and password are ignored.
  119.    * Fallback to {@link #getOAuth2AccessToken()} if not set.
  120.    * @return OAuth 2 access token.
  121.    */
  122.   public String getConsoleOAuth2AccessToken() {
  123.     return StringUtils.defaultString(this.consoleOauth2AccessToken, this.oauth2AccessToken);
  124.   }


  125.   public void setConsoleOAuth2AccessToken(String value) {
  126.     this.consoleOauth2AccessToken = value;
  127.   }

  128.   /**
  129.    * Number of times to retry upload and install via CRX HTTP interface if it fails.
  130.    * @return Retry count
  131.    */
  132.   public int getRetryCount() {
  133.     return this.retryCount;
  134.   }

  135.   public void setRetryCount(int retryCount) {
  136.     this.retryCount = retryCount;
  137.   }

  138.   /**
  139.    * Number of seconds between retry attempts.
  140.    * @return Retry delay
  141.    */
  142.   public int getRetryDelaySec() {
  143.     return this.retryDelaySec;
  144.   }

  145.   public void setRetryDelaySec(int retryDelaySec) {
  146.     this.retryDelaySec = retryDelaySec;
  147.   }

  148.   /**
  149.    * Bundle status JSON URL. If an URL is configured the activation status of all bundles in the system is checked
  150.    * before it is tried to upload and install a new package and after each upload.
  151.    * If not all bundles are activated the upload is delayed up to {link #getBundleStatusWaitLimitSec()} seconds, every 5
  152.    * seconds the activation status is checked anew.
  153.    * Expected is an URL like: http://localhost:4502/system/console/bundles/.json
  154.    * @return URL
  155.    */
  156.   public String getBundleStatusUrl() {
  157.     return this.bundleStatusUrl;
  158.   }

  159.   public void setBundleStatusUrl(String bundleStatusUrl) {
  160.     this.bundleStatusUrl = bundleStatusUrl;
  161.   }

  162.   /**
  163.    * Number of seconds to wait as maximum for a positive bundle status check.
  164.    * If this limit is reached and the bundle status is still not positive the install of the package proceeds anyway.
  165.    * @return Limit in seconds
  166.    */
  167.   public int getBundleStatusWaitLimitSec() {
  168.     return this.bundleStatusWaitLimitSec;
  169.   }

  170.   public void setBundleStatusWaitLimitSec(int bundleStatusWaitLimitSec) {
  171.     this.bundleStatusWaitLimitSec = bundleStatusWaitLimitSec;
  172.   }

  173.   /**
  174.    * Patterns for symbolic names of bundles that are expected to be not present in bundle list.
  175.    * If any of these bundles are found in the bundle list, this system is assumed as not ready for installing further
  176.    * packages because a previous installation (e.g. of AEM service pack) is still in progress.
  177.    * @return List of regular expressions for symbolic bundle names.
  178.    */
  179.   public List<Pattern> getBundleStatusBlacklistBundleNames() {
  180.     return this.bundleStatusBlacklistBundleNames;
  181.   }

  182.   public void setBundleStatusBlacklistBundleNames(List<String> bundleStatusBlacklistBundleNames) {
  183.     this.bundleStatusBlacklistBundleNames = bundleStatusBlacklistBundleNames.stream()
  184.         .map(Pattern::compile)
  185.         .collect(Collectors.toList());
  186.   }

  187.   /**
  188.    * Patterns for symbolic names of bundles that are ignored in bundle list.
  189.    * The state of these bundles has no effect on the bundle status check.
  190.    * @return List of regular expressions for symbolic bundle names.
  191.    */
  192.   public List<Pattern> getBundleStatusWhitelistBundleNames() {
  193.     return this.bundleStatusWhitelistBundleNames;
  194.   }

  195.   public void setBundleStatusWhitelistBundleNames(List<String> bundleStatusWhitelistBundleNames) {
  196.     this.bundleStatusWhitelistBundleNames = bundleStatusWhitelistBundleNames.stream()
  197.         .map(Pattern::compile)
  198.         .collect(Collectors.toList());
  199.   }

  200.   /**
  201.    * Package Manager installation status JSON URL. If an URL is configured the installation status of packages and
  202.    * embedded packages is checked before it is tried to upload and install a new package and after each upload.
  203.    * If not all packages are installed the upload is delayed up to {link #getPackageManagerInstallStatusWaitLimit()}
  204.    * seconds, every 5 seconds the activation status is checked anew.
  205.    * Expected is an URL like: http://localhost:4502/crx/packmgr/installstatus.jsp
  206.    * @return URL
  207.    */
  208.   public String getPackageManagerInstallStatusURL() {
  209.     return this.packageManagerInstallStatusURL;
  210.   }


  211.   public void setPackageManagerInstallStatusURL(String packageManagerInstallStatusURL) {
  212.     this.packageManagerInstallStatusURL = packageManagerInstallStatusURL;
  213.   }

  214.   /**
  215.    * Number of seconds to wait as maximum for a positive package manager install status check.
  216.    * If this limit is reached and the packager manager install status is still not positive the install of the package
  217.    * proceeds anyway.
  218.    * @return Limit in seconds
  219.    */
  220.   public int getPackageManagerInstallStatusWaitLimitSec() {
  221.     return this.packageManagerInstallStatusWaitLimitSec;
  222.   }


  223.   public void setPackageManagerInstallStatusWaitLimitSec(int packageManagerInstallStatusWaitLimitSec) {
  224.     this.packageManagerInstallStatusWaitLimitSec = packageManagerInstallStatusWaitLimitSec;
  225.   }

  226.   /**
  227.    * If set to true also self-signed certificates are accepted.
  228.    * @return Relaced SSL check
  229.    */
  230.   public boolean isRelaxedSSLCheck() {
  231.     return this.relaxedSSLCheck;
  232.   }

  233.   public void setRelaxedSSLCheck(boolean relaxedSSLCheck) {
  234.     this.relaxedSSLCheck = relaxedSSLCheck;
  235.   }

  236.   /**
  237.    * HTTP connection timeout (in seconds).
  238.    * @return Timeout
  239.    */
  240.   public int getHttpConnectTimeoutSec() {
  241.     return this.httpConnectTimeoutSec;
  242.   }

  243.   public void setHttpConnectTimeoutSec(int httpConnectTimeoutSec) {
  244.     this.httpConnectTimeoutSec = httpConnectTimeoutSec;
  245.   }

  246.   /**
  247.    * HTTP socket timeout (in seconds).
  248.    * @return Timeout
  249.    */
  250.   public int getHttpSocketTimeoutSec() {
  251.     return this.httpSocketTimeoutSec;
  252.   }

  253.   public void setHttpSocketTimeoutSec(int httpSocketTimeoutSec) {
  254.     this.httpSocketTimeoutSec = httpSocketTimeoutSec;
  255.   }

  256.   /**
  257.    * HTTP proxies from maven settings
  258.    * @return List of proxies
  259.    */
  260.   public List<Proxy> getProxies() {
  261.     return this.proxies;
  262.   }

  263.   public void setProxies(List<Proxy> proxies) {
  264.     this.proxies = proxies;
  265.   }

  266.   /**
  267.    * Log level to be used to log responses from package manager (which may get huge for large packages).
  268.    * @return Log level (DEBUG or INFO). Default is INFO.
  269.    */
  270.   public String getPackageManagerOutputLogLevel() {
  271.     return this.packageManagerOutputLogLevel;
  272.   }

  273.   public void setPackageManagerOutputLogLevel(String packageManagerOutputLogLevel) {
  274.     this.packageManagerOutputLogLevel = packageManagerOutputLogLevel;
  275.   }

  276. }