Browse Source

Expose Elastic's apiKeyCredentials property

See gh-28400
pull/28436/head
Jonatan Ivanov 4 years ago committed by Andy Wilkinson
parent
commit
dd475a2445
  1. 22
      spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticProperties.java
  2. 7
      spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticPropertiesConfigAdapter.java
  3. 9
      spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticPropertiesConfigAdapterTests.java
  4. 3
      spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticPropertiesTests.java

22
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticProperties.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -60,12 +60,14 @@ public class ElasticProperties extends StepRegistryProperties { @@ -60,12 +60,14 @@ public class ElasticProperties extends StepRegistryProperties {
private boolean autoCreateIndex = true;
/**
* Login user of the Elastic server.
* Login user of the Elastic server. If API key is configured, it will be used for
* authentication instead of username/password.
*/
private String userName;
/**
* Login password of the Elastic server.
* Login password of the Elastic server. If API key is configured, it will be used for
* authentication instead of username/password.
*/
private String password;
@ -74,6 +76,12 @@ public class ElasticProperties extends StepRegistryProperties { @@ -74,6 +76,12 @@ public class ElasticProperties extends StepRegistryProperties {
*/
private String pipeline;
/**
* Base64-encoded credentials string. If configured, it will be used for
* authentication instead of username/password.
*/
private String apiKeyCredentials;
public String getHost() {
return this.host;
}
@ -146,4 +154,12 @@ public class ElasticProperties extends StepRegistryProperties { @@ -146,4 +154,12 @@ public class ElasticProperties extends StepRegistryProperties {
this.pipeline = pipeline;
}
public String getApiKeyCredentials() {
return this.apiKeyCredentials;
}
public void setApiKeyCredentials(String apiKeyCredentials) {
this.apiKeyCredentials = apiKeyCredentials;
}
}

7
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticPropertiesConfigAdapter.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -82,4 +82,9 @@ class ElasticPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter @@ -82,4 +82,9 @@ class ElasticPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter
return get(ElasticProperties::getPipeline, ElasticConfig.super::pipeline);
}
@Override
public String apiKeyCredentials() {
return get(ElasticProperties::getApiKeyCredentials, ElasticConfig.super::apiKeyCredentials);
}
}

9
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticPropertiesConfigAdapterTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -90,4 +90,11 @@ class ElasticPropertiesConfigAdapterTests { @@ -90,4 +90,11 @@ class ElasticPropertiesConfigAdapterTests {
assertThat(new ElasticPropertiesConfigAdapter(properties).pipeline()).isEqualTo("testPipeline");
}
@Test
void whenPropertiesApiKeyCredentialsIsSetAdapterPipelineReturnsIt() {
ElasticProperties properties = new ElasticProperties();
properties.setApiKeyCredentials("secret");
assertThat(new ElasticPropertiesConfigAdapter(properties).apiKeyCredentials()).isEqualTo("secret");
}
}

3
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticPropertiesTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -44,6 +44,7 @@ class ElasticPropertiesTests extends StepRegistryPropertiesTests { @@ -44,6 +44,7 @@ class ElasticPropertiesTests extends StepRegistryPropertiesTests {
assertThat(properties.getUserName()).isEqualTo(config.userName());
assertThat(properties.isAutoCreateIndex()).isEqualTo(config.autoCreateIndex());
assertThat(properties.getPipeline()).isEqualTo(config.pipeline());
assertThat(properties.getApiKeyCredentials()).isEqualTo(config.apiKeyCredentials());
}
}

Loading…
Cancel
Save