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

Automatically add scheme to discovery.ec2.endpoint #11512

Merged
merged 8 commits into from
Dec 12, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Improve boolean parsing performance ([#11308](https://github.com/opensearch-project/OpenSearch/pull/11308))
- Interpret byte array as primitive using VarHandles ([#11362](https://github.com/opensearch-project/OpenSearch/pull/11362))
- Change error message when per shard document limit is breached ([#11312](https://github.com/opensearch-project/OpenSearch/pull/11312))
- Automatically add scheme to discovery.ec2.endpoint ([#11512](https://github.com/opensearch-project/OpenSearch/pull/11512))
- Restore support for Java 8 for RestClient ([#11562](https://github.com/opensearch-project/OpenSearch/pull/11562))

### Deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ protected Ec2Client buildClient(

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

if (Strings.hasText(region)) {
Expand All @@ -110,6 +110,19 @@ protected Ec2Client buildClient(
return SocketAccess.doPrivileged(builder::build);
}

protected String getFullEndpoint(String endpoint) {
if (!Strings.hasText(endpoint)) {
return null;
}
if (endpoint.startsWith("http")) {
return endpoint;
}

// if no scheme is provided, default to https
logger.debug("no scheme found in endpoint [{}], defaulting to https", endpoint);
return "https://" + endpoint;
}

static ProxyConfiguration buildProxyConfiguration(Logger logger, Ec2ClientSettings clientSettings) {
if (Strings.hasText(clientSettings.proxyHost)) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,26 @@ public void testAWSConfigurationWithAwsSettings() {
assertTrue(clientOverrideConfiguration.retryPolicy().isPresent());
assertThat(clientOverrideConfiguration.retryPolicy().get().numRetries(), is(10));
}

public void testGetFullEndpointWithScheme() {
final Settings settings = Settings.builder().put("discovery.ec2.endpoint", "http://ec2.us-west-2.amazonaws.com").build();
Ec2ClientSettings clientSettings = Ec2ClientSettings.getClientSettings(settings);

AwsEc2ServiceImpl awsEc2ServiceImpl = new AwsEc2ServiceImpl();

String endpoint = awsEc2ServiceImpl.getFullEndpoint(clientSettings.endpoint);
assertEquals("http://ec2.us-west-2.amazonaws.com", endpoint);
}

public void testGetFullEndpointWithoutScheme() {
final Settings settings = Settings.builder().put("discovery.ec2.endpoint", "ec2.us-west-2.amazonaws.com").build();
Ec2ClientSettings clientSettings = Ec2ClientSettings.getClientSettings(settings);

AwsEc2ServiceImpl awsEc2ServiceImpl = new AwsEc2ServiceImpl();

String endpoint = awsEc2ServiceImpl.getFullEndpoint(clientSettings.endpoint);
assertEquals("https://ec2.us-west-2.amazonaws.com", endpoint);

assertNull(awsEc2ServiceImpl.getFullEndpoint(""));
}
}
Loading