-
Notifications
You must be signed in to change notification settings - Fork 9
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
A connection to ES on cloud with param fix. #62
Conversation
@@ -1,5 +1,6 @@ | |||
## 0.0.2 (UNRELEASED) | |||
- Presents helpful guidance when run on an unsupported version of Java [#43](https://github.com/elastic/logstash-filter-elastic_integration/pull/43) | |||
- Fix: now plugin is able to establish a connection to Elasticsearch on Elastic cloud with `cloud_id` and `cloud_auth` authentication pair [#62](https://github.com/elastic/logstash-filter-elastic_integration/pull/62) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be moved to 0.0.3
once we release after #51 merge.
@@ -21,13 +21,12 @@ | |||
import org.apache.http.ssl.SSLContextBuilder; | |||
import org.elasticsearch.client.RestClient; | |||
import org.elasticsearch.client.RestClientBuilder; | |||
import org.elasticsearch.common.Strings; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am hesitant to pull unrelated extra bits from Elasticsearch in because although they are likely-stable, they are internal implementation details of Elasticsearch.
final int colonIndex = cloudAuth.getPassword().indexOf(":"); | ||
if (colonIndex <= 0) { | ||
throw new IllegalArgumentException("Invalid cloudAuth."); | ||
} | ||
String username = cloudAuth.getPassword().substring(0, colonIndex); | ||
String password = cloudAuth.getPassword().substring(colonIndex + 1); | ||
|
||
Strings.requireNonEmpty(username, "cloudAuth username"); | ||
Strings.requireNonEmpty(password, "cloudAuth password"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An alternative that doesn't rely on Elasticsearch internals, using com.google.common.base.Strings#isNullOrEmpty(String)
from the guava we already explicitly depend on:
final int colonIndex = cloudAuth.getPassword().indexOf(":"); | |
if (colonIndex <= 0) { | |
throw new IllegalArgumentException("Invalid cloudAuth."); | |
} | |
String username = cloudAuth.getPassword().substring(0, colonIndex); | |
String password = cloudAuth.getPassword().substring(colonIndex + 1); | |
Strings.requireNonEmpty(username, "cloudAuth username"); | |
Strings.requireNonEmpty(password, "cloudAuth password"); | |
final String cloudAuthValue = cloudAuth.getValue(); | |
final int colonIndex = cloudAuthValue.indexOf(":"); | |
final String username; | |
final String password; | |
if ((colonIndex <= 0) | |
|| isNullOrEmpty(username = cloudAuthValue.substring(0, colonIndex)) | |
|| isNullOrEmpty(password = cloudAuthValue.substring(colonIndex + 1))) { | |
throw new IllegalArgumentException("Invalid cloudAuth."); | |
} | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ES Strings
is in common (kind of util) which would less likely change (and have IngestDocument
, etc dependencies) but as we have a guava
for these kinds of operations, updated it with recent commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ES
Strings
is in common (kind of util) which would less likely change (and haveIngestDocument
, etc dependencies) but as we have aguava
for these kinds of operations
Yes; it is on our class-path as a transitive dependency of one or more Elasticsearch bits that we directly depend on, and is likely-stable, but we don't need to increase our cross-ties.
5756475
to
4e1c18d
Compare
Description
A connection to ES on cloud with
cloud_auth
option is raising an exception of[HTTP/1.1 401 Unauthorized]
. This change properly sets theusername
andpassword
in the credentials and establishes successful connection to ES on cloud.