diff --git a/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/config/parameterstore/AwsParameterPropertySourceNotFoundException.java b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/config/parameterstore/AwsParameterPropertySourceNotFoundException.java new file mode 100644 index 000000000..f66055123 --- /dev/null +++ b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/config/parameterstore/AwsParameterPropertySourceNotFoundException.java @@ -0,0 +1,24 @@ +/* + * Copyright 2013-2024 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 io.awspring.cloud.autoconfigure.config.parameterstore; + +public class AwsParameterPropertySourceNotFoundException extends RuntimeException { + + AwsParameterPropertySourceNotFoundException(Exception source) { + super(source); + } + +} diff --git a/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/config/parameterstore/ParameterStoreConfigDataLoader.java b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/config/parameterstore/ParameterStoreConfigDataLoader.java index 4c176528b..89fbe1bea 100644 --- a/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/config/parameterstore/ParameterStoreConfigDataLoader.java +++ b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/config/parameterstore/ParameterStoreConfigDataLoader.java @@ -22,7 +22,6 @@ import org.springframework.boot.context.config.ConfigData; import org.springframework.boot.context.config.ConfigDataLoader; import org.springframework.boot.context.config.ConfigDataLoaderContext; -import org.springframework.boot.context.config.ConfigDataResourceNotFoundException; import org.springframework.boot.logging.DeferredLogFactory; import org.springframework.core.env.MapPropertySource; import org.springframework.lang.Nullable; @@ -47,28 +46,23 @@ public ParameterStoreConfigDataLoader(DeferredLogFactory logFactory) { @Override @Nullable public ConfigData load(ConfigDataLoaderContext context, ParameterStoreConfigDataResource resource) { - try { - // resource is disabled if parameter store integration is disabled via - // spring.cloud.aws.parameterstore.enabled=false - if (resource.isEnabled()) { - SsmClient ssm = context.getBootstrapContext().get(SsmClient.class); - ParameterStorePropertySource propertySource = resource.getPropertySources() - .createPropertySource(resource.getContext(), resource.isOptional(), ssm); - if (propertySource != null) { - return new ConfigData(Collections.singletonList(propertySource)); - } - else { - return null; - } + // resource is disabled if parameter store integration is disabled via + // spring.cloud.aws.parameterstore.enabled=false + if (resource.isEnabled()) { + SsmClient ssm = context.getBootstrapContext().get(SsmClient.class); + ParameterStorePropertySource propertySource = resource.getPropertySources() + .createPropertySource(resource.getContext(), resource.isOptional(), ssm); + if (propertySource != null) { + return new ConfigData(Collections.singletonList(propertySource)); } else { - // create dummy empty config data - return new ConfigData( - Collections.singletonList(new MapPropertySource("aws-parameterstore:" + context, Map.of()))); + return null; } } - catch (Exception e) { - throw new ConfigDataResourceNotFoundException(resource, e); + else { + // create dummy empty config data + return new ConfigData( + Collections.singletonList(new MapPropertySource("aws-parameterstore:" + context, Map.of()))); } } diff --git a/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/config/parameterstore/ParameterStoreExceptionHappenedAnalyzer.java b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/config/parameterstore/ParameterStoreExceptionHappenedAnalyzer.java new file mode 100644 index 000000000..00452268b --- /dev/null +++ b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/config/parameterstore/ParameterStoreExceptionHappenedAnalyzer.java @@ -0,0 +1,29 @@ +/* + * Copyright 2013-2024 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 io.awspring.cloud.autoconfigure.config.parameterstore; + +import org.springframework.boot.diagnostics.AbstractFailureAnalyzer; +import org.springframework.boot.diagnostics.FailureAnalysis; + +public class ParameterStoreExceptionHappenedAnalyzer + extends AbstractFailureAnalyzer { + + @Override + protected FailureAnalysis analyze(Throwable rootFailure, AwsParameterPropertySourceNotFoundException cause) { + return new FailureAnalysis("Could not import properties from AWS Parameter Store: " + cause.getMessage(), + "Depending on error message determine action course", cause); + } +} diff --git a/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/config/parameterstore/ParameterStorePropertySources.java b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/config/parameterstore/ParameterStorePropertySources.java index badb741b5..11ab0bb69 100644 --- a/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/config/parameterstore/ParameterStorePropertySources.java +++ b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/config/parameterstore/ParameterStorePropertySources.java @@ -57,12 +57,4 @@ public ParameterStorePropertySource createPropertySource(String context, boolean return null; } - static class AwsParameterPropertySourceNotFoundException extends RuntimeException { - - AwsParameterPropertySourceNotFoundException(Exception source) { - super(source); - } - - } - } diff --git a/spring-cloud-aws-autoconfigure/src/main/resources/META-INF/spring.factories b/spring-cloud-aws-autoconfigure/src/main/resources/META-INF/spring.factories index 171dee2ad..6dd5278a9 100644 --- a/spring-cloud-aws-autoconfigure/src/main/resources/META-INF/spring.factories +++ b/spring-cloud-aws-autoconfigure/src/main/resources/META-INF/spring.factories @@ -13,5 +13,6 @@ io.awspring.cloud.autoconfigure.config.s3.S3ConfigDataLoader # Failure Analyzers org.springframework.boot.diagnostics.FailureAnalyzer=\ io.awspring.cloud.autoconfigure.config.parameterstore.ParameterStoreMissingKeysFailureAnalyzer, \ +io.awspring.cloud.autoconfigure.config.parameterstore.ParameterStoreExceptionHappenedAnalyzer, \ io.awspring.cloud.autoconfigure.config.secretsmanager.SecretsManagerMissingKeysFailureAnalyzer,\ io.awspring.cloud.autoconfigure.config.s3.S3MissingKeysFailureAnalyzer