use of org.kohsuke.stapler.interceptor.RequirePOST in project configuration-as-code-plugin by jenkinsci.
the class ConfigurationAsCode method doViewExport.
@RequirePOST
@Restricted(NoExternalUse.class)
public void doViewExport(StaplerRequest req, StaplerResponse res) throws Exception {
if (!Jenkins.get().hasPermission(Jenkins.SYSTEM_READ)) {
res.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
export(out);
req.setAttribute("export", out.toString(StandardCharsets.UTF_8.name()));
req.getView(this, "viewExport.jelly").forward(req, res);
}
use of org.kohsuke.stapler.interceptor.RequirePOST in project configuration-as-code-plugin by jenkinsci.
the class ConfigurationAsCode method doCheck.
@RequirePOST
@Restricted(NoExternalUse.class)
public void doCheck(StaplerRequest req, StaplerResponse res) throws Exception {
if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
res.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
final Map<Source, String> issues = checkWith(YamlSource.of(req));
res.setContentType("application/json");
final JSONArray warnings = new JSONArray();
issues.entrySet().stream().map(e -> new JSONObject().accumulate("line", e.getKey().line).accumulate("warning", e.getValue())).forEach(warnings::add);
warnings.write(res.getWriter());
}
Aggregations