Search in sources :

Example 11 with RequirePOST

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);
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) RequirePOST(org.kohsuke.stapler.interceptor.RequirePOST) Restricted(org.kohsuke.accmod.Restricted)

Example 12 with RequirePOST

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());
}
Also used : Sequence(io.jenkins.plugins.casc.model.Sequence) Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) SequenceNode(org.yaml.snakeyaml.nodes.SequenceNode) URL(java.net.URL) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) Scanner(java.util.Scanner) CNode(io.jenkins.plugins.casc.model.CNode) Mapping(io.jenkins.plugins.casc.model.Mapping) Which(hudson.remoting.Which) Node(org.yaml.snakeyaml.nodes.Node) Initializer(hudson.init.Initializer) NonNull(edu.umd.cs.findbugs.annotations.NonNull) Map(java.util.Map) PathMatcher(java.nio.file.PathMatcher) Scalar(io.jenkins.plugins.casc.model.Scalar) URI(java.net.URI) GlobalConfiguration(jenkins.model.GlobalConfiguration) Path(java.nio.file.Path) Functions(hudson.Functions) Restricted(org.kohsuke.accmod.Restricted) Collection(java.util.Collection) Jenkins(jenkins.model.Jenkins) Set(java.util.Set) YamlSource(io.jenkins.plugins.casc.yaml.YamlSource) Logger(java.util.logging.Logger) StandardCharsets(java.nio.charset.StandardCharsets) String.format(java.lang.String.format) Objects(java.util.Objects) IOUtils(org.apache.commons.io.IOUtils) Serializer(org.yaml.snakeyaml.serializer.Serializer) YamlUtils(io.jenkins.plugins.casc.yaml.YamlUtils) List(java.util.List) POST(org.kohsuke.stapler.verb.POST) Stream(java.util.stream.Stream) Writer(java.io.Writer) SchemaGeneration.writeJSONSchema(io.jenkins.plugins.casc.SchemaGeneration.writeJSONSchema) InitMilestone(hudson.init.InitMilestone) Source(io.jenkins.plugins.casc.model.Source) JSONObject(net.sf.json.JSONObject) Permission(hudson.security.Permission) YAMLException(org.yaml.snakeyaml.error.YAMLException) IntStream(java.util.stream.IntStream) Format(io.jenkins.plugins.casc.model.Scalar.Format) ByteArrayOutputStream(java.io.ByteArrayOutputStream) QueryParameter(org.kohsuke.stapler.QueryParameter) StaplerRequest(org.kohsuke.stapler.StaplerRequest) HashMap(java.util.HashMap) PLAIN(org.yaml.snakeyaml.DumperOptions.ScalarStyle.PLAIN) TreeSet(java.util.TreeSet) MappingNode(org.yaml.snakeyaml.nodes.MappingNode) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) Inject(javax.inject.Inject) DumperOptions(org.yaml.snakeyaml.DumperOptions) ACLContext(hudson.security.ACLContext) ACL(hudson.security.ACL) RequirePOST(org.kohsuke.stapler.interceptor.RequirePOST) Extension(hudson.Extension) OutputStreamWriter(java.io.OutputStreamWriter) Resolver(org.yaml.snakeyaml.resolver.Resolver) DOUBLE_QUOTED(org.yaml.snakeyaml.DumperOptions.ScalarStyle.DOUBLE_QUOTED) LinkedHashSet(java.util.LinkedHashSet) Util(hudson.Util) OutputStream(java.io.OutputStream) Iterator(java.util.Iterator) Files(java.nio.file.Files) FormValidation(hudson.util.FormValidation) HttpServletResponse(javax.servlet.http.HttpServletResponse) ManagementLink(hudson.model.ManagementLink) NoExternalUse(org.kohsuke.accmod.restrictions.NoExternalUse) StaplerResponse(org.kohsuke.stapler.StaplerResponse) IOException(java.io.IOException) Tag(org.yaml.snakeyaml.nodes.Tag) File(java.io.File) NodeTuple(org.yaml.snakeyaml.nodes.NodeTuple) Klass(org.kohsuke.stapler.lang.Klass) Collectors.toList(java.util.stream.Collectors.toList) PluginManager(hudson.PluginManager) FileVisitOption(java.nio.file.FileVisitOption) Paths(java.nio.file.Paths) JSONArray(net.sf.json.JSONArray) Emitter(org.yaml.snakeyaml.emitter.Emitter) DefaultConfiguratorRegistry(io.jenkins.plugins.casc.impl.DefaultConfiguratorRegistry) ScalarNode(org.yaml.snakeyaml.nodes.ScalarNode) ServletContext(javax.servlet.ServletContext) CheckForNull(edu.umd.cs.findbugs.annotations.CheckForNull) LITERAL(org.yaml.snakeyaml.DumperOptions.ScalarStyle.LITERAL) Collections(java.util.Collections) BLOCK(org.yaml.snakeyaml.DumperOptions.FlowStyle.BLOCK) FileSystems(java.nio.file.FileSystems) JSONObject(net.sf.json.JSONObject) JSONArray(net.sf.json.JSONArray) YamlSource(io.jenkins.plugins.casc.yaml.YamlSource) Source(io.jenkins.plugins.casc.model.Source) RequirePOST(org.kohsuke.stapler.interceptor.RequirePOST) Restricted(org.kohsuke.accmod.Restricted)

Aggregations

RequirePOST (org.kohsuke.stapler.interceptor.RequirePOST)12 JSONObject (net.sf.json.JSONObject)7 File (java.io.File)4 Restricted (org.kohsuke.accmod.Restricted)4 ACLContext (hudson.security.ACLContext)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 YamlSource (io.jenkins.plugins.casc.yaml.YamlSource)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Component (com.cloudbees.jenkins.support.api.Component)1 ComponentVisitor (com.cloudbees.jenkins.support.api.ComponentVisitor)1 Container (com.cloudbees.jenkins.support.api.Container)1 ObjectComponent (com.cloudbees.jenkins.support.api.ObjectComponent)1 CheckForNull (edu.umd.cs.findbugs.annotations.CheckForNull)1 NonNull (edu.umd.cs.findbugs.annotations.NonNull)1 Extension (hudson.Extension)1 Functions (hudson.Functions)1 PluginManager (hudson.PluginManager)1