Skip to content

Commit fbec06a

Browse files
committed
Support new CSP auth method for Wavefront
Closes gh-37165
1 parent 0a16ec1 commit fbec06a

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616

1717
package org.springframework.boot.actuate.autoconfigure.metrics.export.wavefront;
1818

19+
import com.wavefront.sdk.common.clients.service.token.TokenService.Type;
1920
import io.micrometer.wavefront.WavefrontConfig;
2021

2122
import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.PushRegistryPropertiesConfigAdapter;
2223
import org.springframework.boot.actuate.autoconfigure.wavefront.WavefrontProperties;
2324
import org.springframework.boot.actuate.autoconfigure.wavefront.WavefrontProperties.Metrics.Export;
25+
import org.springframework.boot.actuate.autoconfigure.wavefront.WavefrontProperties.TokenType;
2426

2527
/**
2628
* Adapter to convert {@link WavefrontProperties} to a {@link WavefrontConfig}.
@@ -84,4 +86,18 @@ public boolean reportDayDistribution() {
8486
return get(Export::isReportDayDistribution, WavefrontConfig.super::reportDayDistribution);
8587
}
8688

89+
@Override
90+
public Type apiTokenType() {
91+
TokenType apiTokenType = this.properties.getApiTokenType();
92+
if (apiTokenType == null) {
93+
return WavefrontConfig.super.apiTokenType();
94+
}
95+
return switch (apiTokenType) {
96+
case NO_TOKEN -> Type.NO_TOKEN;
97+
case WAVEFRONT_API_TOKEN -> Type.WAVEFRONT_API_TOKEN;
98+
case CSP_API_TOKEN -> Type.CSP_API_TOKEN;
99+
case CSP_CLIENT_CREDENTIALS -> Type.CSP_CLIENT_CREDENTIALS;
100+
};
101+
}
102+
87103
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/wavefront/WavefrontProperties.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ public class WavefrontProperties {
5757
*/
5858
private String apiToken;
5959

60+
/**
61+
* Type of the API token.
62+
*/
63+
private TokenType apiTokenType;
64+
6065
/**
6166
* Application configuration.
6267
*/
@@ -167,6 +172,14 @@ public void setTraceDerivedCustomTagKeys(Set<String> traceDerivedCustomTagKeys)
167172
this.traceDerivedCustomTagKeys = traceDerivedCustomTagKeys;
168173
}
169174

175+
public TokenType getApiTokenType() {
176+
return this.apiTokenType;
177+
}
178+
179+
public void setApiTokenType(TokenType apiTokenType) {
180+
this.apiTokenType = apiTokenType;
181+
}
182+
170183
public static class Application {
171184

172185
/**
@@ -385,4 +398,30 @@ public void setReportDayDistribution(boolean reportDayDistribution) {
385398

386399
}
387400

401+
/**
402+
* Wavefront token type.
403+
*
404+
* @since 3.2.0
405+
*/
406+
public enum TokenType {
407+
408+
/**
409+
* No token.
410+
*/
411+
NO_TOKEN,
412+
/**
413+
* Wavefront API token.
414+
*/
415+
WAVEFRONT_API_TOKEN,
416+
/**
417+
* CSP API token.
418+
*/
419+
CSP_API_TOKEN,
420+
/**
421+
* CSP client credentials.
422+
*/
423+
CSP_CLIENT_CREDENTIALS
424+
425+
}
426+
388427
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@
1818

1919
import java.net.URI;
2020

21+
import com.wavefront.sdk.common.clients.service.token.TokenService.Type;
2122
import org.junit.jupiter.api.Test;
23+
import org.junit.jupiter.params.ParameterizedTest;
24+
import org.junit.jupiter.params.provider.CsvSource;
2225

2326
import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.PushRegistryPropertiesConfigAdapterTests;
2427
import org.springframework.boot.actuate.autoconfigure.wavefront.WavefrontProperties;
2528
import org.springframework.boot.actuate.autoconfigure.wavefront.WavefrontProperties.Metrics.Export;
29+
import org.springframework.boot.actuate.autoconfigure.wavefront.WavefrontProperties.TokenType;
2630

2731
import static org.assertj.core.api.Assertions.assertThat;
2832

@@ -107,4 +111,20 @@ void whenPropertiesReportDayDistributionIsSetAdapterReportDayDistributionReturns
107111
assertThat(createConfigAdapter(properties).reportDayDistribution()).isTrue();
108112
}
109113

114+
@ParameterizedTest
115+
@CsvSource(textBlock = """
116+
null, WAVEFRONT_API_TOKEN
117+
NO_TOKEN, NO_TOKEN
118+
WAVEFRONT_API_TOKEN, WAVEFRONT_API_TOKEN
119+
CSP_API_TOKEN, CSP_API_TOKEN
120+
CSP_CLIENT_CREDENTIALS, CSP_CLIENT_CREDENTIALS
121+
""")
122+
void whenTokenTypeIsSetAdapterReturnsIt(String property, String wavefront) {
123+
TokenType propertyToken = property.equals("null") ? null : TokenType.valueOf(property);
124+
Type wavefrontToken = Type.valueOf(wavefront);
125+
WavefrontProperties properties = new WavefrontProperties();
126+
properties.setApiTokenType(propertyToken);
127+
assertThat(new WavefrontPropertiesConfigAdapter(properties).apiTokenType()).isEqualTo(wavefrontToken);
128+
}
129+
110130
}

0 commit comments

Comments
 (0)