jetbrains.buildServer.controllers.BasePropertiesBean Java Examples

The following examples show how to use jetbrains.buildServer.controllers.BasePropertiesBean. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PluginPropertiesUtil.java    From teamcity-kubernetes-plugin with Apache License 2.0 5 votes vote down vote up
public static void bindPropertiesFromRequest(HttpServletRequest request, BasePropertiesBean bean, boolean includeEmptyValues) {
    bean.clearProperties();

    for (final Object o : request.getParameterMap().keySet()) {
        String paramName = (String)o;
        if (paramName.startsWith(PROPERTY_PREFIX)) {
            if (paramName.startsWith(ENCRYPTED_PROPERTY_PREFIX)) {
                setEncryptedProperty(paramName, request, bean, includeEmptyValues);
            } else {
                setStringProperty(paramName, request, bean, includeEmptyValues);
            }
        }
    }
}
 
Example #2
Source File: PluginPropertiesUtil.java    From teamcity-kubernetes-plugin with Apache License 2.0 5 votes vote down vote up
private static void setStringProperty(final String paramName, final HttpServletRequest request,
                                      final BasePropertiesBean bean, final boolean includeEmptyValues) {
    String propName = paramName.substring(PROPERTY_PREFIX.length());
    final String propertyValue = request.getParameter(paramName).trim();
    if (includeEmptyValues || propertyValue.length() > 0) {
        bean.setProperty(propName, toUnixLineFeeds(propertyValue));
    }
}
 
Example #3
Source File: PluginPropertiesUtil.java    From teamcity-kubernetes-plugin with Apache License 2.0 5 votes vote down vote up
private static void setEncryptedProperty(final String paramName, final HttpServletRequest request,
                                         final BasePropertiesBean bean, final boolean includeEmptyValues) {
    String propName = paramName.substring(ENCRYPTED_PROPERTY_PREFIX.length());
    String propertyValue = RSACipher.decryptWebRequestData(request.getParameter(paramName));
    if (propertyValue != null && (includeEmptyValues || propertyValue.length() > 0)) {
        bean.setProperty(propName, toUnixLineFeeds(propertyValue));
    }
}
 
Example #4
Source File: VMWareEditProfileController.java    From teamcity-vmware-plugin with Apache License 2.0 5 votes vote down vote up
@Override
protected void doPost(@NotNull final HttpServletRequest request, @NotNull final HttpServletResponse response, @NotNull final Element xmlResponse) {
  final ActionErrors errors = new ActionErrors();

  final BasePropertiesBean propsBean = new BasePropertiesBean(null);
  PluginPropertiesUtil.bindPropertiesFromRequest(request, propsBean, true);

  final Map<String, String> props = propsBean.getProperties();
  final String serverUrl = props.get(VMWareWebConstants.SERVER_URL);
  final String username = props.get(VMWareWebConstants.USERNAME);
  final String password = props.get(VMWareWebConstants.SECURE_PASSWORD);

  try {
    final VMWareApiConnector myApiConnector = VmwareApiConnectorsPool.getOrCreateConnector(
      new URL(serverUrl), username, password, null, null, null, mySslTrustStoreProvider);
    myApiConnector.test();
    xmlResponse.addContent(getVirtualMachinesAsElement(myApiConnector.getVirtualMachines(true)));
    xmlResponse.addContent(getFoldersAsElement(myApiConnector.getFolders()));
    xmlResponse.addContent(getResourcePoolsAsElement(myApiConnector.getResourcePools()));
    xmlResponse.addContent(getCustomizationSpecsAsElement(myApiConnector.getCustomizationSpecs()));
  } catch (Exception ex) {
    LOG.warnAndDebugDetails("Unable to get vCenter details: " + ex.toString(), ex);
    if (ex.getCause() != null && ex.getCause() instanceof SSLException){
      errors.addError(
        "errorFetchResultsSSL",
        VmwareErrorMessages.getInstance().getFriendlyErrorMessage(
          ex, "Please check the connection parameters. See the teamcity-clouds.log for details"
        )
      );
    } else {
      errors.addError(
        "errorFetchResults",
        VmwareErrorMessages.getInstance().getFriendlyErrorMessage(
          ex, "Please check the connection parameters. See the teamcity-clouds.log for details")
      );
    }
    writeErrors(xmlResponse, errors);
  }
}
 
