diff --git a/core/src/main/java/hudson/model/AdministrativeMonitor.java b/core/src/main/java/hudson/model/AdministrativeMonitor.java index 7a9a0dde970c..adc5f488c676 100644 --- a/core/src/main/java/hudson/model/AdministrativeMonitor.java +++ b/core/src/main/java/hudson/model/AdministrativeMonitor.java @@ -39,6 +39,8 @@ import org.kohsuke.stapler.StaplerProxy; import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerResponse; +import org.kohsuke.stapler.export.Exported; +import org.kohsuke.stapler.export.ExportedBean; import org.kohsuke.stapler.interceptor.RequirePOST; /** @@ -89,6 +91,7 @@ * @see Jenkins#administrativeMonitors */ @LegacyInstancesAreScopedToHudson +@ExportedBean public abstract class AdministrativeMonitor extends AbstractModelObject implements ExtensionPoint, StaplerProxy { /** * Human-readable ID of this monitor, which needs to be unique within the system. @@ -97,6 +100,7 @@ public abstract class AdministrativeMonitor extends AbstractModelObject implemen * This ID is used to remember persisted setting for this monitor, * so the ID should remain consistent beyond the Hudson JVM lifespan. */ + @Exported public final String id; protected AdministrativeMonitor(String id) { @@ -146,6 +150,7 @@ public void disable(boolean value) throws IOException { * This flag implements the ability for the admin to say "no thank you" to the monitor that * he wants to ignore. */ + @Exported public boolean isEnabled() { return !Jenkins.get().getDisabledAdministrativeMonitors().contains(id); } @@ -158,6 +163,7 @@ public boolean isEnabled() { * This method is called from the HTML rendering thread, * so it should run efficiently. */ + @Exported public abstract boolean isActivated(); /** @@ -167,6 +173,7 @@ public boolean isEnabled() { * * @since 2.267 */ + @Exported public boolean isSecurity() { return false; } diff --git a/core/src/main/java/jenkins/management/AdministrativeMonitorsApi.java b/core/src/main/java/jenkins/management/AdministrativeMonitorsApi.java index ea2b8e2cf771..4672d7d91894 100644 --- a/core/src/main/java/jenkins/management/AdministrativeMonitorsApi.java +++ b/core/src/main/java/jenkins/management/AdministrativeMonitorsApi.java @@ -1,18 +1,25 @@ package jenkins.management; import hudson.Extension; +import hudson.ExtensionList; +import hudson.model.AdministrativeMonitor; +import hudson.model.Api; import hudson.model.PageDecorator; import hudson.model.RootAction; import java.io.IOException; +import java.util.Collection; import javax.servlet.ServletException; import jenkins.model.Jenkins; import org.kohsuke.accmod.Restricted; import org.kohsuke.accmod.restrictions.NoExternalUse; import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerResponse; +import org.kohsuke.stapler.export.Exported; +import org.kohsuke.stapler.export.ExportedBean; import org.kohsuke.stapler.verb.GET; @Extension +@ExportedBean @Restricted(NoExternalUse.class) public class AdministrativeMonitorsApi implements RootAction { @GET @@ -39,7 +46,7 @@ public String getDisplayName() { @Override public String getUrlName() { - return "administrativeMonitorsApi"; + return "administrative-monitors"; } private AdministrativeMonitorsDecorator getDecorator() { @@ -47,4 +54,21 @@ private AdministrativeMonitorsDecorator getDecorator() { .getExtensionList(PageDecorator.class) .get(AdministrativeMonitorsDecorator.class); } + + @Exported + public Collection getActiveAdministrativeMonitors() { + return ExtensionList.lookupSingleton(AdministrativeMonitorsDecorator.class).getAllActiveAdministrativeMonitors(); + } + + @Exported + public Collection getAdministrativeMonitors() { + return ExtensionList.lookup(AdministrativeMonitor.class); + } + + public Api getApi() { + // Implement a permission check so failure to authenticate doesn't look like everything's OK when accessing /api. + // This check needs to match AdministrativeMonitorsDecorator#getMonitorsToDisplay. + Jenkins.get().checkPermission(Jenkins.SYSTEM_READ); + return new Api(this); + } } diff --git a/core/src/main/java/jenkins/management/AdministrativeMonitorsDecorator.java b/core/src/main/java/jenkins/management/AdministrativeMonitorsDecorator.java index cc1d5214e0ae..c6a2f7a1bf10 100644 --- a/core/src/main/java/jenkins/management/AdministrativeMonitorsDecorator.java +++ b/core/src/main/java/jenkins/management/AdministrativeMonitorsDecorator.java @@ -116,7 +116,7 @@ public List getSecurityAdministrativeMonitors() { .collect(Collectors.toList()); } - private Collection getAllActiveAdministrativeMonitors() { + protected Collection getAllActiveAdministrativeMonitors() { Collection active = new ArrayList<>(); for (AdministrativeMonitor am : Jenkins.get().getActiveAdministrativeMonitors()) { if (am instanceof ReverseProxySetupMonitor) { diff --git a/core/src/main/resources/jenkins/management/AdministrativeMonitorsDecorator/footer.jelly b/core/src/main/resources/jenkins/management/AdministrativeMonitorsDecorator/footer.jelly index ff40bc54365c..ebbcf0156c9a 100644 --- a/core/src/main/resources/jenkins/management/AdministrativeMonitorsDecorator/footer.jelly +++ b/core/src/main/resources/jenkins/management/AdministrativeMonitorsDecorator/footer.jelly @@ -38,7 +38,7 @@ THE SOFTWARE.