package com.kryptnostic.rhizome.pods;

import com.amazonaws.regions.Region;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.kryptnostic.rhizome.configuration.ConfigurationConstants.Profiles;
import com.kryptnostic.rhizome.configuration.amazon.AmazonLaunchConfiguration;
import com.kryptnostic.rhizome.configuration.amazon.AwsLaunchConfiguration;
import com.openlattice.ResourceConfigurationLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Profile;

/**
 * Used for bootstrapping configuration from a (secure) S3 bucket.
 */
@Profile( { Profiles.AWS_CONFIGURATION_PROFILE, Profiles.AWS_TESTING_PROFILE } )
@Configuration
public class AwsConfigurationPod {
    private static final Logger   logger = LoggerFactory.getLogger( ConfigurationPod.class );
    private static final AmazonS3 s3     = new AmazonS3Client();
  private  static final AmazonLaunchConfiguration awsTestConfig;
  private  static final AmazonLaunchConfiguration awsConfig;
  static {
      awsConfig = ResourceConfigurationLoader
              .loadConfigurationFromResource( "aws.yaml", AwsLaunchConfiguration.class );
      awsTestConfig = ResourceConfigurationLoader
              .loadConfigurationFromResource( "awstest.yaml", AwsLaunchConfiguration.class );
  }
    @Bean(name="awsConfig")
    @Profile( Profiles.AWS_CONFIGURATION_PROFILE )
    public AmazonLaunchConfiguration awsConfig() {
        logger.info( "Using aws configuration: {}", awsConfig );
        if( awsConfig.getRegion().isPresent() ) {
            s3.setRegion( Region.getRegion(awsConfig().getRegion().get() ) );
        }
        return awsConfig;
    }

    @Bean(name="awsConfig")
    @Profile( Profiles.AWS_TESTING_PROFILE )
    public AmazonLaunchConfiguration awsTestingConfig() {
        logger.info( "Using aws configuration: {}", awsTestConfig );
        if( awsTestConfig.getRegion().isPresent() ) {
            s3.setRegion( Region.getRegion(awsConfig().getRegion().get() ) );
        }
        return awsTestConfig;
    }

    @Bean
    public AmazonS3 s3() {
      return s3;
    }

}

@@ -620,62 +620,8 @@
 on;%0A
-import org.springframework.context.annotation.Import;%0A
 impo
@@ -671,16 +671,16 @@
 rofile;%0A
+
 %0A/**%0A * 
@@ -1037,16 +1037,18 @@
 ient();%0A
+  
   privat
@@ -1041,33 +1041,32 @@
 ();%0A    private 
- 
 static final Ama
@@ -1103,16 +1103,18 @@
 Config;%0A
+  
   privat
@@ -1115,17 +1115,16 @@
 private 
- 
 static f
@@ -1165,16 +1165,19 @@
 Config;%0A
+%0A  
   static
@@ -1179,16 +1179,18 @@
 tatic %7B%0A
+  
       aw
@@ -1233,32 +1233,34 @@
 r%0A              
+ 
+ 
 .loadConfigurati
@@ -1315,24 +1315,26 @@
 on.class );%0A
+  
       awsTes
@@ -1377,32 +1377,34 @@
 r%0A              
+  
 .loadConfigurati
@@ -1469,17 +1469,20 @@
 ss );%0A  
+ 
-%7D
+ %7D%0A
 %0A    @Be
@@ -1476,37 +1476,40 @@
    %7D%0A%0A    @Bean(
+ 
 name
-=
+ = 
 %22awsConfig%22)%0A   
@@ -1495,32 +1495,33 @@
 me = %22awsConfig%22
+ 
 )%0A    @Profile( 
@@ -1679,24 +1679,25 @@
 ;%0A        if
+ 
 ( awsConfig.
@@ -1759,32 +1759,33 @@
 egion.getRegion(
+ 
 awsConfig().getR
@@ -1769,34 +1769,32 @@
 egion( awsConfig
-()
 .getRegion().get
@@ -1858,13 +1858,16 @@
 ean(
+ 
 name
-=
+ = 
 %22aws
@@ -1873,16 +1873,17 @@
 sConfig%22
+ 
 )%0A    @P
@@ -2058,16 +2058,17 @@
       if
+ 
 ( awsTes
@@ -2146,27 +2146,30 @@
 tRegion(
+ 
 aws
+Test
 Config
-()
 .getRegi
@@ -2264,24 +2264,26 @@
 onS3 s3() %7B%0A
+  
       return

Use correct regions