Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow endpoint overrides in AwsSecretsManagerVault #485

Merged

Conversation

chlorochrule
Copy link
Contributor

@chlorochrule chlorochrule commented Nov 13, 2024

What this PR changes/adds

AwsSecretsManagerVaultExtension do not allow to override AWS endpoint. However, S3CoreExtension allows it. So, I implements endpoint overrides in AwsSecretsManagerVault using edc.aws.endpoint.override the same param of S3CoreExtension.

Why it does that

For AWS-compatible services like localstack.

Closes #486

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are always happy to welcome new contributors ❤️ To make things easier for everyone, please make sure to follow our contribution guidelines, check if you have already signed the ECA, and relate this pull request to an existing issue or discussion.

@paullatzelsperger
Copy link
Member

@chlorochrule do NOT submit surprise PRs.
As per our PR Etiquette, a discussion or an issue must be created beforehand, to outline requirements, motivation and a technical approach for the work.

Committers will then triage the issue and approve it for implementation by removing the triage label. Once that is done you are good to go.

@chlorochrule
Copy link
Contributor Author

@paullatzelsperger I apologize for the breaking etiquette, and thank you for pointing that out! I created a ticket #486

Copy link

This pull request is stale because it has been open for 7 days with no activity.

@github-actions github-actions bot added the stale label Nov 21, 2024
@ndr-brt ndr-brt self-requested a review November 21, 2024 07:42
@ndr-brt ndr-brt added enhancement New feature or request and removed stale labels Nov 21, 2024
Comment on lines 42 to 43
@Setting
private static final String AWS_ENDPOINT_OVERRIDE = "edc.aws.endpoint.override";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this setting should be different than the one used to create the S3 client, and be called edc.vault.aws.endpoint.override, to align with the region setting.

plus, settings can be injected in a different way, as described in this DR

Please adapt and add some description to the annotation

@@ -47,4 +47,15 @@ void configOptionRegionProvided_shouldNotThrowException() {
extension.createVault(validContext);
}

@Test
void configOptionEndpointOverrideProvided_shouldNotThrowException() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test is asserting nothing. I know that you inherited from the already existing tests, but tests without assertions should be avoided.
Demonstration: if you try to add a proper assertion like:

        var vault = extension.createVault(validContext);

        assertThat(vault).extracting("smClient", type(SecretsManagerClient.class)).satisfies(client -> {
            assertThat(client.serviceClientConfiguration().endpointOverride()).contains(URI.create("http://localhost:4566"));
        });

it won't pass, that's because you set the mock to respond a call where only the setting key is passed, but not the default value.
Another suggestion would be not to mock the config object but to create one using ConfigFactory.fromMap, that will make everything easier.

Copy link
Contributor Author

@chlorochrule chlorochrule left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ndr-brt Thank you for reviewing! I fixed!

Comment on lines 39 to 41
@Setting(key = "edc.vault.aws.region",
description = "The AWS Secrets Manager client will point to the specified region")
String vaultRegion;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but to be tackled eventually in a separated issue/PR.

Comment on lines 39 to 41
@Setting(key = "edc.vault.aws.region",
description = "The AWS Secrets Manager client will point to the specified region")
String vaultRegion;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

package private for testing

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not a good pattern, please see my previous comment

@Setting(key = "edc.vault.aws.endpoint.override",
description = "If valued, the AWS Secrets Manager client will point to the specified endpoint",
required = false)
String vaultAwsEndpointOverride;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

package private for testing

Comment on lines 33 to 39
private static ServiceExtensionContext context;

