This repository was archived by the owner on Jan 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 368
Add aws-parameterstore: prefix config import #723
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7aade86
Add aws-parameterstore: prefix config import
eddumelendez ae8e0ac
Remove unused import
eddumelendez 6a31b97
Fix texts
eddumelendez 0825703
Fix tests
eddumelendez 865e6d8
Add license header
eddumelendez 2967827
Take advantage of optional
eddumelendez 728db2f
Polish
eddumelendez 4006bc8
Fallback name with spring.application.name
eddumelendez dc3fcc5
Polish
eddumelendez 73260e4
Polish
eddumelendez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
.../src/main/java/org/springframework/cloud/aws/paramstore/AwsParamStorePropertySources.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* Copyright 2013-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 org.springframework.cloud.aws.paramstore; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement; | ||
import org.apache.commons.logging.Log; | ||
|
||
import org.springframework.util.StringUtils; | ||
|
||
/** | ||
* @author Eddú Meléndez | ||
* @since 2.3 | ||
*/ | ||
public class AwsParamStorePropertySources { | ||
|
||
private final AwsParamStoreProperties properties; | ||
|
||
private final Log log; | ||
|
||
public AwsParamStorePropertySources(AwsParamStoreProperties properties, Log log) { | ||
this.properties = properties; | ||
this.log = log; | ||
} | ||
|
||
public List<String> getAutomaticContexts(List<String> profiles) { | ||
List<String> contexts = new ArrayList<>(); | ||
String prefix = this.properties.getPrefix(); | ||
String defaultContext = getContext(prefix, this.properties.getDefaultContext()); | ||
|
||
String appName = this.properties.getName(); | ||
|
||
String appContext = prefix + "/" + appName; | ||
addProfiles(contexts, appContext, profiles); | ||
contexts.add(appContext + "/"); | ||
|
||
addProfiles(contexts, defaultContext, profiles); | ||
contexts.add(defaultContext + "/"); | ||
return contexts; | ||
} | ||
|
||
protected String getContext(String prefix, String context) { | ||
if (StringUtils.hasLength(prefix)) { | ||
return prefix + "/" + context; | ||
} | ||
return context; | ||
} | ||
|
||
private void addProfiles(List<String> contexts, String baseContext, List<String> profiles) { | ||
for (String profile : profiles) { | ||
contexts.add(baseContext + this.properties.getProfileSeparator() + profile + "/"); | ||
} | ||
} | ||
|
||
/** | ||
* Creates property source for given context. | ||
* @param context property source context equivalent to the parameter name | ||
* @param optional if creating context should fail with exception if parameter cannot | ||
* be loaded | ||
* @param client System Manager Management client | ||
* @return a property source or null if parameter could not be loaded and optional is | ||
* set to true | ||
*/ | ||
public AwsParamStorePropertySource createPropertySource(String context, boolean optional, | ||
AWSSimpleSystemsManagement client) { | ||
try { | ||
AwsParamStorePropertySource propertySource = new AwsParamStorePropertySource(context, client); | ||
propertySource.init(); | ||
return propertySource; | ||
// TODO: howto call close when /refresh | ||
} | ||
catch (Exception e) { | ||
if (!optional) { | ||
throw new AwsParameterPropertySourceNotFoundException(e); | ||
} | ||
else { | ||
log.warn("Unable to load AWS parameter from " + context + ". " + e.getMessage()); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
static class AwsParameterPropertySourceNotFoundException extends RuntimeException { | ||
|
||
AwsParameterPropertySourceNotFoundException(Exception source) { | ||
super(source); | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to how i suggested in SM integration, we should add logging information: 21011e6#diff-ab9058ccbead5f4685b9fc609e6e10808f622475492ea1b099af6994edfa3e70R80