Example #5
Source File: PluginPropertiesUtil.java    From teamcity-kubernetes-plugin with Apache License 2.0 4 votes vote down vote up
public static void bindPropertiesFromRequest(HttpServletRequest request, BasePropertiesBean bean) {
    bindPropertiesFromRequest(request, bean, false);
}
 
Example #6
Source File: ChooserController.java    From teamcity-kubernetes-plugin with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
protected ModelAndView doHandle(@NotNull HttpServletRequest httpServletRequest, @NotNull HttpServletResponse httpServletResponse) throws Exception {
    BasePropertiesBean propsBean = new BasePropertiesBean(null);
    PluginPropertiesUtil.bindPropertiesFromRequest(httpServletRequest, propsBean, true);
    Map<String, String> props = propsBean.getProperties();

    KubeApiConnection apiConnection = new KubeApiConnection() {
        @NotNull
        @Override
        public String getApiServerUrl() {
            return props.get(API_SERVER_URL);
        }

        @NotNull
        @Override
        public String getNamespace() {
            String explicitNameSpace = props.get(KUBERNETES_NAMESPACE);
            return StringUtil.isEmpty(explicitNameSpace) ? DEFAULT_NAMESPACE : explicitNameSpace;
        }

        @Nullable
        @Override
        public String getCustomParameter(@NotNull String parameterName) {
            return props.containsKey(parameterName) ? props.get(parameterName) : props.get(SECURE_PROPERTY_PREFIX + parameterName);
        }

        @Nullable
        @Override
        public String getCACertData() {
            return props.get(SECURE_PROPERTY_PREFIX + CA_CERT_DATA);
        }
    };
    String authStrategy = props.get(AUTH_STRATEGY);

    ModelAndView modelAndView = new ModelAndView(myPluginDescriptor.getPluginResourcesPath(getJspName()));
    try {
        KubeApiConnector apiConnector = new KubeApiConnectorImpl("editProfile", apiConnection, myAuthStrategyProvider.get(authStrategy));
        modelAndView.getModelMap().put(getItemsName(), getItems(apiConnector));
        modelAndView.getModelMap().put("error","");
    } catch (Exception ex){
        modelAndView.getModelMap().put(getItemsName(), Collections.emptyList());
        if (ex.getCause() != null) {
            modelAndView.getModelMap().put("error", ex.getCause().getLocalizedMessage());
        } else {
            modelAndView.getModelMap().put("error", ex.getLocalizedMessage());
        }
    }
    return modelAndView;
}
 
Example #7
Source File: S3SettingsController.java    From teamcity-s3-artifact-storage-plugin with Apache License 2.0 4 votes vote down vote up
private Map<String, String> getProperties(final HttpServletRequest request) {
  final BasePropertiesBean propsBean = new BasePropertiesBean(null);
  S3StoragePropertiesUtil.bindPropertiesFromRequest(request, propsBean);
  return propsBean.getProperties();
}
 
Example #8
Source File: S3StoragePropertiesUtil.java    From teamcity-s3-artifact-storage-plugin with Apache License 2.0 4 votes vote down vote up
public static void bindPropertiesFromRequest(HttpServletRequest request, BasePropertiesBean bean) {
  final Map<String, String> properties = parsePropertiesFromRequest(request);
  bindProperties(bean, properties);
}
 
Example #9
Source File: S3StoragePropertiesUtil.java    From teamcity-s3-artifact-storage-plugin with Apache License 2.0 4 votes vote down vote up
private static void bindProperties(@NotNull final BasePropertiesBean bean, @NotNull final Map<String, String> properties) {
  bean.clearProperties();
  for (final Map.Entry<String, String> property : properties.entrySet()) {
    bean.setProperty(property.getKey(), property.getValue());
  }
}