Skip to content

Commit

Permalink
Adds support for custom name for Eucalyptus. Also fixes roundtrip for…
Browse files Browse the repository at this point in the history
… ec2Endpoint and s3Endpoint (#837)
  • Loading branch information
Vlatombe committed Apr 9, 2023
1 parent b17f646 commit 05cc875
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/main/java/hudson/plugins/ec2/EC2Cloud.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import hudson.ProxyConfiguration;
import hudson.Util;
import hudson.model.Computer;
import hudson.model.Descriptor;
import hudson.model.ItemGroup;
Expand Down Expand Up @@ -176,8 +177,8 @@ protected EC2Cloud(String name, boolean useInstanceProfileForCredentials, String
this.useInstanceProfileForCredentials = useInstanceProfileForCredentials;
this.roleArn = roleArn;
this.roleSessionName = roleSessionName;
this.credentialsId = credentialsId;
this.sshKeysCredentialsId = sshKeysCredentialsId;
this.credentialsId = Util.fixEmpty(credentialsId);
this.sshKeysCredentialsId = Util.fixEmpty(sshKeysCredentialsId);

if (templates == null) {
this.templates = Collections.emptyList();
Expand Down
19 changes: 11 additions & 8 deletions src/main/java/hudson/plugins/ec2/Eucalyptus.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,22 @@ public class Eucalyptus extends EC2Cloud {
private final URL s3endpoint;

@DataBoundConstructor
public Eucalyptus(URL ec2endpoint, URL s3endpoint, boolean useInstanceProfileForCredentials, String credentialsId, String privateKey, String sshKeysCredentialsId, String instanceCapStr, List<SlaveTemplate> templates, String roleArn, String roleSessionName)
public Eucalyptus(String name, URL ec2EndpointUrl, URL s3EndpointUrl, boolean useInstanceProfileForCredentials, String credentialsId, String privateKey, String sshKeysCredentialsId, String instanceCapStr, List<SlaveTemplate> templates, String roleArn, String roleSessionName) {
super(name, useInstanceProfileForCredentials, credentialsId, privateKey, sshKeysCredentialsId, instanceCapStr, templates, roleArn, roleSessionName);
this.ec2endpoint = ec2EndpointUrl;
this.s3endpoint = s3EndpointUrl;
}

@Deprecated
public Eucalyptus(URL ec2EndpointUrl, URL s3EndpointUrl, boolean useInstanceProfileForCredentials, String credentialsId, String privateKey, String sshKeysCredentialsId, String instanceCapStr, List<SlaveTemplate> templates, String roleArn, String roleSessionName)
throws IOException {
super("eucalyptus", useInstanceProfileForCredentials, credentialsId, privateKey, sshKeysCredentialsId, instanceCapStr, templates, roleArn, roleSessionName);
this.ec2endpoint = ec2endpoint;
this.s3endpoint = s3endpoint;
this("eucalyptus", ec2EndpointUrl, s3EndpointUrl, useInstanceProfileForCredentials, credentialsId, privateKey, sshKeysCredentialsId, instanceCapStr, templates, roleArn, roleSessionName);
}

@Deprecated
public Eucalyptus(URL ec2endpoint, URL s3endpoint, boolean useInstanceProfileForCredentials, String credentialsId, String privateKey, String instanceCapStr, List<SlaveTemplate> templates, String roleArn, String roleSessionName)
public Eucalyptus(URL ec2EndpointUrl, URL s3EndpointUrl, boolean useInstanceProfileForCredentials, String credentialsId, String privateKey, String instanceCapStr, List<SlaveTemplate> templates, String roleArn, String roleSessionName)
throws IOException {
super("eucalyptus", useInstanceProfileForCredentials, credentialsId, privateKey, instanceCapStr, templates, roleArn, roleSessionName);
this.ec2endpoint = ec2endpoint;
this.s3endpoint = s3endpoint;
this("eucalyptus", ec2EndpointUrl, s3EndpointUrl, useInstanceProfileForCredentials, credentialsId, privateKey, null, instanceCapStr, templates, roleArn, roleSessionName);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ THE SOFTWARE.
-->
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form" xmlns:c="/lib/credentials">
<f:entry title="${%Eucalyptus EC2 URL}" field="ec2endpoint">
<f:entry title="${%Name}" field="name">
<f:textbox />
</f:entry>
<f:entry title="${%Eucalyptus S3 URL}" field="s3endpoint">
<f:entry title="${%Eucalyptus EC2 URL}" field="ec2EndpointUrl">
<f:textbox />
</f:entry>
<f:entry title="${%Eucalyptus S3 URL}" field="s3EndpointUrl">
<f:textbox />
</f:entry>
<f:entry field="credentialsId" title="${%Amazon EC2 Credentials}" description="AWS IAM Access Key used to connect to EC2. If not specified, implicit authentication mechanisms are used (IAM roles...)">
Expand Down
25 changes: 25 additions & 0 deletions src/test/java/hudson/plugins/ec2/EucalyptusTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package hudson.plugins.ec2;

import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import java.net.URL;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

public class EucalyptusTest {
@Rule
public JenkinsRule r = new JenkinsRule();

@Test
public void configRoundTrip() throws Exception {
Eucalyptus cloud = new Eucalyptus("test", new URL("https://ec2"), new URL("https://s3"), false, null, "test", null, "0", null, null, null);
r.jenkins.clouds.add(cloud);
r.jenkins.save();
JenkinsRule.WebClient wc = r.createWebClient();
HtmlPage p = wc.goTo("configureClouds/");
HtmlForm f = p.getFormByName("config");
r.submit(f);
r.assertEqualBeans(cloud, r.jenkins.getCloud("test"), "name,ec2EndpointUrl,s3EndpointUrl,useInstanceProfileForCredentials,roleArn,roleSessionName,credentialsId,sshKeysCredentialsId,instanceCap,templates");
}
}

0 comments on commit 05cc875

Please sign in to comment.