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

fix(kms): to honor kms credentials when present. #1272

Merged
merged 6 commits into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -40,18 +40,20 @@
public class GcpKmsAutoConfiguration {

private final GcpProjectIdProvider gcpProjectIdProvider;
private final CredentialsProvider credentialsProvider;

public GcpKmsAutoConfiguration(GcpKmsProperties properties) {
public GcpKmsAutoConfiguration(GcpKmsProperties properties,
CredentialsProvider credentialsProvider)
throws IOException {
this.gcpProjectIdProvider =
properties.getProjectId() != null
? properties::getProjectId
: new DefaultGcpProjectIdProvider();
}

@Bean
@ConditionalOnMissingBean
public CredentialsProvider googleCredentials(GcpKmsProperties kmsProperties) throws IOException {
return new DefaultCredentialsProvider(kmsProperties);
this.credentialsProvider =
properties.getCredentials().hasKey()
? new DefaultCredentialsProvider(properties)
: credentialsProvider;
}

@Bean
Expand All @@ -60,7 +62,7 @@ public KeyManagementServiceClient keyManagementClient(CredentialsProvider google
throws IOException {
KeyManagementServiceSettings settings =
KeyManagementServiceSettings.newBuilder()
.setCredentialsProvider(googleCredentials)
.setCredentialsProvider(this.credentialsProvider)
.setHeaderProvider(new UserAgentHeaderProvider(GcpKmsAutoConfiguration.class))
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,6 @@ void testKmsTemplateCreated() {
@Configuration
static class TestBootstrapConfiguration {

@Bean
public static KeyManagementServiceClient keyManagementClient() {
KeyManagementServiceClient client = mock(KeyManagementServiceClient.class);
return client;
}

@Bean
public static CredentialsProvider googleCredentials() {
return () -> mock(Credentials.class);
Expand Down