Support new CSP auth method for Wavefront

Closes gh-37165
pull/37768/head
Moritz Halbritter 1 year ago
parent 0a16ec17e9
commit fbec06a134

@ -16,11 +16,13 @@
package org.springframework.boot.actuate.autoconfigure.metrics.export.wavefront;
import com.wavefront.sdk.common.clients.service.token.TokenService.Type;
import io.micrometer.wavefront.WavefrontConfig;
import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.PushRegistryPropertiesConfigAdapter;
import org.springframework.boot.actuate.autoconfigure.wavefront.WavefrontProperties;
import org.springframework.boot.actuate.autoconfigure.wavefront.WavefrontProperties.Metrics.Export;
import org.springframework.boot.actuate.autoconfigure.wavefront.WavefrontProperties.TokenType;
/**
* Adapter to convert {@link WavefrontProperties} to a {@link WavefrontConfig}.
@ -84,4 +86,18 @@ public class WavefrontPropertiesConfigAdapter
return get(Export::isReportDayDistribution, WavefrontConfig.super::reportDayDistribution);
}
@Override
public Type apiTokenType() {
TokenType apiTokenType = this.properties.getApiTokenType();
if (apiTokenType == null) {
return WavefrontConfig.super.apiTokenType();
}
return switch (apiTokenType) {
case NO_TOKEN -> Type.NO_TOKEN;
case WAVEFRONT_API_TOKEN -> Type.WAVEFRONT_API_TOKEN;
case CSP_API_TOKEN -> Type.CSP_API_TOKEN;
case CSP_CLIENT_CREDENTIALS -> Type.CSP_CLIENT_CREDENTIALS;
};
}
}

@ -57,6 +57,11 @@ public class WavefrontProperties {
*/
private String apiToken;
/**
* Type of the API token.
*/
private TokenType apiTokenType;
/**
* Application configuration.
*/
@ -167,6 +172,14 @@ public class WavefrontProperties {
this.traceDerivedCustomTagKeys = traceDerivedCustomTagKeys;
}
public TokenType getApiTokenType() {
return this.apiTokenType;
}
public void setApiTokenType(TokenType apiTokenType) {
this.apiTokenType = apiTokenType;
}
public static class Application {
/**
@ -385,4 +398,30 @@ public class WavefrontProperties {
}
/**
* Wavefront token type.
*
* @since 3.2.0
*/
public enum TokenType {
/**
* No token.
*/
NO_TOKEN,
/**
* Wavefront API token.
*/
WAVEFRONT_API_TOKEN,
/**
* CSP API token.
*/
CSP_API_TOKEN,
/**
* CSP client credentials.
*/
CSP_CLIENT_CREDENTIALS
}
}

@ -18,11 +18,15 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.wavefront;
import java.net.URI;
import com.wavefront.sdk.common.clients.service.token.TokenService.Type;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.PushRegistryPropertiesConfigAdapterTests;
import org.springframework.boot.actuate.autoconfigure.wavefront.WavefrontProperties;
import org.springframework.boot.actuate.autoconfigure.wavefront.WavefrontProperties.Metrics.Export;
import org.springframework.boot.actuate.autoconfigure.wavefront.WavefrontProperties.TokenType;
import static org.assertj.core.api.Assertions.assertThat;
@ -107,4 +111,20 @@ class WavefrontPropertiesConfigAdapterTests extends
assertThat(createConfigAdapter(properties).reportDayDistribution()).isTrue();
}
@ParameterizedTest
@CsvSource(textBlock = """
null, WAVEFRONT_API_TOKEN
NO_TOKEN, NO_TOKEN
WAVEFRONT_API_TOKEN, WAVEFRONT_API_TOKEN
CSP_API_TOKEN, CSP_API_TOKEN
CSP_CLIENT_CREDENTIALS, CSP_CLIENT_CREDENTIALS
""")
void whenTokenTypeIsSetAdapterReturnsIt(String property, String wavefront) {
TokenType propertyToken = property.equals("null") ? null : TokenType.valueOf(property);
Type wavefrontToken = Type.valueOf(wavefront);
WavefrontProperties properties = new WavefrontProperties();
properties.setApiTokenType(propertyToken);
assertThat(new WavefrontPropertiesConfigAdapter(properties).apiTokenType()).isEqualTo(wavefrontToken);
}
}

Loading…
Cancel
Save