Skip to content

Commit

Permalink
Merge pull request #539 from MRamonLeon/JENKINS-60482-improve-alt-end…
Browse files Browse the repository at this point in the history
…point-checking
  • Loading branch information
MRamonLeon authored Nov 24, 2020
2 parents 0780e33 + fe4fa4b commit 6712bf5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
23 changes: 21 additions & 2 deletions src/main/java/hudson/plugins/ec2/AmazonEC2Cloud.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import java.net.URL;
import java.util.List;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nullable;
import javax.servlet.ServletException;

Expand All @@ -59,6 +61,8 @@
* @author Kohsuke Kawaguchi
*/
public class AmazonEC2Cloud extends EC2Cloud {
private final static Logger LOGGER = Logger.getLogger(AmazonEC2Cloud.class.getName());

/**
* Represents the region. Can be null for backward compatibility reasons.
*/
Expand Down Expand Up @@ -178,6 +182,17 @@ public FormValidation doCheckCloudName(@QueryParameter String value) {
return FormValidation.ok();
}

public FormValidation doCheckAltEC2Endpoint(@QueryParameter String value) {
if (Util.fixEmpty(value) != null) {
try {
new URL(value);
} catch (MalformedURLException ignored) {
return FormValidation.error(Messages.AmazonEC2Cloud_MalformedUrl());
}
}
return FormValidation.ok();
}

@RequirePOST
public ListBoxModel doFillRegionItems(
@QueryParameter String altEC2Endpoint,
Expand Down Expand Up @@ -212,8 +227,12 @@ URL determineEC2EndpointURL(@Nullable String altEC2Endpoint) throws MalformedURL
if (Util.fixEmpty(altEC2Endpoint) == null) {
return new URL(DEFAULT_EC2_ENDPOINT);
}

return new URL(altEC2Endpoint);
try {
return new URL(altEC2Endpoint);
} catch (MalformedURLException e) {
LOGGER.log(Level.WARNING, "The alternate EC2 endpoint is malformed ({0}). Using the default endpoint ({1})", new Object[]{altEC2Endpoint, DEFAULT_EC2_ENDPOINT});
return new URL(DEFAULT_EC2_ENDPOINT);
}
}

@RequirePOST
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/hudson/plugins/ec2/Messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ EC2SpotSlave.Spot1=Spot $
EC2SpotSlave.Spot2= max bid price

AmazonEC2Cloud.NonUniqName=Cloud name must be unique across EC2 clouds

AmazonEC2Cloud.MalformedUrl=The URL is malformed. The default endpoint will be used
General.MissingPermission=You do not have the Overall/Administer right to modify this field

0 comments on commit 6712bf5

Please sign in to comment.