Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ private KubernetesVaultTokenSupplier(Builder builder) {
Objects.requireNonNull(builder.serviceAccountTokenPath, "k8s service account token path");
}

public static Builder builder() {
return new Builder();
}

public static KubernetesVaultTokenSupplier newInstance() {
return builder().build();
}

@Override
public String getToken(VaultConfig config) {
try (Stream<String> stream = Files.lines(Paths.get(serviceAccountTokenPath))) {
Expand Down Expand Up @@ -53,7 +61,7 @@ public static class Builder {
Optional.ofNullable(ENVIRONMENT_LOADER.loadVariable("SERVICE_ACCOUNT_TOKEN_PATH"))
.orElse("/var/run/secrets/kubernetes.io/serviceaccount/token");

public Builder() {}
private Builder() {}

public Builder vaultRole(String vaultRole) {
this.vaultRole = vaultRole;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ public CompletableFuture<String> getToken() {
+ "ignoring EnvironmentVaultTokenSupplier "
+ "(specify either vaultToken or vaultRole, not both)");
}
vaultTokenSupplier =
new KubernetesVaultTokenSupplier.Builder().vaultRole(vaultRole).build();
vaultTokenSupplier = KubernetesVaultTokenSupplier.builder().vaultRole(vaultRole).build();
vaultConfig = new VaultConfig().address(vaultAddress).build();
} else {
vaultTokenSupplier = new EnvironmentVaultTokenSupplier();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ private VaultConfigSource(VaultInvoker vault, Collection<String> secretsPaths) {
this.secretsPaths = new ArrayList<>(secretsPaths);
}

public static Builder builder() {
return new Builder();
}

@Override
public Map<String, ConfigProperty> loadConfig() {
Map<String, ConfigProperty> propertyMap = new HashMap<>();
Expand Down Expand Up @@ -85,7 +89,7 @@ public static final class Builder {
.map(HashSet::new)
.orElseGet(HashSet::new);

public Builder() {}
private Builder() {}

/**
* Appends secrets paths (each path value may contain values separated by colons).
Expand Down Expand Up @@ -161,7 +165,7 @@ public Builder tokenSupplier(VaultTokenSupplier tokenSupplier) {

public VaultConfigSource build() {
return new VaultConfigSource(
invoker != null ? invoker : builderFunction.apply(new VaultInvoker.Builder()).build(),
invoker != null ? invoker : builderFunction.apply(VaultInvoker.builder()).build(),
secretsPaths);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ private VaultInvoker(Builder builder) {
this.builder = builder;
}

public static Builder builder() {
return new Builder();
}

/**
* Invokes a given call with vault.
*
Expand Down Expand Up @@ -213,7 +217,7 @@ public static class Builder {

private VaultTokenSupplier tokenSupplier = new EnvironmentVaultTokenSupplier();

public Builder() {}
private Builder() {}

/**
* Setter for {@link VaultConfig} operator.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static VaultInvoker newVaultInvoker() {
}

final VaultInvoker.Builder builder =
new VaultInvoker.Builder()
VaultInvoker.builder()
.options(config -> config.address(vaultAddr).engineVersion(vaultEngineVersion));

if (!isNullOrNone(vaultRole)) {
Expand All @@ -71,7 +71,7 @@ public static VaultInvoker newVaultInvoker() {
+ "ignoring EnvironmentVaultTokenSupplier "
+ "(specify either VAULT_ROLE or VAULT_TOKEN, not both)");
}
builder.tokenSupplier(new KubernetesVaultTokenSupplier.Builder().build());
builder.tokenSupplier(KubernetesVaultTokenSupplier.newInstance());
} else {
builder.tokenSupplier(new EnvironmentVaultTokenSupplier());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static void beforeAll() {
@Test
void testFirstTenant() {
VaultConfigSource vaultConfigSource =
new VaultConfigSource.Builder()
VaultConfigSource.builder()
.config(c -> c.token(vaultContainerExtension.vaultInstance().rootToken()))
.config(c -> c.address(vaultContainerExtension.vaultInstance().address()))
.addSecretsPath(VAULT_SECRETS_PATH1)
Expand All @@ -70,7 +70,7 @@ void testFirstTenant() {
@Test
void testSecondTenant() {
VaultConfigSource vaultConfigSource =
new VaultConfigSource.Builder()
VaultConfigSource.builder()
.config(c -> c.token(vaultContainerExtension.vaultInstance().rootToken()))
.config(c -> c.address(vaultContainerExtension.vaultInstance().address()))
.addSecretsPath(VAULT_SECRETS_PATH2)
Expand All @@ -87,7 +87,7 @@ void testSecondTenant() {
@Test
void testMultiplePathsEnv() {
VaultConfigSource vaultConfigSource =
new VaultConfigSource.Builder()
VaultConfigSource.builder()
.config(c -> c.token(vaultContainerExtension.vaultInstance().rootToken()))
.config(c -> c.address(vaultContainerExtension.vaultInstance().address()))
.addSecretsPath(VAULT_SECRETS_PATH1 + ":" + VAULT_SECRETS_PATH2)
Expand Down Expand Up @@ -120,7 +120,7 @@ void testMultiplePathsEnv() {
@Test
void testMissingProperty() {
VaultConfigSource vaultConfigSource =
new VaultConfigSource.Builder()
VaultConfigSource.builder()
.config(c -> c.token(vaultContainerExtension.vaultInstance().rootToken()))
.config(c -> c.address(vaultContainerExtension.vaultInstance().address()))
.addSecretsPath(VAULT_SECRETS_PATH3)
Expand All @@ -135,7 +135,7 @@ void testMissingProperty() {

@Test
void testMissingTenant() {
new VaultConfigSource.Builder()
VaultConfigSource.builder()
.config(c -> c.token(vaultContainerExtension.vaultInstance().rootToken()))
.config(c -> c.address(vaultContainerExtension.vaultInstance().address()))
.addSecretsPath("secrets/unknown/path")
Expand All @@ -145,7 +145,7 @@ void testMissingTenant() {
@Test
void testInvalidAddress() {
VaultConfigSource vaultConfigSource =
new VaultConfigSource.Builder()
VaultConfigSource.builder()
.config(c -> c.token(vaultContainerExtension.vaultInstance().rootToken()))
.config(c -> c.address("http://invalid.host.local:8200"))
.addSecretsPath(VAULT_SECRETS_PATH1)
Expand All @@ -157,7 +157,7 @@ void testInvalidAddress() {
@Test
void testInvalidToken() {
VaultConfigSource vaultConfigSource =
new VaultConfigSource.Builder()
VaultConfigSource.builder()
.config(c -> c.token("zzzzzz"))
.config(c -> c.address("http://invalid.host.local:8200"))
.addSecretsPath("secrets/unknown/path")
Expand All @@ -178,7 +178,7 @@ void shouldWorkWhenRegistryIsReloadedAndVaultIsRunning() throws InterruptedExcep
ConfigRegistrySettings.builder()
.addLastSource(
"vault",
new VaultConfigSource.Builder()
VaultConfigSource.builder()
.config(vaultConfig -> vaultConfig.address(address).token(rootToken))
.addSecretsPath(VAULT_SECRETS_PATH1)
.build())
Expand Down Expand Up @@ -212,7 +212,7 @@ void shouldWorkWhenRegistryIsReloadedAndVaultIsDown() {
ConfigRegistrySettings.builder()
.addLastSource(
"vault",
new VaultConfigSource.Builder()
VaultConfigSource.builder()
.config(vaultConfig -> vaultConfig.address(address).token(rootToken))
.addSecretsPath(VAULT_SECRETS_PATH1)
.build())
Expand Down Expand Up @@ -244,7 +244,7 @@ void testSealed() throws Throwable {
vault.seal().seal();
assumeTrue(vault.seal().sealStatus().getSealed(), "vault seal status");

new VaultConfigSource.Builder()
VaultConfigSource.builder()
.config(c -> c.token("ROOT"))
.config(c -> c.address(vaultInstance.address()))
.addSecretsPath(VAULT_SECRETS_PATH1)
Expand All @@ -271,7 +271,7 @@ void shouldWorkWhenRegistryIsReloadedAndVaultIsUnSealed() throws InterruptedExce
ConfigRegistrySettings.builder()
.addLastSource(
"vault",
new VaultConfigSource.Builder()
VaultConfigSource.builder()
.config(vaultConfig -> vaultConfig.address(address).token(rootToken))
.addSecretsPath(VAULT_SECRETS_PATH1)
.build())
Expand Down Expand Up @@ -319,7 +319,7 @@ void testRenewableToken() throws InterruptedException {
.getAuthClientToken();

VaultConfigSource vaultConfigSource =
new VaultConfigSource.Builder()
VaultConfigSource.builder()
.config(c -> c.token(vaultContainerExtension.vaultInstance().rootToken()))
.config(c -> c.address(vaultContainerExtension.vaultInstance().address()))
.addSecretsPath(VAULT_SECRETS_PATH1)
Expand Down Expand Up @@ -347,7 +347,7 @@ void testNonrenewableToken() {
.getAuthClientToken();

VaultConfigSource vaultConfigSource =
new VaultConfigSource.Builder()
VaultConfigSource.builder()
.config(c -> c.token(vaultContainerExtension.vaultInstance().rootToken()))
.config(c -> c.address(vaultContainerExtension.vaultInstance().address()))
.addSecretsPath(VAULT_SECRETS_PATH1)
Expand Down Expand Up @@ -385,7 +385,7 @@ void testRenewableTokenWithExplicitMaxTtl() {
.getAuthClientToken();

VaultConfigSource vaultConfigSource =
new VaultConfigSource.Builder()
VaultConfigSource.builder()
.config(c -> c.token(vaultContainerExtension.vaultInstance().rootToken()))
.config(c -> c.address(vaultContainerExtension.vaultInstance().address()))
.addSecretsPath(VAULT_SECRETS_PATH1)
Expand Down Expand Up @@ -423,7 +423,7 @@ void testRenewableTokenWithUseLimit() {
.getAuthClientToken();

VaultConfigSource vaultConfigSource =
new VaultConfigSource.Builder()
VaultConfigSource.builder()
.config(c -> c.token(vaultContainerExtension.vaultInstance().rootToken()))
.config(c -> c.address(vaultContainerExtension.vaultInstance().address()))
.addSecretsPath(VAULT_SECRETS_PATH1)
Expand All @@ -449,7 +449,7 @@ void testRenewableTokenWithUseLimit() {
@Test
void testTokenSupplierGeneratesNewRenewableTokenWithExplicitMaxTtl() throws Exception {
VaultConfigSource vaultConfigSource =
new VaultConfigSource.Builder()
VaultConfigSource.builder()
.config(c -> c.token(vaultContainerExtension.vaultInstance().rootToken()))
.config(c -> c.address(vaultContainerExtension.vaultInstance().address()))
.addSecretsPath(VAULT_SECRETS_PATH1)
Expand Down Expand Up @@ -482,7 +482,7 @@ void testRenewableTokenWhichWillBeRevoked() {
.getAuthClientToken();

VaultConfigSource vaultConfigSource =
new VaultConfigSource.Builder()
VaultConfigSource.builder()
.config(c -> c.token(vaultContainerExtension.vaultInstance().rootToken()))
.config(c -> c.address(vaultContainerExtension.vaultInstance().address()))
.addSecretsPath(VAULT_SECRETS_PATH1)
Expand Down Expand Up @@ -515,7 +515,7 @@ void testRenewableTokenWhichWillBeRevoked() {
void testTokenSupplierGeneratesNewRenewableTokenWhichWillBeRevoked() throws Exception {
AtomicReference<String> tokenRef = new AtomicReference<>();
VaultConfigSource vaultConfigSource =
new VaultConfigSource.Builder()
VaultConfigSource.builder()
.config(c -> c.token(vaultContainerExtension.vaultInstance().rootToken()))
.config(c -> c.address(vaultContainerExtension.vaultInstance().address()))
.addSecretsPath(VAULT_SECRETS_PATH1)
Expand Down