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

Introduce Analzyer for exceptions that happen during loading. #1309

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
@@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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())));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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<AwsParameterPropertySourceNotFoundException> {

@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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,4 @@ public ParameterStorePropertySource createPropertySource(String context, boolean
return null;
}

static class AwsParameterPropertySourceNotFoundException extends RuntimeException {

AwsParameterPropertySourceNotFoundException(Exception source) {
super(source);
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading