|
1 | 1 | package org.sagebionetworks.template.global; |
2 | 2 |
|
3 | | -import com.google.inject.Inject; |
4 | | -import org.apache.logging.log4j.Logger; |
| 3 | +import static org.sagebionetworks.template.Constants.DELETION_POLICY; |
| 4 | +import static org.sagebionetworks.template.Constants.GLOBAL_CFSTACK_OUTPUT_KEY_SES_BOUNCE_TOPIC; |
| 5 | +import static org.sagebionetworks.template.Constants.GLOBAL_CFSTACK_OUTPUT_KEY_SES_COMPLAINT_TOPIC; |
| 6 | +import static org.sagebionetworks.template.Constants.GLOBAL_RESOURCES_STACK_NAME_FORMAT; |
| 7 | +import static org.sagebionetworks.template.Constants.IDENTITY_ARN; |
| 8 | +import static org.sagebionetworks.template.Constants.JSON_INDENT; |
| 9 | +import static org.sagebionetworks.template.Constants.OPS_VPC_EXPORT_PREFIX; |
| 10 | +import static org.sagebionetworks.template.Constants.PROPERTY_KEY_STACK; |
| 11 | +import static org.sagebionetworks.template.Constants.SES_SYNAPSE_DOMAIN; |
| 12 | +import static org.sagebionetworks.template.Constants.STACK; |
| 13 | +import static org.sagebionetworks.template.Constants.TEMPLATE_GLOBAL_RESOURCES; |
| 14 | +import static org.sagebionetworks.template.Constants.VPC_EXPORT_PREFIX; |
| 15 | + |
| 16 | +import java.io.StringWriter; |
| 17 | + |
5 | 18 | import org.apache.velocity.Template; |
6 | 19 | import org.apache.velocity.VelocityContext; |
7 | 20 | import org.apache.velocity.app.VelocityEngine; |
8 | 21 | import org.json.JSONObject; |
9 | 22 | import org.sagebionetworks.template.CloudFormationClientWrapper; |
10 | 23 | import org.sagebionetworks.template.Constants; |
11 | 24 | import org.sagebionetworks.template.CreateOrUpdateStackRequest; |
12 | | -import org.sagebionetworks.template.LoggerFactory; |
13 | 25 | import org.sagebionetworks.template.SesClientWrapper; |
14 | 26 | import org.sagebionetworks.template.StackTagsProvider; |
15 | 27 | import org.sagebionetworks.template.config.Configuration; |
16 | 28 | import org.sagebionetworks.template.repo.DeletionPolicy; |
17 | | -import software.amazon.awssdk.services.cloudformation.model.Capability; |
18 | 29 |
|
19 | | -import java.io.StringWriter; |
| 30 | +import com.google.inject.Inject; |
20 | 31 |
|
21 | | -import static org.sagebionetworks.template.Constants.DELETION_POLICY; |
22 | | -import static org.sagebionetworks.template.Constants.GLOBAL_RESOURCES_STACK_NAME_FORMAT; |
23 | | -import static org.sagebionetworks.template.Constants.JSON_INDENT; |
24 | | -import static org.sagebionetworks.template.Constants.PROPERTY_KEY_STACK; |
25 | | -import static org.sagebionetworks.template.Constants.SES_SYNAPSE_DOMAIN; |
26 | | -import static org.sagebionetworks.template.Constants.STACK; |
27 | | -import static org.sagebionetworks.template.Constants.TEMPLATE_GLOBAL_RESOURCES; |
28 | | -import static org.sagebionetworks.template.Constants.CAPABILITY_NAMED_IAM; |
29 | | -import static org.sagebionetworks.template.Constants.GLOBAL_CFSTACK_OUTPUT_KEY_SES_BOUNCE_TOPIC; |
30 | | -import static org.sagebionetworks.template.Constants.GLOBAL_CFSTACK_OUTPUT_KEY_SES_COMPLAINT_TOPIC; |
| 32 | +import software.amazon.awssdk.services.cloudformation.model.Capability; |
| 33 | +import software.amazon.awssdk.services.sts.StsClient; |
31 | 34 |
|
32 | 35 | public class GlobalResourcesBuilderImpl implements GlobalResourcesBuilder { |
33 | 36 |
|
34 | | - CloudFormationClientWrapper cloudFormationClientWrapper; |
35 | | - VelocityEngine velocityEngine; |
36 | | - Configuration config; |
37 | | - Logger logger; |
38 | | - StackTagsProvider stackTagsProvider; |
39 | | - SesClientWrapper sesClientWrapper; |
| 37 | + private final CloudFormationClientWrapper cloudFormationClientWrapper; |
| 38 | + private final VelocityEngine velocityEngine; |
| 39 | + private final Configuration config; |
| 40 | + private final StackTagsProvider stackTagsProvider; |
| 41 | + private final SesClientWrapper sesClientWrapper; |
| 42 | + private final StsClient stsClient; |
40 | 43 |
|
41 | 44 | @Inject |
42 | 45 | public GlobalResourcesBuilderImpl(CloudFormationClientWrapper cloudFormationClientWrapper, |
43 | 46 | VelocityEngine velocityEngine, |
44 | 47 | Configuration config, |
45 | | - LoggerFactory loggerFactory, |
46 | 48 | StackTagsProvider stackTagsProvider, |
47 | | - SesClientWrapper sesClientWrapper) { |
| 49 | + SesClientWrapper sesClientWrapper, |
| 50 | + StsClient stsClient) { |
48 | 51 | this.cloudFormationClientWrapper = cloudFormationClientWrapper; |
49 | 52 | this.velocityEngine = velocityEngine; |
50 | 53 | this.config = config; |
51 | | - this.logger = loggerFactory.getLogger(GlobalResourcesBuilderImpl.class); |
52 | 54 | this.stackTagsProvider = stackTagsProvider; |
53 | 55 | this.sesClientWrapper = sesClientWrapper; |
| 56 | + this.stsClient = stsClient; |
54 | 57 | } |
55 | 58 |
|
56 | 59 | @Override |
@@ -83,15 +86,23 @@ public String createStackName() { |
83 | 86 |
|
84 | 87 | public VelocityContext createContext() { |
85 | 88 | VelocityContext context = new VelocityContext(); |
86 | | - context.put(STACK, config.getProperty(PROPERTY_KEY_STACK)); |
87 | | - context.put(DELETION_POLICY, |
88 | | - Constants.isProd(config.getProperty(PROPERTY_KEY_STACK)) ? DeletionPolicy.Retain.name() : DeletionPolicy.Delete.name()); |
| 89 | + |
| 90 | + String stack = config.getProperty(PROPERTY_KEY_STACK); |
| 91 | + |
| 92 | + context.put(STACK, stack); |
| 93 | + context.put(DELETION_POLICY, Constants.isProd(config.getProperty(PROPERTY_KEY_STACK)) ? DeletionPolicy.Retain.name() : DeletionPolicy.Delete.name()); |
| 94 | + |
| 95 | + context.put(VPC_EXPORT_PREFIX, Constants.createVpcExportPrefix(stack)); |
| 96 | + context.put(OPS_VPC_EXPORT_PREFIX, "us-east-1-vpc"); |
| 97 | + context.put(IDENTITY_ARN, stsClient.getCallerIdentity().arn()); |
| 98 | + |
89 | 99 | return context; |
90 | 100 | } |
91 | 101 |
|
92 | 102 | public void setupSesTopics(String stackName) { |
93 | 103 | String sesComplaintSnsTopic = this.cloudFormationClientWrapper.getOutput(stackName, GLOBAL_CFSTACK_OUTPUT_KEY_SES_COMPLAINT_TOPIC); |
94 | 104 | String sesBounceSnsTopic = this.cloudFormationClientWrapper.getOutput(stackName, GLOBAL_CFSTACK_OUTPUT_KEY_SES_BOUNCE_TOPIC); |
| 105 | + |
95 | 106 | sesClientWrapper.setComplaintNotificationTopic(SES_SYNAPSE_DOMAIN, sesComplaintSnsTopic); |
96 | 107 | sesClientWrapper.setBounceNotificationTopic(SES_SYNAPSE_DOMAIN, sesBounceSnsTopic); |
97 | 108 | } |
|
0 commit comments