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);
}
Aggregations