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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

chlorochrule
Copy link

@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
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
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
Author

Choose a reason for hiding this comment

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

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

@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
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
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

Comment on lines +64 to +65
extension.vaultRegion = "eu-west-1";
extension.vaultAwsEndpointOverride = "http://localhost:4566";
Copy link
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!

@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 ;)

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