Skip to content

Commit

Permalink
fix: compile errors after EDC token refactor (#195)
Browse files Browse the repository at this point in the history
* fix: compile errors after EDC token refactor

* pr remarks
  • Loading branch information
paullatzelsperger authored Jan 15, 2024
1 parent 27096ff commit 7e0784f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 33 deletions.
4 changes: 4 additions & 0 deletions DEPENDENCIES
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ maven/mavencentral/com.github.docker-java/docker-java-transport-zerodep/3.3.4, A
maven/mavencentral/com.github.docker-java/docker-java-transport/3.3.4, Apache-2.0, approved, #7942
maven/mavencentral/com.github.stephenc.jcip/jcip-annotations/1.0-1, Apache-2.0, approved, CQ21949
maven/mavencentral/com.google.code.findbugs/jsr305/3.0.2, Apache-2.0, approved, #20
maven/mavencentral/com.google.code.gson/gson/2.10.1, Apache-2.0, approved, #6159
maven/mavencentral/com.google.crypto.tink/tink/1.12.0, Apache-2.0, approved, #12041
maven/mavencentral/com.google.errorprone/error_prone_annotations/2.22.0, Apache-2.0, approved, #10661
maven/mavencentral/com.google.errorprone/error_prone_annotations/2.7.1, Apache-2.0, approved, clearlydefined
maven/mavencentral/com.google.guava/failureaccess/1.0.1, Apache-2.0, approved, CQ22654
maven/mavencentral/com.google.guava/guava/31.0.1-jre, Apache-2.0, approved, clearlydefined
maven/mavencentral/com.google.guava/listenablefuture/9999.0-empty-to-avoid-conflict-with-guava, Apache-2.0, approved, CQ22657
maven/mavencentral/com.google.j2objc/j2objc-annotations/1.3, Apache-2.0, approved, CQ21195
maven/mavencentral/com.google.protobuf/protobuf-java/3.24.3, BSD-3-Clause, approved, clearlydefined
maven/mavencentral/com.nimbusds/nimbus-jose-jwt/9.37.3, Apache-2.0, approved, #11701
maven/mavencentral/com.puppycrawl.tools/checkstyle/10.0, LGPL-2.1-or-later, approved, #7936
maven/mavencentral/com.squareup.okhttp3/okhttp-dnsoverhttps/4.12.0, Apache-2.0, approved, #11159
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,20 @@
package org.eclipse.edc.vault.aws;

import org.eclipse.edc.runtime.metamodel.annotation.Extension;
import org.eclipse.edc.runtime.metamodel.annotation.Provides;
import org.eclipse.edc.runtime.metamodel.annotation.Provider;
import org.eclipse.edc.runtime.metamodel.annotation.Setting;
import org.eclipse.edc.spi.EdcException;
import org.eclipse.edc.spi.security.CertificateResolver;
import org.eclipse.edc.spi.security.PrivateKeyResolver;
import org.eclipse.edc.spi.security.Vault;
import org.eclipse.edc.spi.security.VaultCertificateResolver;
import org.eclipse.edc.spi.security.VaultPrivateKeyResolver;
import org.eclipse.edc.spi.system.ServiceExtension;
import org.eclipse.edc.spi.system.ServiceExtensionContext;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.secretsmanager.SecretsManagerClient;

import static org.eclipse.edc.util.configuration.ConfigurationFunctions.propOrEnv;
import static org.eclipse.edc.util.string.StringUtils.isNullOrEmpty;

/**
* This extension registers an implementation of the Vault interface for AWS Secrets Manager.
* It also registers a VaultPrivateKeyResolver and VaultCertificateResolver, which store and retrieve certificates
* using the AWS Secretes Manager Vault implementation.
* The extension requires the "edc.vault.aws.region" parameter to be set to the AWS region in which secrets should be stored.
*/
@Provides({ Vault.class, PrivateKeyResolver.class, CertificateResolver.class })
@Extension(value = org.eclipse.edc.vault.aws.AwsSecretsManagerVaultExtension.NAME)
public class AwsSecretsManagerVaultExtension implements ServiceExtension {
public static final String NAME = "AWS Secrets Manager Vault";
Expand All @@ -50,17 +41,14 @@ public String name() {
return NAME;
}

@Override
public void initialize(ServiceExtensionContext context) {
var vaultRegion = getMandatorySetting(context, VAULT_AWS_REGION);
@Provider
public Vault createVault(ServiceExtensionContext context) {
var vaultRegion = context.getConfig().getString(VAULT_AWS_REGION);

var smClient = buildSmClient(vaultRegion);
var vault = new AwsSecretsManagerVault(smClient, context.getMonitor(),
new AwsSecretsManagerVaultDefaultSanitationStrategy(context.getMonitor()));

context.registerService(Vault.class, vault);
context.registerService(PrivateKeyResolver.class, new VaultPrivateKeyResolver(vault));
context.registerService(CertificateResolver.class, new VaultCertificateResolver(vault));
return new AwsSecretsManagerVault(smClient, context.getMonitor(),
new AwsSecretsManagerVaultDefaultSanitationStrategy(context.getMonitor()));
}

private SecretsManagerClient buildSmClient(String vaultRegion) {
Expand All @@ -69,15 +57,4 @@ private SecretsManagerClient buildSmClient(String vaultRegion) {
return builder.build();
}

private String getMandatorySetting(ServiceExtensionContext context, String setting) {
var value = context.getSetting(setting, null);
if (isNullOrEmpty(value)) {
value = propOrEnv(setting, null);
if (isNullOrEmpty(value)) {
throw new EdcException(String.format("'%s' must be supplied but was null", setting));
}
}
return value;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

package org.eclipse.edc.vault.aws;

import org.eclipse.edc.spi.EdcException;
import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.edc.spi.system.ServiceExtensionContext;
import org.eclipse.edc.spi.system.configuration.Config;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand All @@ -33,16 +33,18 @@ void configOptionRegionNotProvided_shouldThrowException() {
ServiceExtensionContext invalidContext = mock(ServiceExtensionContext.class);
when(invalidContext.getMonitor()).thenReturn(monitor);

Assertions.assertThrows(EdcException.class, () -> extension.initialize(invalidContext));
Assertions.assertThrows(NullPointerException.class, () -> extension.createVault(invalidContext));
}

@Test
void configOptionRegionProvided_shouldNotThrowException() {
ServiceExtensionContext validContext = mock(ServiceExtensionContext.class);
when(validContext.getSetting("edc.vault.aws.region", null)).thenReturn("eu-west-1");
Config cfg = mock();
when(cfg.getString("edc.vault.aws.region")).thenReturn("eu-west-1");
when(validContext.getConfig()).thenReturn(cfg);
when(validContext.getMonitor()).thenReturn(monitor);

extension.initialize(validContext);
extension.createVault(validContext);
}

}

0 comments on commit 7e0784f

Please sign in to comment.