Skip to content

Commit dd475a2

Browse files
jonatan-ivanovwilkinsona
authored andcommitted
Expose Elastic's apiKeyCredentials property
See gh-28400
1 parent 56b8494 commit dd475a2

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -60,12 +60,14 @@ public class ElasticProperties extends StepRegistryProperties {
6060
private boolean autoCreateIndex = true;
6161

6262
/**
63-
* Login user of the Elastic server.
63+
* Login user of the Elastic server. If API key is configured, it will be used for
64+
* authentication instead of username/password.
6465
*/
6566
private String userName;
6667

6768
/**
68-
* Login password of the Elastic server.
69+
* Login password of the Elastic server. If API key is configured, it will be used for
70+
* authentication instead of username/password.
6971
*/
7072
private String password;
7173

@@ -74,6 +76,12 @@ public class ElasticProperties extends StepRegistryProperties {
7476
*/
7577
private String pipeline;
7678

79+
/**
80+
* Base64-encoded credentials string. If configured, it will be used for
81+
* authentication instead of username/password.
82+
*/
83+
private String apiKeyCredentials;
84+
7785
public String getHost() {
7886
return this.host;
7987
}
@@ -146,4 +154,12 @@ public void setPipeline(String pipeline) {
146154
this.pipeline = pipeline;
147155
}
148156

157+
public String getApiKeyCredentials() {
158+
return this.apiKeyCredentials;
159+
}
160+
161+
public void setApiKeyCredentials(String apiKeyCredentials) {
162+
this.apiKeyCredentials = apiKeyCredentials;
163+
}
164+
149165
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -82,4 +82,9 @@ public String pipeline() {
8282
return get(ElasticProperties::getPipeline, ElasticConfig.super::pipeline);
8383
}
8484

85+
@Override
86+
public String apiKeyCredentials() {
87+
return get(ElasticProperties::getApiKeyCredentials, ElasticConfig.super::apiKeyCredentials);
88+
}
89+
8590
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -90,4 +90,11 @@ void whenPropertiesPipelineIsSetAdapterPipelineReturnsIt() {
9090
assertThat(new ElasticPropertiesConfigAdapter(properties).pipeline()).isEqualTo("testPipeline");
9191
}
9292

93+
@Test
94+
void whenPropertiesApiKeyCredentialsIsSetAdapterPipelineReturnsIt() {
95+
ElasticProperties properties = new ElasticProperties();
96+
properties.setApiKeyCredentials("secret");
97+
assertThat(new ElasticPropertiesConfigAdapter(properties).apiKeyCredentials()).isEqualTo("secret");
98+
}
99+
93100
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -44,6 +44,7 @@ void defaultValuesAreConsistent() {
4444
assertThat(properties.getUserName()).isEqualTo(config.userName());
4545
assertThat(properties.isAutoCreateIndex()).isEqualTo(config.autoCreateIndex());
4646
assertThat(properties.getPipeline()).isEqualTo(config.pipeline());
47+
assertThat(properties.getApiKeyCredentials()).isEqualTo(config.apiKeyCredentials());
4748
}
4849

4950
}

0 commit comments

Comments
 (0)