Search in sources :

Example 1 with ExportedConfig

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();
    }
}
Also used : ExportedConfig(com.thoughtworks.go.plugin.access.configrepo.ExportedConfig) JsonReader(com.thoughtworks.go.api.representers.JsonReader) ConfigHelperOptions(com.thoughtworks.go.apiv10.admin.shared.representers.stages.ConfigHelperOptions)

Example 2 with ExportedConfig

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();
    }
}
Also used : ExportedConfig(com.thoughtworks.go.plugin.access.configrepo.ExportedConfig) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) ConfigRepoPlugin(com.thoughtworks.go.config.ConfigRepoPlugin)

Aggregations

ExportedConfig (com.thoughtworks.go.plugin.access.configrepo.ExportedConfig)2 JsonReader (com.thoughtworks.go.api.representers.JsonReader)1 ConfigHelperOptions (com.thoughtworks.go.apiv10.admin.shared.representers.stages.ConfigHelperOptions)1 ConfigRepoPlugin (com.thoughtworks.go.config.ConfigRepoPlugin)1 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)1