public PropertiesProcessor getParametersProcessor()

in commit-status-publisher-server/src/main/java/jetbrains/buildServer/commitPublisher/bitbucketCloud/BitbucketCloudSettings.java [123:173]


  public PropertiesProcessor getParametersProcessor(@NotNull BuildTypeIdentity buildTypeOrTemplate) {
    return new PropertiesProcessor() {
      public Collection<InvalidProperty> process(Map<String, String> params) {
        List<InvalidProperty> errors = new ArrayList<InvalidProperty>();

        final String authType = getAuthType(params);
        switch (authType) {
          case Constants.PASSWORD:
            params.remove(Constants.TOKEN_ID);

            if (StringUtil.isEmptyOrSpaces(params.get(Constants.BITBUCKET_CLOUD_USERNAME))) {
              errors.add(new InvalidProperty(Constants.BITBUCKET_CLOUD_USERNAME, "Username must be specified"));
            }

            if (StringUtil.isEmptyOrSpaces(params.get(Constants.BITBUCKET_CLOUD_PASSWORD))) {
              errors.add(new InvalidProperty(Constants.BITBUCKET_CLOUD_PASSWORD, "Password must be specified"));
            }
            break;

          case Constants.AUTH_TYPE_STORED_TOKEN:
            params.remove(Constants.BITBUCKET_CLOUD_USERNAME);
            params.remove(Constants.BITBUCKET_CLOUD_PASSWORD);

            if (StringUtil.isEmpty(params.get(Constants.TOKEN_ID))) {
              errors.add(new InvalidProperty(Constants.TOKEN_ID, "No token configured"));
            }
            break;

          case Constants.AUTH_TYPE_VCS:
            params.remove(Constants.BITBUCKET_CLOUD_USERNAME);
            params.remove(Constants.BITBUCKET_CLOUD_PASSWORD);
            params.remove(Constants.TOKEN_ID);

            String vcsRootId = params.get(Constants.VCS_ROOT_ID_PARAM);
            SVcsRoot vcsRoot = null == vcsRootId ? null : myProjectManager.findVcsRootByExternalId(vcsRootId);
            if (null != vcsRoot) {
              String vcsUrl = vcsRoot.getProperty("url");
              if (!StringUtil.isEmpty(vcsUrl) && !vcsUrl.trim().toLowerCase().startsWith("http"))
                errors.add(new InvalidProperty(Constants.AUTH_TYPE, "Credentials can not be extracted as the selected VCS root uses non-HTTP(S) fetch URL"));
            }

            break;

          default:
            errors.add(new InvalidProperty(Constants.AUTH_TYPE, "Unsupported authentication type"));
        }

        return errors;
      }
    };
  }