001 package org.kuali.common.deploy.aws.spring;
002
003 import org.kuali.common.deploy.aws.model.AwsContext;
004 import org.kuali.common.deploy.aws.model.EC2Context;
005 import org.kuali.common.deploy.aws.model.S3Context;
006 import org.kuali.common.deploy.aws.model.SesContext;
007 import org.kuali.common.deploy.aws.model.SesCredentials;
008 import org.kuali.common.util.spring.env.EnvironmentService;
009 import org.kuali.common.util.spring.service.SpringServiceConfig;
010 import org.springframework.beans.factory.annotation.Autowired;
011 import org.springframework.context.annotation.Bean;
012 import org.springframework.context.annotation.Configuration;
013 import org.springframework.context.annotation.Import;
014
015 @Configuration
016 @Import({ SpringServiceConfig.class })
017 public class DefaultAwsContextConfig implements AwsContextConfig {
018
019 @Autowired
020 EnvironmentService env;
021
022 @Override
023 @Bean
024 public AwsContext awsContext() {
025 EC2Context ec2 = getEC2Context();
026 S3Context s3 = getS3Context();
027 SesContext ses = getSesContext();
028 return new AwsContext(ec2, s3, ses);
029 }
030
031 protected EC2Context getEC2Context() {
032 String ami = env.getString("ec2.ami");
033 String securityGroup = env.getString("ec2.securityGroup");
034 String type = env.getString("ec2.type");
035 return new EC2Context(ami, securityGroup, type);
036 }
037
038 protected S3Context getS3Context() {
039 String accessKey = env.getString("s3.accessKey");
040 String secretKey = env.getString("s3.secretKey");
041 return new S3Context(accessKey, secretKey);
042 }
043
044 protected SesContext getSesContext() {
045 String username = env.getString("ses.username");
046 String password = env.getString("ses.password");
047 SesCredentials credentials = new SesCredentials(username, password);
048 String host = env.getString("ses.host");
049
050 // These next four need to come from the environment (even though the pojo has default values for them)
051 // This is because the environment properties used to setup the pojo are also used to filter config files
052 boolean debug = env.getBoolean("ses.debug");
053 boolean sslEnable = env.getBoolean("ses.ssl.enable");
054 boolean auth = env.getBoolean("ses.auth");
055 int port = env.getInteger("ses.port");
056
057 // Build a context object from the configuration
058 return new SesContext.Builder(host, credentials).debug(debug).sslEnable(sslEnable).auth(auth).port(port).build();
059 }
060
061 }