File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
x-pack/plugin/monitoring/src
main/java/org/elasticsearch/xpack/monitoring/exporter/http
test/java/org/elasticsearch/xpack/monitoring/exporter/http Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -763,9 +763,15 @@ public static List<String> loadSettings(Settings settings) {
763
763
* @throws SettingsException if the username is missing, but a password is supplied
764
764
*/
765
765
@ Nullable
766
- private static CredentialsProvider createCredentialsProvider (final Config config ) {
766
+ // visible for testing
767
+ static CredentialsProvider createCredentialsProvider (final Config config ) {
767
768
final String username = AUTH_USERNAME_SETTING .getConcreteSettingForNamespace (config .name ()).get (config .settings ());
768
769
770
+ if (Strings .isNullOrEmpty (username )) {
771
+ // nothing to configure; default situation for most users
772
+ return null ;
773
+ }
774
+
769
775
final String deprecatedPassword = AUTH_PASSWORD_SETTING .getConcreteSettingForNamespace (config .name ()).get (config .settings ());
770
776
final SecureString securePassword = SECURE_AUTH_PASSWORDS .get (config .name ());
771
777
final String password ;
Original file line number Diff line number Diff line change 5
5
*/
6
6
package org .elasticsearch .xpack .monitoring .exporter .http ;
7
7
8
+ import org .apache .http .client .CredentialsProvider ;
8
9
import org .apache .http .entity .ContentType ;
9
10
import org .apache .http .entity .StringEntity ;
10
11
import org .apache .http .nio .conn .ssl .SSLIOSessionStrategy ;
@@ -356,6 +357,17 @@ public void testCreateRestClient() throws IOException {
356
357
}
357
358
}
358
359
360
+ public void testCreateCredentialsProviderWithoutSecurity () {
361
+ final Settings .Builder builder = Settings .builder ()
362
+ .put ("xpack.monitoring.exporters._http.type" , "http" )
363
+ .put ("xpack.monitoring.exporters._http.host" , "http://localhost:9200" );
364
+
365
+ final Config config = createConfig (builder .build ());
366
+ CredentialsProvider provider = HttpExporter .createCredentialsProvider (config );
367
+
368
+ assertNull (provider );
369
+ }
370
+
359
371
public void testCreateSnifferDisabledByDefault () {
360
372
final Config config = createConfig (Settings .EMPTY );
361
373
final RestClient client = mock (RestClient .class );
You can’t perform that action at this time.
0 commit comments