Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/main/java/org/jvnet/hudson/plugins/CredentialsSSHSite.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import hudson.Util;

public class CredentialsSSHSite {

Expand All @@ -49,6 +50,8 @@ public static class LegacySSHSite extends CredentialsSSHSite {
transient String keyfile;
}

String name;

String hostname;
String username;
int port;
Expand All @@ -67,13 +70,14 @@ private CredentialsSSHSite() {
}

@DataBoundConstructor
public CredentialsSSHSite(final String hostname, final String port, final String credentialId,
public CredentialsSSHSite(final String name, final String hostname, final String port, final String credentialId,
final String serverAliveInterval, final String timeout) {
final StandardUsernameCredentials credentials = lookupCredentialsById(credentialId);
if (credentials != null) {
this.username = credentials.getUsername();
}

this.name = Util.fixEmptyAndTrim(name);
this.hostname = hostname;
try {
this.port = Integer.parseInt(port);
Expand Down Expand Up @@ -192,7 +196,7 @@ legacy.username, new FileOnMasterPrivateKeySource(legacy.keyfile), legacy.passwo
credentialId = existingCredentials.getId();
}

return new CredentialsSSHSite(legacy.hostname, String.valueOf(legacy.port), credentialId,
return new CredentialsSSHSite(null, legacy.hostname, String.valueOf(legacy.port), credentialId,
String.valueOf(legacy.serverAliveInterval), String.valueOf(legacy.timeout));
}

Expand Down Expand Up @@ -299,7 +303,7 @@ public String getServerAliveInterval() {

/** Returns &quot;identifier&quot; for ssh site: <strong>username@hostname:port</strong> */
public String getSitename() {
return username + "@" + hostname + ":" + port;
return (Util.fixEmptyAndTrim(name) == null) ? username + "@" + hostname + ":" + port : name + " - " + username + "@" + hostname + ":" + port;
}

public String getTimeout() {
Expand Down Expand Up @@ -329,6 +333,14 @@ public void setPort(final String port) {
}
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = Util.fixEmptyAndTrim(name);
}

@DataBoundSetter
public void setPty(final Boolean pty) {
this.pty = pty;
Expand Down Expand Up @@ -365,7 +377,7 @@ public void testConnection(final PrintStream logger) throws JSchException, IOExc

@Override
public String toString() {
return "SSHSite [username=" + username + ", hostname=" + hostname + ",port=" + port + ", credentialId="
return "SSHSite [name=" + name + ", username=" + username + ", hostname=" + hostname + ",port=" + port + ", credentialId="
+ credentialId + ", pty=" + pty + "]";
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/jvnet/hudson/plugins/SSHBuildWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,12 @@ public ListBoxModel doFillCredentialIdItems(final @AncestorInPath ItemGroup<?> c
/**
* Validates ssh connection - currently this is executed on master node
*/
public FormValidation doLoginCheck(@QueryParameter("hostname") String hostname,
public FormValidation doLoginCheck(@QueryParameter("name") String name, @QueryParameter("hostname") String hostname,
@QueryParameter("port") String port,
@QueryParameter("credentialId") String credentialId,
@QueryParameter("serverAliveInterval") String serverAliveInterval,
@QueryParameter("timeout") String timeout) {
name = Util.fixEmptyAndTrim(name);
hostname = Util.fixEmpty(hostname);
port = Util.fixEmpty(port);
credentialId = Util.fixEmpty(credentialId);
Expand All @@ -272,7 +273,7 @@ public FormValidation doLoginCheck(@QueryParameter("hostname") String hostname,
return FormValidation.warning("Please fill host, port and credentials.");
}

final CredentialsSSHSite site = new CredentialsSSHSite(hostname, port, credentialId,
final CredentialsSSHSite site = new CredentialsSSHSite(name, hostname, port, credentialId,
serverAliveInterval, timeout);
try {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
description="${%SSH sites that projects will want to connect}">
<f:repeatable var="site" name="sites" items="${descriptor.sites}">
<table width="100%">
<f:entry title="${%Name}" help="/plugin/ssh/help-name.html">
<f:textbox name="name" value="${site.name}"/>
</f:entry>
<f:entry title="${%Hostname}" help="/plugin/ssh/help-hostname.html">
<f:textbox name="hostname" value="${site.hostname}" checkUrl="'${rootURL}/descriptorByName/org.jvnet.hudson.plugins.SSHBuildWrapper/checkHostname?hostname='+escape(this.value)" />
</f:entry>
Expand Down
1 change: 1 addition & 0 deletions src/main/webapp/help-name.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div>SSH name/alias</div>
1 change: 1 addition & 0 deletions src/main/webapp/help-name_ja.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div>SSH名/エイリアス</div>
12 changes: 12 additions & 0 deletions src/test/java/org/jvnet/hudson/plugins/SSHBuildWrapperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,16 @@ public void loadAllThreePossibleSiteConfigs() throws Exception {
}
}
}

@LocalData
@Test
public void checkNameForSSHConfiguration() throws Exception {
SSHBuildWrapper.DescriptorImpl desc = new SSHBuildWrapper.DescriptorImpl();
assertEquals(3, desc.getSites().length);

CredentialsSSHSite[] site = desc.getSites();
assertEquals("SSH worker1 - root@worker1.example.com:22", site[0].getSitename());
assertEquals("root@worker2.example.com:22", site[1].getSitename());
assertEquals("root@worker3.example.com:22", site[2].getSitename());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version='1.0' encoding='UTF-8'?>
<hudson>
<version>1.609.3</version>
<numExecutors>1</numExecutors>
<mode>NORMAL</mode>
<useSecurity>true</useSecurity>
<authorizationStrategy class="hudson.security.ProjectMatrixAuthorizationStrategy">
<permission>hudson.model.Hudson.Read:anonymous</permission>
<permission>hudson.model.Item.Read:anonymous</permission>
</authorizationStrategy>
<securityRealm class="hudson.security.LegacySecurityRealm"/>
<jdks/>
<slaves/>
<quietPeriod>5</quietPeriod>
</hudson>

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version='1.0' encoding='UTF-8'?>
<org.jvnet.hudson.plugins.SSHBuildWrapper_-DescriptorImpl plugin="ssh@2.6">
<sites>
<org.jvnet.hudson.plugins.CredentialsSSHSite>
<name>SSH worker1</name>
<hostname>worker1.example.com</hostname>
<port>22</port>
<username>root</username>
<credentialId>ca0fcca1-8d34-4f6d-91d3-61a58a1ebb8a</credentialId>
<timeout>0</timeout>
<pty>false</pty>
</org.jvnet.hudson.plugins.CredentialsSSHSite>
<org.jvnet.hudson.plugins.CredentialsSSHSite>
<name/>
<hostname>worker2.example.com</hostname>
<port>22</port>
<username>root</username>
<credentialId>ca0fcca1-8d34-4f6d-91d3-61a58a1ebb8a</credentialId>
<timeout>0</timeout>
<pty>false</pty>
</org.jvnet.hudson.plugins.CredentialsSSHSite>
<org.jvnet.hudson.plugins.CredentialsSSHSite>
<name> </name>
<hostname>worker3.example.com</hostname>
<port>22</port>
<username>root</username>
<credentialId>ca0fcca1-8d34-4f6d-91d3-61a58a1ebb8a</credentialId>
<timeout>0</timeout>
<pty>false</pty>
</org.jvnet.hudson.plugins.CredentialsSSHSite>
</sites>
</org.jvnet.hudson.plugins.SSHBuildWrapper_-DescriptorImpl>