Skip to content

Commit

Permalink
Default discovery-ec2 region to none. (opensearch-project#7969)
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <[email protected]>
Signed-off-by: Rishab Nahata <[email protected]>
  • Loading branch information
dblock authored and imRishN committed Jun 27, 2023
1 parent c99ab11 commit 833db1d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
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,
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

0 comments on commit 833db1d

Please sign in to comment.