Search in sources :

Example 1 with CheckConnectionSubprocessExecutionContext

use of com.thoughtworks.go.server.service.CheckConnectionSubprocessExecutionContext in project gocd by gocd.

the class AbstractMaterialTestController method testConnection.

public String testConnection(Request request, Response response) {
    JsonReader jsonReader = GsonTransformer.getInstance().jsonReaderFrom(request.body());
    String type = jsonReader.getString("type");
    String pipelineName = jsonReader.getStringOrDefault("pipeline_name", "");
    String pipelineGroupName = jsonReader.getStringOrDefault("pipeline_group", "");
    haltIfMaterialTypeIsInvalid(type);
    haltIfMaterialTypeDoesNotSupportsCheckConnection(type);
    ScmMaterialConfig scmMaterialConfig = buildSCMMaterialFromRequestBody(request);
    validateMaterialConfig(scmMaterialConfig, pipelineName, pipelineGroupName);
    if (!scmMaterialConfig.errors().isEmpty()) {
        List<String> errorsList = new ArrayList<>();
        scmMaterialConfig.errors().forEach((key, errors) -> errorsList.add(String.format("- %s: %s", key, StringUtils.join(errors, ", "))));
        response.status(422);
        return MessageJson.create(String.format("There was an error with the material configuration.\n%s", StringUtils.join(errorsList, "\n")), jsonWriter(scmMaterialConfig));
    }
    performParamExpansion(scmMaterialConfig, pipelineName);
    Material material = materialConfigConverter.toMaterial(scmMaterialConfig);
    resolveSecrets(pipelineGroupName, material);
    ValidationBean validationBean = material.checkConnection(new CheckConnectionSubprocessExecutionContext(systemEnvironment));
    return handleValidationBeanResponse(validationBean, response);
}
Also used : ArrayList(java.util.ArrayList) JsonReader(com.thoughtworks.go.api.representers.JsonReader) Material(com.thoughtworks.go.domain.materials.Material) ScmMaterial(com.thoughtworks.go.config.materials.ScmMaterial) CheckConnectionSubprocessExecutionContext(com.thoughtworks.go.server.service.CheckConnectionSubprocessExecutionContext) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) ValidationBean(com.thoughtworks.go.domain.materials.ValidationBean) ScmMaterialConfig(com.thoughtworks.go.config.materials.ScmMaterialConfig)

Aggregations

JsonReader (com.thoughtworks.go.api.representers.JsonReader)1 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)1 ScmMaterial (com.thoughtworks.go.config.materials.ScmMaterial)1 ScmMaterialConfig (com.thoughtworks.go.config.materials.ScmMaterialConfig)1 Material (com.thoughtworks.go.domain.materials.Material)1 ValidationBean (com.thoughtworks.go.domain.materials.ValidationBean)1 CheckConnectionSubprocessExecutionContext (com.thoughtworks.go.server.service.CheckConnectionSubprocessExecutionContext)1 ArrayList (java.util.ArrayList)1