@BeforeAll
public static void beforeAll() {
context = mock(ServiceExtensionContext.class);
when(context.getMonitor()).thenReturn(mock(Monitor.class));
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AwsSecretsManagerVaultExtension uses only monitor, does not use ServiceExtensionContext

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using DependencyInjectionExtension will make these lines unnecessary

Comment on lines 64 to 65
extension.vaultRegion = "eu-west-1";
extension.vaultAwsEndpointOverride = "http://localhost:4566";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to use key of @Setting, but I can't find the way to inject the testing value to the field variable. Please let me know how to test @Setting annotated value with key overrides if you know a better way!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My suggestion is to use the DependencyInjectionExtension that can be found in the edc-junit module.

Then this test can be written this way:

    @Test
    void configOptionEndpointOverrideProvided_shouldNotThrowException(ObjectFactory factory, ServiceExtensionContext context) {
        var config = ConfigFactory.fromMap(Map.of(
                "edc.vault.aws.region", "region",
                "edc.vault.aws.endpoint.override", "http://localhost:4566"
        ));
        when(context.getConfig()).thenReturn(config);
        var extension = factory.constructInstance(AwsSecretsManagerVaultExtension.class);

        var vault = extension.createVault(context);

        assertThat(vault).extracting("smClient", type(SecretsManagerClient.class)).satisfies(client -> {
            assertThat(client.serviceClientConfiguration().endpointOverride()).contains(URI.create("http://localhost:4566"));
        });
    }

and no need to make the setting fields package private

@ndr-brt
Copy link
Member

ndr-brt commented Nov 26, 2024

@chlorochrule when you are ready for another review please re-request my review, so this will be listed on my "review-to-be-done" tab ;)

@chlorochrule chlorochrule requested a review from ndr-brt November 26, 2024 14:02
Comment on lines 64 to 65
extension.vaultRegion = "eu-west-1";
extension.vaultAwsEndpointOverride = "http://localhost:4566";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My suggestion is to use the DependencyInjectionExtension that can be found in the edc-junit module.

Then this test can be written this way:

    @Test
    void configOptionEndpointOverrideProvided_shouldNotThrowException(ObjectFactory factory, ServiceExtensionContext context) {
        var config = ConfigFactory.fromMap(Map.of(
                "edc.vault.aws.region", "region",
                "edc.vault.aws.endpoint.override", "http://localhost:4566"
        ));
        when(context.getConfig()).thenReturn(config);
        var extension = factory.constructInstance(AwsSecretsManagerVaultExtension.class);

        var vault = extension.createVault(context);

        assertThat(vault).extracting("smClient", type(SecretsManagerClient.class)).satisfies(client -> {
            assertThat(client.serviceClientConfiguration().endpointOverride()).contains(URI.create("http://localhost:4566"));
        });
    }

and no need to make the setting fields package private

Comment on lines 39 to 41
@Setting(key = "edc.vault.aws.region",
description = "The AWS Secrets Manager client will point to the specified region")
String vaultRegion;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but to be tackled eventually in a separated issue/PR.

Comment on lines 39 to 41
@Setting(key = "edc.vault.aws.region",
description = "The AWS Secrets Manager client will point to the specified region")
String vaultRegion;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not a good pattern, please see my previous comment

Comment on lines 33 to 39
private static ServiceExtensionContext context;

@BeforeAll
public static void beforeAll() {
context = mock(ServiceExtensionContext.class);
when(context.getMonitor()).thenReturn(mock(Monitor.class));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using DependencyInjectionExtension will make these lines unnecessary


return new AwsSecretsManagerVault(smClient, context.getMonitor(),
new AwsSecretsManagerVaultDefaultSanitationStrategy(context.getMonitor()));
}

private SecretsManagerClient buildSmClient(String vaultRegion) {
private SecretsManagerClient buildSmClient(String vaultRegion, URI vaultEndpointOverride) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would inline this method as it's not really giving any improvement.

@chlorochrule chlorochrule requested a review from ndr-brt November 29, 2024 14:08
Copy link
Member

@ndr-brt ndr-brt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ndr-brt ndr-brt merged commit fa3fbf6 into eclipse-edc:main Dec 2, 2024
8 checks passed
@chlorochrule chlorochrule deleted the feat-aws-vault-endpoint-override branch December 4, 2024 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AwsSecretsManagerVault does not support endpiont overrides
3 participants