Skip to content

Commit

Permalink
Support new CSP auth method for Wavefront
Browse files Browse the repository at this point in the history
Closes gh-37165
  • Loading branch information
mhalbritter committed Oct 5, 2023
1 parent 0a16ec1 commit fbec06a
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand Down Expand Up @@ -84,4 +86,18 @@ public boolean reportDayDistribution() {
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;
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public class WavefrontProperties {
*/
private String apiToken;

/**
* Type of the API token.
*/
private TokenType apiTokenType;

/**
* Application configuration.
*/
Expand Down Expand Up @@ -167,6 +172,14 @@ public void setTraceDerivedCustomTagKeys(Set<String> traceDerivedCustomTagKeys)
this.traceDerivedCustomTagKeys = traceDerivedCustomTagKeys;
}

public TokenType getApiTokenType() {
return this.apiTokenType;
}

public void setApiTokenType(TokenType apiTokenType) {
this.apiTokenType = apiTokenType;
}

public static class Application {

/**
Expand Down Expand Up @@ -385,4 +398,30 @@ public void setReportDayDistribution(boolean reportDayDistribution) {

}

/**
* 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

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@

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;

Expand Down Expand Up @@ -107,4 +111,20 @@ void whenPropertiesReportDayDistributionIsSetAdapterReportDayDistributionReturns
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);
}

}

0 comments on commit fbec06a

Please sign in to comment.