This repository was archived by the owner on Jan 19, 2022. It is now read-only.
  
  
  - 
        Couldn't load subscription status. 
- Fork 364
Feature/AppConfig as PropertySource #652
          
     Open
      
      
            jarpz
  wants to merge
  74
  commits into
  spring-attic:2.3.x
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
jarpz:feature/app-config
  
      
      
   
  
    
  
  
  
 
  
      
    base: 2.3.x
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from 5 commits
      Commits
    
    
            Show all changes
          
          
            74 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      a6e7c73
              
                Fix AwsSecretsManagerProperties.prefix javadoc
              
              
                sixcorners d52dae1
              
                Bumping versions
              
              
                spring-builds 33e1535
              
                Bumping versions
              
              
                spring-builds 328b130
              
                Updated docs
              
              
                marcingrzejszczak 9294f1c
              
                Merge branch '2.2.x'
              
              
                spencergibb 5ac4cdb
              
                Bumps versions to 3.0.0-SNAPHOT
              
              
                spencergibb 6d84666
              
                Merge pull request #484 from sixcorners/patch-1
              
              
                maciejwalkowiak e540b7c
              
                Update of documentation regarding supported DB engines that Amazon RD…
              
              
                DJakosa 37b1251
              
                Fix "Sending a message" reference documentation code samples.
              
              
                luramarchanjo c935e72
              
                Fixes SNS auto configuration when Spring WebMvc is not on the classpath.
              
              
                kingbbode 5f5d8bc
              
                Remove the misleading property in documentation of spring-cloud-aws-rds.
              
              
                SenthilPanneerselvam e805878
              
                Rename config properties in ContextCredentialsAutoConfiguration to ke…
              
              
                lukasznyrc 4c11014
              
                Add tests for relaxed binding support in "cloud.aws.credentials".
              
              
                tac-yacht 6e3f32d
              
                Allow ConditionalOnAwsCloudEnvironment to be used on method level.
              
              
                bsamartins e72a3d2
              
                Set CloudWatchProperties default batch size to API max.
              
              
                bsamartins 159200b
              
                Add option to use default AWS region provider chain.
              
              
                maciejwalkowiak f6100dd
              
                Add logging to AWSParameterStorePropertySource.
              
              
                cschroedl-gov 6da9925
              
                Update documentation on how to hide warning message logged by AWS SDK…
              
              
                maciejwalkowiak 8caf811
              
                Fix typo in the exception text
              
              
                tmnuwan12 7a052a5
              
                Bump AWS Java SDK dependency version to 1.11.792.
              
              
                maciejwalkowiak f2ab807
              
                Update reference documentation on how to upgrade AWS SDK dependency.
              
              
                maciejwalkowiak 58e636d
              
                Fix S3 object key encoding in `SimpleStorageResource.getURL`.
              
              
                 deb9088
              
                Fix duplicate error logging when processing exception thrown in SQS l…
              
              
                sayembd 76df24c
              
                Allow to specify PropertySource name returned by AwsSecretsManagerPro…
              
              
                cbm-afoulfoin eb4d65a
              
                Add a dependency to JUnit 4.
              
              
                maciejwalkowiak f61178d
              
                Document default credentials chain for auto-configuration.
              
              
                maciejwalkowiak 211990c
              
                Add CloudWatch integration documentation to the reference.
              
              
                maciejwalkowiak 2a59abf
              
                Add a method to get S3 URI from a SimpleStorageResource.
              
              
                tmnuwan12 647375b
              
                Fix StackResourceRegistry creation when CloudFormation support is tur…
              
              
                maciejwalkowiak 38c7e6a
              
                Drop XML support in all modules and integration tests.
              
              
                maciejwalkowiak 8af3aca
              
                Changed packaging to jar
              
              
                marcingrzejszczak 6a7580b
              
                Remove Autowired annotations
              
              
                eddumelendez 80391e9
              
                Enforce spring-javaformat plugin
              
              
                eddumelendez 650cc69
              
                Use DefaultAWSCredentialsProvider and DefaultAWSRegionProviderChain b…
              
              
                maciejwalkowiak 68799fb
              
                Migrate to JUnit 5.
              
              
                DarrenForsythe 0c84250
              
                Merge branch '2.3.x'
              
              
                eddumelendez 11e5078
              
                Merge branch '2.3.x'
              
              
                eddumelendez 7817a37
              
                Configure SQS to use existing ObjectMapper if present in application …
              
              
                maciejwalkowiak ddde60b
              
                Drop dependency to javax.validation in Parameter Store and Secrets Ma…
              
              
                MatejNedic dea203b
              
                Merge branch '2.3.x'
              
              
                maciejwalkowiak babe84f
              
                Merge branch '2.3.x'
              
              
                maciejwalkowiak 6148d73
              
                Merge branch '2.3.x'
              
              
                maciejwalkowiak fec66b9
              
                Merge branch '2.3.x'
              
              
                maciejwalkowiak eea7e8f
              
                Merge branch '2.3.x'
              
              
                maciejwalkowiak 9e5c01c
              
                Merge branch '2.3.x'
              
              
                maciejwalkowiak 045fd9c
              
                Merge branch '2.3.x'
              
              
                maciejwalkowiak 582fdc6
              
                Merge branch '2.3.x'
              
              
                maciejwalkowiak 53275a2
              
                Merge branch '2.3.x'
              
              
                maciejwalkowiak 2f63fe3
              
                Merge branch '2.3.x'
              
              
                maciejwalkowiak 2b26b92
              
                Merge branch '2.3.x'
              
              
                eddumelendez 82a873c
              
                Merge branch '2.3.x'
              
              
                maciejwalkowiak 7f01157
              
                Merge branch '2.3.x'
              
              
                eddumelendez ff28c4b
              
                Update version
              
              
                eddumelendez 7244864
              
                Merge branch '2.3.x'
              
              
                eddumelendez fcbb893
              
                Merge branch '2.3.x'
              
              
                maciejwalkowiak 26c5435
              
                Merge branch '2.3.x'
              
              
                eddumelendez 6f67aeb
              
                Merge branch '2.3.x'
              
              
                eddumelendez e72fce9
              
                Merge branch '2.3.x'
              
              
                eddumelendez 926a6ca
              
                Merge branch '2.3.x'
              
              
                maciejwalkowiak 10d2b77
              
                Merge branch '2.3.x'
              
              
                maciejwalkowiak b506a9f
              
                Merge branch '2.3.x'
              
              
                maciejwalkowiak 24b2068
              
                Merge branch '2.3.x' into master
              
              
                 4d0b386
              
                feat(aws-appconfig): add appconfig & starter-appconfig modules
              
              
                jarpz 7eba07c
              
                feat(aws-appconfig): add aws appconfig component
              
              
                jarpz 241d6d3
              
                feat(aws-appconfig): add starter appconfig
              
              
                jarpz 33d2559
              
                feat(aws-appconfig): rename module removing config suffix
              
              
                jarpz d21e4dc
              
                feat(aws-appconfig): move classes & fix comments
              
              
                jarpz ebd950e
              
                feat(aws-appconfig): remove unused dependencies
              
              
                jarpz c373eec
              
                test(aws-appconfig): change tests to use ApplicationContextRunner
              
              
                jarpz fd58ab1
              
                feat(aws-appconfig): change properties prefix to spring.cloud.aws.* +…
              
              
                jarpz 2cbf279
              
                feat(aws-appconfig): use assert when appName is empty or null
              
              
                jarpz 33d96f5
              
                feat(aws-appconfig): rename accountId as clientId + allow default ran…
              
              
                jarpz b2cad8d
              
                Merge branch 'master' of https://github.com/jarpz/spring-cloud-aws in…
              
              
                jarpz e3cfc4d
              
                feat: Align code with master branch & fix code style
              
              
                jarpz 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
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- | ||
| ~ 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. | ||
| --> | ||
| <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <parent> | ||
| <groupId>org.springframework.cloud</groupId> | ||
| <artifactId>spring-cloud-aws</artifactId> | ||
| <version>2.3.0.BUILD-SNAPSHOT</version> | ||
| </parent> | ||
|  | ||
| <artifactId>spring-cloud-aws-appconfig</artifactId> | ||
|  | ||
| <name>Spring Cloud AWS AppConfig Configuration</name> | ||
| <description>Spring Cloud AWS AppConfig Configuration</description> | ||
|  | ||
|  | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.springframework</groupId> | ||
| <artifactId>spring-context</artifactId> | ||
| </dependency> | ||
|  | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-autoconfigure</artifactId> | ||
| </dependency> | ||
|  | ||
| <dependency> | ||
| <groupId>org.springframework.cloud</groupId> | ||
| <artifactId>spring-cloud-context</artifactId> | ||
| </dependency> | ||
|  | ||
| <dependency> | ||
| <groupId>com.amazonaws</groupId> | ||
| <artifactId>aws-java-sdk-appconfig</artifactId> | ||
| </dependency> | ||
|  | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-configuration-processor</artifactId> | ||
|         
                  eddumelendez marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| <optional>true</optional> | ||
