diff --git a/spring-cloud-gcp-secretmanager/src/main/java/com/google/cloud/spring/secretmanager/SecretManagerPropertySourceLocator.java b/spring-cloud-gcp-secretmanager/src/main/java/com/google/cloud/spring/secretmanager/SecretManagerPropertySourceLocator.java deleted file mode 100644 index 9976c2c685..0000000000 --- a/spring-cloud-gcp-secretmanager/src/main/java/com/google/cloud/spring/secretmanager/SecretManagerPropertySourceLocator.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2017-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.cloud.spring.secretmanager; - -import com.google.cloud.spring.core.GcpProjectIdProvider; -import org.springframework.cloud.bootstrap.config.PropertySourceLocator; -import org.springframework.core.env.Environment; -import org.springframework.core.env.PropertySource; - -/** - * Implementation of {@link PropertySourceLocator} which provides GCP Secret Manager as a property - * source. - * - * @since 1.2.2 - */ -public class SecretManagerPropertySourceLocator implements PropertySourceLocator { - - private static final String SECRET_MANAGER_NAME = "spring-cloud-gcp-secret-manager"; - - private final SecretManagerTemplate template; - - private final GcpProjectIdProvider projectIdProvider; - - public SecretManagerPropertySourceLocator( - SecretManagerTemplate template, GcpProjectIdProvider projectIdProvider) { - this.template = template; - this.projectIdProvider = projectIdProvider; - } - - @Override - public PropertySource locate(Environment environment) { - return new SecretManagerPropertySource( - SECRET_MANAGER_NAME, this.template, this.projectIdProvider); - } -} diff --git a/spring-cloud-gcp-secretmanager/src/test/java/com/google/cloud/spring/secretmanager/it/SecretManagerPropertySourceIntegrationTests.java b/spring-cloud-gcp-secretmanager/src/test/java/com/google/cloud/spring/secretmanager/it/SecretManagerPropertySourceIntegrationTests.java deleted file mode 100644 index 23e716c871..0000000000 --- a/spring-cloud-gcp-secretmanager/src/test/java/com/google/cloud/spring/secretmanager/it/SecretManagerPropertySourceIntegrationTests.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 2017-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.cloud.spring.secretmanager.it; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - -import com.google.cloud.spring.secretmanager.SecretManagerTemplate; -import io.grpc.StatusRuntimeException; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.EnabledIfSystemProperty; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.WebApplicationType; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@EnabledIfSystemProperty(named = "it.secretmanager", matches = "true") -class SecretManagerPropertySourceIntegrationTests { - - private ConfigurableApplicationContext context = - new SpringApplicationBuilder(SecretManagerTestConfiguration.class, TestConfiguration.class) - .web(WebApplicationType.NONE) - .properties("spring.cloud.bootstrap.enabled=true") - .run(); - - private static final String TEST_SECRET_ID = "spring-cloud-gcp-it-secret"; - - @BeforeAll - static void prepare() { - // Create the test secret if it does not already currently exist. - ConfigurableApplicationContext setupContext = - new SpringApplicationBuilder(SecretManagerTestConfiguration.class) - .web(WebApplicationType.NONE) - .run(); - - SecretManagerTemplate template = - setupContext.getBeanFactory().getBean(SecretManagerTemplate.class); - if (!template.secretExists(TEST_SECRET_ID)) { - template.createSecret(TEST_SECRET_ID, "the secret data."); - } - } - - @Test - void testConfiguration() { - assertThat(context.getEnvironment().getProperty("sm://" + TEST_SECRET_ID)) - .isEqualTo("the secret data."); - - byte[] byteArraySecret = - context.getEnvironment().getProperty("sm://" + TEST_SECRET_ID + "/latest", byte[].class); - assertThat(byteArraySecret).isEqualTo("the secret data.".getBytes()); - } - - @Test - void testValueAnnotation() { - String secret = context.getBean("secret", String.class); - assertThat(secret).isEqualTo("the secret data."); - } - - @Test - void testMissingSecret() { - assertThatThrownBy( - () -> context.getEnvironment().getProperty("sm://missing-secret/10", String.class)) - .hasCauseInstanceOf(StatusRuntimeException.class) - .hasMessageContaining("NOT_FOUND"); - } - - @Configuration - static class TestConfiguration { - - @Value("${sm://" + TEST_SECRET_ID + "}") - private String secret; - - @Bean - public String secret() { - return secret; - } - } -} diff --git a/spring-cloud-gcp-secretmanager/src/test/java/com/google/cloud/spring/secretmanager/it/SecretManagerTestConfiguration.java b/spring-cloud-gcp-secretmanager/src/test/java/com/google/cloud/spring/secretmanager/it/SecretManagerTestConfiguration.java index 6edc2f707c..c76d8d03ea 100644 --- a/spring-cloud-gcp-secretmanager/src/test/java/com/google/cloud/spring/secretmanager/it/SecretManagerTestConfiguration.java +++ b/spring-cloud-gcp-secretmanager/src/test/java/com/google/cloud/spring/secretmanager/it/SecretManagerTestConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2020 the original author or authors. + * Copyright 2017-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,11 +25,9 @@ import com.google.cloud.spring.core.DefaultGcpProjectIdProvider; import com.google.cloud.spring.core.GcpEnvironmentProvider; import com.google.cloud.spring.core.GcpProjectIdProvider; -import com.google.cloud.spring.secretmanager.SecretManagerPropertySourceLocator; import com.google.cloud.spring.secretmanager.SecretManagerTemplate; import com.google.protobuf.ByteString; import java.io.IOException; -import org.springframework.cloud.bootstrap.config.PropertySourceLocator; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.convert.converter.Converter; @@ -94,12 +92,4 @@ public SecretManagerServiceClient secretManagerClient() throws IOException { public SecretManagerTemplate secretManagerTemplate(SecretManagerServiceClient client) { return new SecretManagerTemplate(client, this.projectIdProvider); } - - @Bean - public PropertySourceLocator secretManagerPropertySourceLocator( - SecretManagerTemplate secretManagerTemplate) { - SecretManagerPropertySourceLocator propertySourceLocator = - new SecretManagerPropertySourceLocator(secretManagerTemplate, this.projectIdProvider); - return propertySourceLocator; - } }