Skip to content

Commit

Permalink
Merge pull request #1929 from stephenc/jenkins-31596-followup
Browse files Browse the repository at this point in the history
[JENKINS-31596] The kill switch is never relevant if you do not have RUN_SCRIPTS
  • Loading branch information
stephenc committed Nov 26, 2015
2 parents d2e0f6f + 3c94a7c commit d1a8d8e
Showing 1 changed file with 1 addition and 41 deletions.
@@ -1,8 +1,6 @@
package jenkins.security.s2m;

import hudson.Extension;
import hudson.ExtensionList;
import hudson.ExtensionPoint;
import javax.inject.Inject;
import jenkins.model.GlobalConfiguration;
import jenkins.model.GlobalConfigurationCategory;
Expand Down Expand Up @@ -48,45 +46,7 @@ public boolean configure(StaplerRequest req, JSONObject json) throws FormExcepti
* Unless this option is relevant, we don't let users choose this.
*/
public boolean isRelevant() {
if (rule.getMasterKillSwitch()) {
return true; // always relevant if it is enabled.
}
return jenkins.isUseSecurity() // if security is off, there's no point
&& (jenkins.getComputers().length>1 // if there's no slave,
|| !jenkins.clouds.isEmpty() // and no clouds, likewise this is pointless
|| Relevance.fromExtension() // unless a plugin thinks otherwise
)
;
}

/**
* Some plugins may cause the {@link MasterKillSwitchConfiguration} to be relevant for additional reasons,
* by implementing this extension point they can indicate such additional conditions.
*
* @since FIXME
*/
public static abstract class Relevance implements ExtensionPoint {

/**
* Is the {@link MasterKillSwitchConfiguration} relevant.
*
* @return {@code true} if the {@link MasterKillSwitchConfiguration} relevant.
*/
public abstract boolean isRelevant();

/**
* Is the {@link MasterKillSwitchConfiguration} relevant for any of the {@link Relevance} extensions.
*
* @return {@code true} if and only if {@link Relevance#isRelevant()} for at least one extension.
*/
public static boolean fromExtension() {
for (Relevance r : ExtensionList.lookup(Relevance.class)) {
if (r.isRelevant()) {
return true;
}
}
return false;
}
return jenkins.hasPermission(Jenkins.RUN_SCRIPTS) && jenkins.isUseSecurity();
}
}

0 comments on commit d1a8d8e

Please sign in to comment.