| </dependency> | ||
| </dependencies> | ||
|  | ||
|  | ||
| </project> | ||
        
          
          
            162 changes: 162 additions & 0 deletions
          
          162 
        
  ...fig/src/main/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySource.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,162 @@ | ||
| /* | ||
| * 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.appconfig; | ||
|  | ||
| import java.io.IOException; | ||
| import java.nio.ByteBuffer; | ||
| import java.util.Collection; | ||
| import java.util.Iterator; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
| import java.util.Properties; | ||
| import java.util.Set; | ||
|  | ||
| import com.amazonaws.services.appconfig.AmazonAppConfig; | ||
| import com.amazonaws.services.appconfig.model.GetConfigurationRequest; | ||
| import com.amazonaws.services.appconfig.model.GetConfigurationResult; | ||
| import com.fasterxml.jackson.core.type.TypeReference; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
|  | ||
| import org.springframework.beans.factory.config.YamlPropertiesFactoryBean; | ||
| import org.springframework.core.env.EnumerablePropertySource; | ||
| import org.springframework.core.io.ByteArrayResource; | ||
| import org.springframework.util.ReflectionUtils; | ||
|  | ||
| /** | ||
| * @author jarpz | ||
| */ | ||
| public class AwsAppConfigPropertySource | ||
| extends EnumerablePropertySource<AmazonAppConfig> { | ||
|  | ||
| private static final String SUPPORTED_TYPE_JSON = "application/json"; | ||
|  | ||
| private static final String SUPPORTED_TYPE_YAML = "application/x-yaml"; | ||
|  | ||
| private final String accountId; | ||
|  | ||
| private final String application; | ||
|  | ||
| private final String configurationVersion; | ||
|  | ||
| private final String environment; | ||
|  | ||
| private Properties properties; | ||
|  | ||
| public AwsAppConfigPropertySource(String name, String accountId, String application, | ||
| String environment, String configurationVersion, | ||
| AmazonAppConfig appConfigClient) { | ||
| super(name, appConfigClient); | ||
| this.accountId = accountId; | ||
| this.application = application; | ||
| this.configurationVersion = configurationVersion; | ||
| this.environment = environment; | ||
| } | ||
|  | ||
| public void init() { | ||
| GetConfigurationRequest request = new GetConfigurationRequest() | ||
| .withClientId(accountId).withApplication(application) | ||
| .withConfiguration(name) | ||
| .withClientConfigurationVersion(configurationVersion) | ||
| .withEnvironment(environment); | ||
|  | ||
| getAppConfig(request); | ||
| } | ||
|  | ||
| @Override | ||
| public String[] getPropertyNames() { | ||
| Set<String> strings = properties.stringPropertyNames(); | ||
| return strings.toArray(new String[strings.size()]); | ||
| } | ||
|  | ||
| @Override | ||
| public Object getProperty(String name) { | ||
| return properties.get(name); | ||
| } | ||
|  | ||
| private void getAppConfig(GetConfigurationRequest request) { | ||
| GetConfigurationResult result = this.source.getConfiguration(request); | ||
|  | ||
| logger.trace(String.format("loading file: %s/%s/%s/%s", application, name, | ||
| environment, result.getConfigurationVersion())); | ||
|  | ||
| switch (result.getContentType()) { | ||
| case SUPPORTED_TYPE_YAML: | ||
| processYamlContent(result.getContent()); | ||
| break; | ||
| case SUPPORTED_TYPE_JSON: | ||
| processJsonContent(result.getContent()); | ||
| break; | ||
| default: | ||
| throw new IllegalStateException(String.format("Unsupported content type: %s", | ||
| result.getContentType())); | ||
| } | ||
| } | ||
|  | ||
| private void processYamlContent(ByteBuffer byteBuffer) { | ||
| YamlPropertiesFactoryBean bean = new YamlPropertiesFactoryBean(); | ||
|  | ||
| bean.setResources(new ByteArrayResource(byteBuffer.array())); | ||
|  | ||
| properties = bean.getObject(); | ||
| } | ||
|  | ||
| private void processJsonContent(ByteBuffer byteBuffer) { | ||
| try { | ||
| Map<String, Object> map = new ObjectMapper().readValue(byteBuffer.array(), | ||
| new TypeReference<Map<String, Object>>() { | ||
| }); | ||
|  | ||
| Map<String, Object> result = new LinkedHashMap<>(); | ||
| this.flatten(null, result, map); | ||
|  | ||
| properties = new Properties(); | ||
| properties.putAll(result); | ||
| } | ||
| catch (IOException ex) { | ||
| ReflectionUtils.rethrowRuntimeException(ex); | ||
| } | ||
| } | ||
|  | ||
| /** | ||
| * flatten json structure. | ||
| */ | ||
| private void flatten(String prefix, Map<String, Object> result, | ||
| Map<String, Object> map) { | ||
| String namePrefix = Objects.nonNull(prefix) ? prefix + "." : ""; | ||
|  | ||
| map.forEach((key, value) -> this.extract(namePrefix + key, result, value)); | ||
| } | ||
|  | ||
| private void extract(String name, Map<String, Object> result, Object value) { | ||
| if (value instanceof Map) { | ||
| this.flatten(name, result, (Map) value); | ||
| } | ||
| else if (value instanceof Collection) { | ||
| int index = 0; | ||
|  | ||
| for (Iterator it = ((Collection) value).iterator(); it.hasNext(); ++index) { | ||
| Object object = it.next(); | ||
| this.extract(name + "[" + index + "]", result, object); | ||
| } | ||
| } | ||
| else { | ||
| result.put(name, value); | ||
| } | ||
| } | ||
|  | ||
| } | 
        
          
          
            110 changes: 110 additions & 0 deletions
          
          110 
        
  .../main/java/org/springframework/cloud/aws/appconfig/AwsAppConfigPropertySourceLocator.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,110 @@ | ||
