From cf4c8eb9781e26b4f8ebd954d6ac1a3607b7f048 Mon Sep 17 00:00:00 2001 From: Emilio Escobar Date: Mon, 25 Nov 2019 19:11:46 +0100 Subject: [PATCH] =?UTF-8?q?Make=20the=20`io.jenkins.plugins.casc.Configura?= =?UTF-8?q?tionAsCode`=20API=20avai=E2=80=A6=20(#1203)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [issue-1202] Removed ConfigurationAsCode restriction * Added restriction to doXX and public methods * All public methods should be restricted. --- .../jenkins/plugins/casc/ConfigurationAsCode.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/plugin/src/main/java/io/jenkins/plugins/casc/ConfigurationAsCode.java b/plugin/src/main/java/io/jenkins/plugins/casc/ConfigurationAsCode.java index c55bcc2ded..5ef8d94479 100644 --- a/plugin/src/main/java/io/jenkins/plugins/casc/ConfigurationAsCode.java +++ b/plugin/src/main/java/io/jenkins/plugins/casc/ConfigurationAsCode.java @@ -99,7 +99,6 @@ * @author Nicolas De Loof */ @Extension -@Restricted(NoExternalUse.class) public class ConfigurationAsCode extends ManagementLink { public static final String CASC_JENKINS_CONFIG_PROPERTY = "casc.jenkins.config"; @@ -148,6 +147,7 @@ public List getSources() { } @RequirePOST + @Restricted(NoExternalUse.class) public void doReload(StaplerRequest request, StaplerResponse response) throws Exception { if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) { response.sendError(HttpServletResponse.SC_FORBIDDEN); @@ -158,6 +158,7 @@ public void doReload(StaplerRequest request, StaplerResponse response) throws Ex } @RequirePOST + @Restricted(NoExternalUse.class) public void doReplace(StaplerRequest request, StaplerResponse response) throws Exception { if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) { response.sendError(HttpServletResponse.SC_FORBIDDEN); @@ -201,6 +202,7 @@ private boolean canApplyFrom(List yamlSources) { } @POST + @Restricted(NoExternalUse.class) public FormValidation doCheckNewSource(@QueryParameter String newSource) { Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER); String normalizedSource = Util.fixEmptyAndTrim(newSource); @@ -267,6 +269,7 @@ private List getConfigFromSources(List newSources) throws Co * * @throws Exception when the file provided cannot be found or parsed */ + @Restricted(NoExternalUse.class) @Initializer(after = InitMilestone.EXTENSIONS_AUGMENTED, before = InitMilestone.JOB_LOADED) public static void init() throws Exception { detectVaultPluginMissing(); @@ -325,6 +328,7 @@ private List getStandardConfig() { return configParameters; } + @Restricted(NoExternalUse.class) public List getBundledCasCURIs() { final String cascFile = "/WEB-INF/" + DEFAULT_JENKINS_YAML_PATH; final String cascDirectory = "/WEB-INF/" + DEFAULT_JENKINS_YAML_PATH + ".d/"; @@ -360,6 +364,7 @@ public List getBundledCasCURIs() { } @RequirePOST + @Restricted(NoExternalUse.class) public void doCheck(StaplerRequest req, StaplerResponse res) throws Exception { if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) { @@ -376,6 +381,7 @@ public void doCheck(StaplerRequest req, StaplerResponse res) throws Exception { } @RequirePOST + @Restricted(NoExternalUse.class) public void doApply(StaplerRequest req, StaplerResponse res) throws Exception { if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) { @@ -390,6 +396,7 @@ public void doApply(StaplerRequest req, StaplerResponse res) throws Exception { * @throws Exception */ @RequirePOST + @Restricted(NoExternalUse.class) public void doExport(StaplerRequest req, StaplerResponse res) throws Exception { if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) { @@ -406,6 +413,7 @@ public void doExport(StaplerRequest req, StaplerResponse res) throws Exception { * Export JSONSchema to URL * @throws Exception */ + @Restricted(NoExternalUse.class) public void doSchema(StaplerRequest req, StaplerResponse res) throws Exception { if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) { @@ -418,6 +426,7 @@ public void doSchema(StaplerRequest req, StaplerResponse res) throws Exception { } @RequirePOST + @Restricted(NoExternalUse.class) public void doViewExport(StaplerRequest req, StaplerResponse res) throws Exception { if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) { res.sendError(HttpServletResponse.SC_FORBIDDEN); @@ -431,6 +440,7 @@ public void doViewExport(StaplerRequest req, StaplerResponse res) throws Excepti req.getView(this, "viewExport.jelly").forward(req, res); } + @Restricted(NoExternalUse.class) public void doReference(StaplerRequest req, StaplerResponse res) throws Exception { if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) { res.sendError(HttpServletResponse.SC_FORBIDDEN); @@ -622,6 +632,7 @@ private void closeSources(List sources) { * @param path base path to start (can be file or directory) * @return list of all paths matching pattern. Only base file itself if it is a file matching pattern */ + @Restricted(NoExternalUse.class) public List configs(String path) throws ConfiguratorException { final Path root = Paths.get(path); @@ -783,6 +794,7 @@ private void listElements(Set elements, Set> attributes, * @return String that shows help. May be empty * @throws IOException if the resource cannot be read */ + @Restricted(NoExternalUse.class) @NonNull public String getHtmlHelp(Class type, String attribute) throws IOException { final URL resource = Klass.java(type).getResource("help-" + attribute + ".html"); @@ -797,6 +809,7 @@ public String getHtmlHelp(Class type, String attribute) throws IOException { * * @return String representation of the extension source, usually artifactId. */ + @Restricted(NoExternalUse.class) @CheckForNull public String getExtensionSource(Configurator c) throws IOException { final Class e = c.getImplementedAPI();