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

Default discovery-ec2 region to none. #7969

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected Ec2Client buildClient(
ProxyConfiguration proxyConfiguration,
ClientOverrideConfiguration overrideConfiguration,
String endpoint,
Region region,
String region,
kotwanikunal marked this conversation as resolved.
Show resolved Hide resolved
long readTimeoutMillis
) {
ApacheHttpClient.Builder clientBuilder = ApacheHttpClient.builder()
Expand All @@ -94,14 +94,18 @@ protected Ec2Client buildClient(
Ec2ClientBuilder builder = Ec2Client.builder()
.overrideConfiguration(overrideConfiguration)
.httpClientBuilder(clientBuilder)
.credentialsProvider(awsCredentialsProvider)
.region(region);
.credentialsProvider(awsCredentialsProvider);

if (Strings.hasText(endpoint)) {
logger.debug("using explicit ec2 endpoint [{}]", endpoint);
builder.endpointOverride(URI.create(endpoint));
}

if (Strings.hasText(region)) {
logger.debug("using explicit ec2 region [{}]", region);
builder.region(Region.of(region));
}

return SocketAccess.doPrivileged(builder::build);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import software.amazon.awssdk.auth.credentials.AwsCredentials;
import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
import software.amazon.awssdk.core.Protocol;
import software.amazon.awssdk.regions.Region;

import java.util.Locale;

Expand Down Expand Up @@ -79,10 +78,10 @@ final class Ec2ClientSettings {
);

/** An override for the scoping region for authentication. */
static final Setting<Region> REGION_SETTING = new Setting<>(
static final Setting<String> REGION_SETTING = new Setting<>(
"discovery.ec2.region",
"us-west-2",
s -> Region.of(s.toLowerCase(Locale.ROOT)),
"",
s -> s.toLowerCase(Locale.ROOT),
Property.NodeScope
);

Expand Down Expand Up @@ -124,7 +123,7 @@ final class Ec2ClientSettings {
/**
* The ec2 signing region.
*/
final Region region;
final String region;

/** The protocol to use to talk to ec2. Defaults to https. */
final Protocol protocol;
Expand All @@ -150,7 +149,7 @@ final class Ec2ClientSettings {
protected Ec2ClientSettings(
AwsCredentials credentials,
String endpoint,
Region region,
String region,
Protocol protocol,
String proxyHost,
int proxyPort,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,16 @@ public void testDefaultEndpoint() throws IOException {
public void testDefaultRegion() throws IOException {
final Settings settings = Settings.builder().build();
try (Ec2DiscoveryPluginMock plugin = new Ec2DiscoveryPluginMock(settings)) {
final Region region = ((MockEc2Client) plugin.ec2Service.client().get()).region;
assertEquals(region, Region.US_WEST_2);
final String region = ((MockEc2Client) plugin.ec2Service.client().get()).region;
assertEquals(region, "");
}
}

public void testSpecificRegion() throws IOException {
final Settings settings = Settings.builder().put(Ec2ClientSettings.REGION_SETTING.getKey(), "us-west-2").build();
try (Ec2DiscoveryPluginMock plugin = new Ec2DiscoveryPluginMock(settings)) {
final Region region = ((MockEc2Client) plugin.ec2Service.client().get()).region;
assertEquals(region, Region.US_WEST_2);
final String region = ((MockEc2Client) plugin.ec2Service.client().get()).region;
assertEquals(region, Region.US_WEST_2.toString());
}
}

Expand Down Expand Up @@ -249,7 +249,7 @@ protected Ec2Client buildClient(
ProxyConfiguration proxyConfiguration,
ClientOverrideConfiguration overrideConfiguration,
String endpoint,
Region region,
String region,
long readTimeoutMillis
) {
return new MockEc2Client(credentials, proxyConfiguration, overrideConfiguration, endpoint, region, readTimeoutMillis);
Expand All @@ -261,7 +261,7 @@ protected Ec2Client buildClient(
private static class MockEc2Client implements Ec2Client {

String endpoint;
final Region region;
final String region;
final AwsCredentialsProvider credentials;
final ClientOverrideConfiguration clientOverrideConfiguration;
final ProxyConfiguration proxyConfiguration;
Expand All @@ -272,7 +272,7 @@ private static class MockEc2Client implements Ec2Client {
ProxyConfiguration proxyConfiguration,
ClientOverrideConfiguration clientOverrideConfiguration,
String endpoint,
Region region,
String region,
long readTimeoutMillis
) {
this.credentials = credentials;
Expand Down