| /* | ||
| * 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.appconfig; | ||
|  | ||
| import com.amazonaws.services.appconfig.AmazonAppConfig; | ||
| import org.apache.commons.logging.Log; | ||
| import org.apache.commons.logging.LogFactory; | ||
|  | ||
| import org.springframework.cloud.bootstrap.config.PropertySourceLocator; | ||
| import org.springframework.core.env.CompositePropertySource; | ||
| import org.springframework.core.env.ConfigurableEnvironment; | ||
| import org.springframework.core.env.Environment; | ||
| import org.springframework.core.env.PropertySource; | ||
| import org.springframework.util.ReflectionUtils; | ||
|  | ||
| import static java.util.Objects.isNull; | ||
| import static java.util.Objects.requireNonNull; | ||
|  | ||
| /** | ||
| * @author jarpz | ||
| */ | ||
| public class AwsAppConfigPropertySourceLocator implements PropertySourceLocator { | ||
|  | ||
| private final AmazonAppConfig appConfigClient; | ||
|  | ||
| private final String accountId; | ||
|  | ||
| private final String application; | ||
|  | ||
| private final String configurationProfile; | ||
|  | ||
| private final String environment; | ||
|  | ||
| private final String configurationVersion; | ||
|  | ||
| private final boolean failFast; | ||
|  | ||
| private static final Log logger = LogFactory | ||
| .getLog(AwsAppConfigPropertySourceLocator.class); | ||
|  | ||
| public AwsAppConfigPropertySourceLocator(AmazonAppConfig appConfigClient, | ||
| String accountId, String application, String configurationProfile, | ||
| String environment, String configurationVersion, boolean failFast) { | ||
| this.appConfigClient = appConfigClient; | ||
| this.accountId = accountId; | ||
| this.application = application; | ||
| this.configurationProfile = configurationProfile; | ||
| this.environment = environment; | ||
| this.configurationVersion = configurationVersion; | ||
| this.failFast = failFast; | ||
| } | ||
|  | ||
| @Override | ||
| public PropertySource<?> locate(Environment environment) { | ||
| if (!(environment instanceof ConfigurableEnvironment)) { | ||
| return null; | ||
| } | ||
|  | ||
| ConfigurableEnvironment env = (ConfigurableEnvironment) environment; | ||
|  | ||
| String appName = configurationProfile; | ||
| if (isNull(appName)) { | ||
| appName = requireNonNull(env.getProperty("spring.application.name"), | ||
| "configurationProfile should not be empty or null."); | ||
| } | ||
|  | ||
| CompositePropertySource composite = new CompositePropertySource("aws-app-config"); | ||
|  | ||
| try { | ||
| composite.addPropertySource(create(appName)); | ||
| } | ||
| catch (Exception ex) { | ||
| if (failFast) { | ||
| logger.error( | ||
| "Fail fast is set and there was an error reading configuration from AWS AppConfig: {}", | ||
| ex); | ||
| ReflectionUtils.rethrowRuntimeException(ex); | ||
| } | ||
| else { | ||
| logger.warn("Unable to load AWS AppConfig from " + appName, ex); | ||
| } | ||
| } | ||
|  | ||
| return composite; | ||
| } | ||
|  | ||
| private AwsAppConfigPropertySource create(String appName) { | ||
| AwsAppConfigPropertySource propertySource = new AwsAppConfigPropertySource( | ||
| appName, accountId, application, environment, configurationVersion, | ||
| appConfigClient); | ||
| propertySource.init(); | ||
|  | ||
| return propertySource; | ||
| } | ||
|  | ||
| } | 
      
      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.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.