Skip to content

Commit

Permalink
Make the io.jenkins.plugins.casc.ConfigurationAsCode API avai… (#1203)
Browse files Browse the repository at this point in the history
* [issue-1202] Removed ConfigurationAsCode restriction

* Added restriction to doXX and public methods

* All public methods should be restricted.
  • Loading branch information
escoem authored and timja committed Nov 25, 2019
1 parent b435303 commit cf4c8eb
Showing 1 changed file with 14 additions and 1 deletion.
Expand Up @@ -99,7 +99,6 @@
* @author <a href="mailto:nicolas.deloof@gmail.com">Nicolas De Loof</a>
*/
@Extension
@Restricted(NoExternalUse.class)
public class ConfigurationAsCode extends ManagementLink {

public static final String CASC_JENKINS_CONFIG_PROPERTY = "casc.jenkins.config";
Expand Down Expand Up @@ -148,6 +147,7 @@ public List<String> 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);
Expand All @@ -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);
Expand Down Expand Up @@ -201,6 +202,7 @@ private boolean canApplyFrom(List<YamlSource> yamlSources) {
}

@POST
@Restricted(NoExternalUse.class)
public FormValidation doCheckNewSource(@QueryParameter String newSource) {
Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER);
String normalizedSource = Util.fixEmptyAndTrim(newSource);
Expand Down Expand Up @@ -267,6 +269,7 @@ private List<YamlSource> getConfigFromSources(List<String> 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();
Expand Down Expand Up @@ -325,6 +328,7 @@ private List<String> getStandardConfig() {
return configParameters;
}

@Restricted(NoExternalUse.class)
public List<String> getBundledCasCURIs() {
final String cascFile = "/WEB-INF/" + DEFAULT_JENKINS_YAML_PATH;
final String cascDirectory = "/WEB-INF/" + DEFAULT_JENKINS_YAML_PATH + ".d/";
Expand Down Expand Up @@ -360,6 +364,7 @@ public List<String> getBundledCasCURIs() {
}

@RequirePOST
@Restricted(NoExternalUse.class)
public void doCheck(StaplerRequest req, StaplerResponse res) throws Exception {

if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) {
Expand All @@ -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)) {
Expand All @@ -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)) {
Expand All @@ -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)) {
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -622,6 +632,7 @@ private void closeSources(List<YamlSource> 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<Path> configs(String path) throws ConfiguratorException {
final Path root = Paths.get(path);

Expand Down Expand Up @@ -783,6 +794,7 @@ private void listElements(Set<Object> elements, Set<Attribute<?,?>> 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");
Expand All @@ -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();
Expand Down

0 comments on commit cf4c8eb

Please sign in to comment.