use of com.thoughtworks.go.plugin.access.configrepo.ConfigFileList in project gocd by gocd.
the class PipelinesAsCodeInternalControllerV1 method configFiles.
String configFiles(Request req, Response res) {
ConfigRepoPlugin repoPlugin = pluginFromRequest(req);
File folder = null;
try {
JsonReader jsonReader = GsonTransformer.getInstance().jsonReaderFrom(req.body());
ConfigHelperOptions options = new ConfigHelperOptions(goConfigService.getCurrentConfig(), passwordDeserializer);
MaterialConfig materialConfig = MaterialsRepresenter.fromJSON(jsonReader, options);
if (!(materialConfig instanceof ScmMaterialConfig)) {
res.status(HttpStatus.UNPROCESSABLE_ENTITY.value());
return MessageJson.create(format("This material check requires an SCM repository; instead, supplied material was of type: %s", materialConfig.getType()));
}
validateMaterial(materialConfig);
if (materialConfig.errors().present()) {
res.status(HttpStatus.UNPROCESSABLE_ENTITY.value());
return MessageJson.create(format("Please fix the following SCM configuration errors: %s", materialConfig.errors().asString()));
}
if (configRepoService.hasConfigRepoByFingerprint(materialConfig.getFingerprint())) {
res.status(HttpStatus.CONFLICT.value());
return MessageJson.create("Material is already being used as a config repository");
}
folder = FileUtil.createTempFolder();
checkoutFromMaterialConfig(materialConfig, folder);
final Map<String, ConfigFileList> pacPluginFiles = Collections.singletonMap(repoPlugin.id(), repoPlugin.getConfigFiles(folder, new ArrayList<>()));
return jsonizeAsTopLevelObject(req, w -> ConfigFileListsRepresenter.toJSON(w, pacPluginFiles));
} catch (TimeoutException e) {
res.status(HttpStatus.PAYLOAD_TOO_LARGE.value());
return MessageJson.create("Aborted check because cloning the SCM repository took too long");
} catch (ExecutionException e) {
res.status(HttpStatus.INTERNAL_SERVER_ERROR.value());
// unwrap these exceptions thrown by the future
return MessageJson.create(e.getCause().getMessage());
} catch (Exception e) {
res.status(HttpStatus.INTERNAL_SERVER_ERROR.value());
return MessageJson.create(e.getMessage());
} finally {
if (null != folder) {
FileUtils.deleteQuietly(folder);
}
}
}
Aggregations