use of com.thoughtworks.go.plugin.access.configrepo.ExportedConfig in project gocd by gocd.
the class PipelinesAsCodeInternalControllerV1 method preview.
String preview(Request req, Response res) {
ConfigRepoPlugin repoPlugin = pluginFromRequest(req);
String pluginId = repoPlugin.id();
String groupName = requiredQueryParam(req, "group");
if (!pluginService.supportsPipelineExport(pluginId)) {
throw haltBecauseOfReason("Plugin `%s` does not support pipeline config export.", pluginId);
}
ConfigHelperOptions options = new ConfigHelperOptions(goConfigService.getCurrentConfig(), passwordDeserializer);
JsonReader jsonReader = GsonTransformer.getInstance().jsonReaderFrom(req.body());
validateNamePresent(jsonReader);
PipelineConfig pipeline = PipelineConfigRepresenter.fromJSON(jsonReader, options);
if (requiresFullValidation(req) && !isValidPipelineConfig(pipeline, groupName)) {
res.status(HttpStatus.UNPROCESSABLE_ENTITY.value());
return MessageJson.create(format("Please fix the validation errors for pipeline %s.", pipeline.name()), jsonWriter(pipeline));
}
String etag = entityHashingService.hashForEntity(pipeline, groupName, pluginId);
if (fresh(req, etag)) {
return notModified(res);
} else {
setEtagHeader(res, etag);
ExportedConfig export = repoPlugin.pipelineExport(pipeline, groupName);
res.header("Content-Type", export.getContentType());
res.header("Content-Disposition", format("attachment; filename=\"%s\"", export.getFilename()));
return export.getContent();
}
}
use of com.thoughtworks.go.plugin.access.configrepo.ExportedConfig in project gocd by gocd.
the class ExportControllerV1 method exportPipeline.
public String exportPipeline(Request req, Response res) {
PipelineConfig pipelineConfig = pipelineConfigFromRequest(req);
String pluginId = requiredQueryParam(req, "plugin_id");
String groupName = configService.findGroupNameByPipeline(pipelineConfig.getName());
if (!crPluginService.isConfigRepoPlugin(pluginId)) {
throw haltBecauseOfReason("Plugin `%s` is not a config-repo plugin.", pluginId);
}
if (!crPluginService.supportsPipelineExport(pluginId)) {
throw haltBecauseOfReason("Plugin `%s` does not support pipeline config export.", pluginId);
}
ConfigRepoPlugin repoPlugin = crPlugin(pluginId);
String etag = entityHashingService.hashForEntity(pipelineConfig, groupName, pluginId);
if (fresh(req, etag)) {
return notModified(res);
} else {
setEtagHeader(res, etag);
ExportedConfig export = repoPlugin.pipelineExport(pipelineConfig, groupName);
res.header("Content-Type", export.getContentType());
res.header("Content-Disposition", format("attachment; filename=\"%s\"", export.getFilename()));
return export.getContent();
}
}
Aggregations