Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-60482] Improve alternate ec2 point checks #539

Merged
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
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