Skip to content

Commit

Permalink
[JENKINS-46172] Prevent Jenkins/configure submit if ssh host definiti…
Browse files Browse the repository at this point in the history
…on is incomplete.

Proper ssh host should have at least:
1. hostname not empty
2. attached credentials
  • Loading branch information
ljader committed Mar 25, 2018
1 parent d18d0ed commit 6f443e7
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/main/java/org/jvnet/hudson/plugins/SSHBuildWrapper.java
Expand Up @@ -31,6 +31,8 @@
import jenkins.model.Jenkins;
import net.sf.json.JSONObject;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.plugins.jsch.JSchConnector;
import org.kohsuke.stapler.AncestorInPath;
Expand Down Expand Up @@ -199,9 +201,22 @@ public CredentialsSSHSite[] getSites() {
return sites.toArray(new CredentialsSSHSite[0]);
}

public FormValidation doCheckHostname(@QueryParameter("hostname") String hostname) {
if ((hostname == null) || (hostname.trim().isEmpty())) {
return FormValidation.error("Hostname not specified!");
}
return FormValidation.ok();
}

@Override
public boolean configure(StaplerRequest req, JSONObject formData) {
sites.replaceBy(req.bindJSONToList(CredentialsSSHSite.class, formData.get("sites")));
List<CredentialsSSHSite> sitesFromRequest = req.bindJSONToList(CredentialsSSHSite.class, formData.get("sites"));
for (CredentialsSSHSite sshSite : sitesFromRequest) {
if (StringUtils.isBlank(sshSite.getHostname()) || StringUtils.isBlank(sshSite.getCredentialId())) {
return false;
}
}
sites.replaceBy(sitesFromRequest);

save();
return true;
Expand Down

0 comments on commit 6f443e7

Please sign in to comment.