Skip to content

Commit

Permalink
chore: Cleanup Hashicorp Vault package structure (#4082)
Browse files Browse the repository at this point in the history
Cleanup Hashicorp Vault package structure
  • Loading branch information
jimmarino committed Apr 3, 2024
1 parent 772d9cb commit 0b83737
Show file tree
Hide file tree
Showing 19 changed files with 52 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.edc.spi.result.Result;
import org.eclipse.edc.spi.security.Vault;
import org.eclipse.edc.vault.hashicorp.client.HashicorpVaultClient;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -43,8 +44,8 @@ public HashicorpVault(@NotNull HashicorpVaultClient hashicorpVaultClient, @NotNu
if (result.failed()) {
monitor.debug("Failed to resolve secret '%s': %s".formatted(key, result.getFailureMessages()));
return null;
}
}

return result.getContent();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
import org.eclipse.edc.spi.system.ExecutorInstrumentation;
import org.eclipse.edc.spi.system.ServiceExtension;
import org.eclipse.edc.spi.system.ServiceExtensionContext;
import org.eclipse.edc.vault.hashicorp.client.HashicorpVaultClient;
import org.eclipse.edc.vault.hashicorp.client.HashicorpVaultSettings;
import org.eclipse.edc.vault.hashicorp.client.HashicorpVaultTokenRenewTask;

import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES;

Expand Down Expand Up @@ -110,6 +113,7 @@ public void initialize(ServiceExtensionContext context) {
monitor = context.getMonitor().withPrefix(NAME);
settings = getSettings(context);
tokenRenewalTask = new HashicorpVaultTokenRenewTask(
NAME,
executorInstrumentation,
hashicorpVaultClient(),
settings.renewBuffer(),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
*/

package org.eclipse.edc.vault.hashicorp;
package org.eclipse.edc.vault.hashicorp.client;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
Expand All @@ -31,6 +31,7 @@
import org.eclipse.edc.vault.hashicorp.model.CreateEntryRequestPayload;
import org.eclipse.edc.vault.hashicorp.model.CreateEntryResponsePayload;
import org.eclipse.edc.vault.hashicorp.model.GetEntryResponsePayload;
import org.eclipse.edc.vault.hashicorp.util.PathUtil;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;
Expand Down Expand Up @@ -70,10 +71,10 @@ public class HashicorpVaultClient {
private final HttpUrl healthCheckUrl;
private final Monitor monitor;

HashicorpVaultClient(@NotNull EdcHttpClient httpClient,
@NotNull ObjectMapper objectMapper,
@NotNull Monitor monitor,
@NotNull HashicorpVaultSettings settings) {
public HashicorpVaultClient(@NotNull EdcHttpClient httpClient,
@NotNull ObjectMapper objectMapper,
@NotNull Monitor monitor,
@NotNull HashicorpVaultSettings settings) {
this.httpClient = httpClient;
this.objectMapper = objectMapper;
this.monitor = monitor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
*/

package org.eclipse.edc.vault.hashicorp;
package org.eclipse.edc.vault.hashicorp.client;

import dev.failsafe.Fallback;
import okhttp3.Request;
Expand All @@ -28,7 +28,7 @@
*/
public class HashicorpVaultClientFallbackFactory implements FallbackFactory {

private static final int[] NON_RETRYABLE_STATUS_CODES = {200, 204, 400, 403, 404, 405};
private static final int[] NON_RETRYABLE_STATUS_CODES = { 200, 204, 400, 403, 404, 405 };

@Override
public Fallback<Response> create(Request request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
*
*/

package org.eclipse.edc.vault.hashicorp;
package org.eclipse.edc.vault.hashicorp.client;

import okhttp3.HttpUrl;

import static java.util.Objects.requireNonNull;

/**
* Value container for {@link HashicorpVaultExtension} settings.
* Settings for the {@link HashicorpVaultClient}.
*/
public class HashicorpVaultSettings {

Expand All @@ -33,7 +33,8 @@ public class HashicorpVaultSettings {
private long renewBuffer;
private String secretPath;

private HashicorpVaultSettings() {}
private HashicorpVaultSettings() {
}

public HttpUrl url() {
return url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
*/

package org.eclipse.edc.vault.hashicorp;
package org.eclipse.edc.vault.hashicorp.client;

import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.edc.spi.system.ExecutorInstrumentation;
Expand All @@ -34,11 +34,12 @@ public class HashicorpVaultTokenRenewTask {
private static final String INITIAL_TOKEN_RENEW_ERR_MSG_FORMAT = "Initial token renewal failed with reason: %s";
private static final String SCHEDULED_TOKEN_RENEWAL_ERR_MSG_FORMAT = "Scheduled token renewal failed: %s";

@NotNull
private final String name;

private final ExecutorInstrumentation executorInstrumentation;
@NotNull

private final HashicorpVaultClient client;
@NotNull

private final Monitor monitor;
private final long renewBuffer;
private ScheduledExecutorService scheduledExecutorService;
Expand All @@ -51,14 +52,16 @@ public class HashicorpVaultTokenRenewTask {
* before the token expires and failed renewals can be retried in time.
*
* @param executorInstrumentation executor instrumentation used to initialize a {@link ScheduledExecutorService}
* @param client the HashicorpVaultClient
* @param renewBuffer the renewal buffer time in seconds
* @param monitor the monitor
* @param client the HashicorpVaultClient
* @param renewBuffer the renewal buffer time in seconds
* @param monitor the monitor
*/
public HashicorpVaultTokenRenewTask(@NotNull ExecutorInstrumentation executorInstrumentation,
public HashicorpVaultTokenRenewTask(@NotNull String name,
@NotNull ExecutorInstrumentation executorInstrumentation,
@NotNull HashicorpVaultClient client,
long renewBuffer,
@NotNull Monitor monitor) {
this.name = name;
this.executorInstrumentation = executorInstrumentation;
this.client = client;
this.renewBuffer = renewBuffer;
Expand All @@ -71,7 +74,7 @@ public HashicorpVaultTokenRenewTask(@NotNull ExecutorInstrumentation executorIns
*/
public void start() {
if (!isRunning()) {
scheduledExecutorService = executorInstrumentation.instrument(Executors.newSingleThreadScheduledExecutor(), HashicorpVaultExtension.NAME);
scheduledExecutorService = executorInstrumentation.instrument(Executors.newSingleThreadScheduledExecutor(), name);
scheduledExecutorService.execute(this::initialize);
isRunning.set(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
*
*/

package org.eclipse.edc.vault.hashicorp;
package org.eclipse.edc.vault.hashicorp.health;

import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.edc.spi.system.health.HealthCheckResult;
import org.eclipse.edc.spi.system.health.LivenessProvider;
import org.eclipse.edc.spi.system.health.ReadinessProvider;
import org.eclipse.edc.spi.system.health.StartupStatusProvider;
import org.eclipse.edc.vault.hashicorp.client.HashicorpVaultClient;

/**
* Implements the healthcheck of the Hashicorp Vault.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
*
*/

package org.eclipse.edc.vault.hashicorp;
package org.eclipse.edc.vault.hashicorp.health;

import org.eclipse.edc.runtime.metamodel.annotation.Extension;
import org.eclipse.edc.runtime.metamodel.annotation.Inject;
import org.eclipse.edc.runtime.metamodel.annotation.Requires;
import org.eclipse.edc.spi.system.ServiceExtension;
import org.eclipse.edc.spi.system.ServiceExtensionContext;
import org.eclipse.edc.spi.system.health.HealthCheckService;
import org.eclipse.edc.vault.hashicorp.client.HashicorpVaultClient;

import static org.eclipse.edc.vault.hashicorp.HashicorpVaultExtension.VAULT_HEALTH_CHECK_ENABLED;
import static org.eclipse.edc.vault.hashicorp.HashicorpVaultExtension.VAULT_HEALTH_CHECK_ENABLED_DEFAULT;
Expand Down Expand Up @@ -51,7 +52,7 @@ public void initialize(ServiceExtensionContext context) {
healthCheckService.addLivenessProvider(healthCheck);
healthCheckService.addReadinessProvider(healthCheck);
healthCheckService.addStartupStatusProvider(healthCheck);
monitor.info("Vault health check initialization complete");
monitor.debug("Vault health check initialization complete");
} else {
monitor.info("Vault health check disabled");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
*/

package org.eclipse.edc.vault.hashicorp;
package org.eclipse.edc.vault.hashicorp.util;

public class PathUtil {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
# Mercedes-Benz Tech Innovation GmbH - Initial ServiceExtension file
#
org.eclipse.edc.vault.hashicorp.HashicorpVaultExtension
org.eclipse.edc.vault.hashicorp.HashicorpVaultHealthExtension
org.eclipse.edc.vault.hashicorp.health.HashicorpVaultHealthExtension
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.edc.spi.result.Result;
import org.eclipse.edc.vault.hashicorp.client.HashicorpVaultClient;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
*/

package org.eclipse.edc.vault.hashicorp;
package org.eclipse.edc.vault.hashicorp.client;

import okhttp3.Request;
import org.eclipse.edc.http.spi.FallbackFactories;
Expand All @@ -22,7 +22,7 @@

class HashicorpVaultClientFallbackFactoryTest {

private static final int[] NON_RETRYABLE_STATUS_CODES = {200, 204, 400, 403, 404, 405};
private static final int[] NON_RETRYABLE_STATUS_CODES = { 200, 204, 400, 403, 404, 405 };

@Test
void create_shouldInitializeWithCorrectStatusCodes() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
*/

package org.eclipse.edc.vault.hashicorp;
package org.eclipse.edc.vault.hashicorp.client;

import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.json.Json;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
*/

package org.eclipse.edc.vault.hashicorp;
package org.eclipse.edc.vault.hashicorp.client;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
*/

package org.eclipse.edc.vault.hashicorp;
package org.eclipse.edc.vault.hashicorp.client;

import okhttp3.HttpUrl;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -87,7 +87,7 @@ void createSettings_withVaultTokenNull_shouldThrowException() {
var throwable = assertThrows(Exception.class, () -> createSettings(
URL,
null,
HEALTH_CHECK_PATH,
HEALTH_CHECK_PATH,
VAULT_TOKEN_TTL_DEFAULT,
VAULT_TOKEN_RENEW_BUFFER_DEFAULT));
assertThat(throwable.getMessage()).isEqualTo("Vault token must not be null");
Expand All @@ -105,12 +105,12 @@ void createSettings_withVaultTokenTtlLessThan5_shouldThrowException() {
}

@ParameterizedTest
@ValueSource(longs = {VAULT_TOKEN_TTL_DEFAULT, VAULT_TOKEN_TTL_DEFAULT + 1})
@ValueSource(longs = { VAULT_TOKEN_TTL_DEFAULT, VAULT_TOKEN_TTL_DEFAULT + 1 })
void createSettings_withVaultTokenRenewBufferEqualOrGreaterThanTtl_shouldThrowException(long value) {
var throwable = assertThrows(Exception.class, () -> createSettings(
URL,
TOKEN,
HEALTH_CHECK_PATH,
HEALTH_CHECK_PATH,
VAULT_TOKEN_TTL_DEFAULT,
value));
assertThat(throwable.getMessage()).isEqualTo("Vault token renew buffer value must be less than ttl value");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
*/

package org.eclipse.edc.vault.hashicorp;
package org.eclipse.edc.vault.hashicorp.client;

import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.edc.spi.result.Result;
Expand All @@ -38,6 +38,7 @@ class HashicorpVaultTokenRenewTaskTest {
private final Monitor monitor = mock();
private final HashicorpVaultClient client = mock();
private final HashicorpVaultTokenRenewTask tokenRenewTask = new HashicorpVaultTokenRenewTask(
"Hashicorp Vault",
ExecutorInstrumentation.noop(),
client,
RENEW_BUFFER,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
*
*/

package org.eclipse.edc.vault.hashicorp;
package org.eclipse.edc.vault.hashicorp.health;

import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.edc.spi.result.Result;
import org.eclipse.edc.vault.hashicorp.client.HashicorpVaultClient;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
Expand Down
Loading

0 comments on commit 0b83737

Please sign in to comment.