-
Notifications
You must be signed in to change notification settings - Fork 4
/
resources.py
174 lines (133 loc) · 5.28 KB
/
resources.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
import utils, get_filepath
from aws_resource import Resource
TEMPLATE_DIR_PATH = get_filepath.ROOT_DIR + "/templates/"
ALB_TEMPLATE_PATH = TEMPLATE_DIR_PATH + "ALB.json"
CLB_TEMPLATE_PATH = TEMPLATE_DIR_PATH + "CLB.json"
CF_TEMPLATE_PATH = TEMPLATE_DIR_PATH + "CloudFront.json"
EC2_TEMPLATE_PATH = TEMPLATE_DIR_PATH + "EC2.json"
ELASCACHE_TEMPLATE_PATH = TEMPLATE_DIR_PATH + "ElastiCache.json"
NLB_TEMPLATE_PATH = TEMPLATE_DIR_PATH + "NLB.json"
RDS_TEMPLATE_PATH = TEMPLATE_DIR_PATH + "RDS.json"
AURORA_CLUSTER_TEMPLATE_PATH = TEMPLATE_DIR_PATH + "AuroraCluster.json"
AURORA_INSTANCE_TEMPLATE_PATH = TEMPLATE_DIR_PATH + "AuroraInstance.json"
NAT_TEMPLATE_PATH = TEMPLATE_DIR_PATH + "NAT.json"
MQ_TEMPLATE_PATH = TEMPLATE_DIR_PATH + "MQ.json"
MSK_TEMPLATE_PATH = TEMPLATE_DIR_PATH + "MSK.json"
S3_TEMPLATE_PATH = TEMPLATE_DIR_PATH + "S3.json"
class Alb(Resource):
def __init__(self, input_file: dict):
super().__init__(input_file)
self.is_elbv2 = True
def _read_template(self):
self.template = utils.json_to_dict(ALB_TEMPLATE_PATH)
def write_template(self) -> dict:
self._read_template()
self._data_processing(
"ALB", "LoadBalancer"
)
return self.template
class Clb(Resource):
def _read_template(self):
self.template = utils.json_to_dict(CLB_TEMPLATE_PATH)
def write_template(self) -> dict:
self._read_template()
self._data_processing("CLB", "LoadBalancer")
return self.template
class Cloudfront(Resource):
def __init__(self, input_file: dict):
super().__init__(input_file)
self.is_cf = True
def _read_template(self):
self.template = utils.json_to_dict(CF_TEMPLATE_PATH)
def write_template(self) -> dict:
self._read_template()
self._data_processing("CloudFront", "DistributionId")
return self.template
class Ec2(Resource):
def _read_template(self):
self.template = utils.json_to_dict(EC2_TEMPLATE_PATH)
def write_template(self) -> dict:
self._read_template()
self._data_processing("EC2", "InstanceId")
return self.template
class ElastiCache(Resource):
def __init__(self, input_file: dict):
super().__init__(input_file)
self.is_elastic_cache = True
def _read_template(self):
self.template = utils.json_to_dict(ELASCACHE_TEMPLATE_PATH)
def write_template(self) -> dict:
self._read_template()
self._data_processing("ElastiCache", "CacheClusterId")
return self.template
class Nlb(Resource):
def __init__(self, input_file: dict):
super().__init__(input_file)
self.is_elbv2 = True
def _read_template(self):
self.template = utils.json_to_dict(NLB_TEMPLATE_PATH)
def write_template(self) -> dict:
self._read_template()
self._data_processing(
"NLB", "LoadBalancer"
)
return self.template
class Rds(Resource):
def _read_template(self):
self.template = utils.json_to_dict(RDS_TEMPLATE_PATH)
def write_template(self) -> dict:
self._read_template()
self._data_processing("RDS", "DBInstanceIdentifier")
return self.template
class AuroraCluster(Resource):
def _read_template(self):
self.template = utils.json_to_dict(AURORA_CLUSTER_TEMPLATE_PATH)
def write_template(self) -> dict:
self._read_template()
self._data_processing("AuroraCluster", "DBClusterIdentifier")
return self.template
class AuroraInstance(Resource):
def _read_template(self):
self.template = utils.json_to_dict(AURORA_INSTANCE_TEMPLATE_PATH)
def write_template(self) -> dict:
self._read_template()
self._data_processing("AuroraInstance", "DBInstanceIdentifier")
return self.template
class Nat(Resource):
def _read_template(self):
self.template = utils.json_to_dict(NAT_TEMPLATE_PATH)
def write_template(self) -> dict:
self._read_template()
self._data_processing("NAT", "NatGatewayId")
return self.template
class Mq(Resource):
def _read_template(self):
self.template = utils.json_to_dict(MQ_TEMPLATE_PATH)
def write_template(self) -> dict:
self._read_template()
self._data_processing("AmazonMQ", "Broker")
return self.template
class Msk(Resource):
def _read_template(self):
self.template = utils.json_to_dict(MSK_TEMPLATE_PATH)
def write_template(self) -> dict:
self._read_template()
self._data_processing("AmazonMSK", "Cluster Name")
return self.template
class S3(Resource):
def __init__(self, input_file: dict):
super().__init__(input_file)
self.S3_Y_AXIS = 1600 # https://quip-amazon.com/OtgHAamF64Ab/Event-Monitoring-Generator-for-IEM#CcI9CABLhc5
self.is_s3 = True
def _read_template(self):
self.template = utils.json_to_dict(S3_TEMPLATE_PATH)
def _s3_template_preprocessing(self) -> None:
for widgets in self.template:
widgets['y'] += self.S3_Y_AXIS
def write_template(self) -> dict:
self._read_template()
self._s3_template_preprocessing()
self._data_processing("S3", "BucketName")
return self.template