-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathConfig.py
173 lines (145 loc) · 5.4 KB
/
Config.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
import traceback
import os
import boto3
import constants as _C
class Config:
AWS_SDK = {
'signature_version': 'v4'
}
ADVISOR = {
'TITLE': 'Service Screener',
'VERSION': '2.3.0',
'LAST_UPDATE': '02-Dec-2024'
}
ADMINLTE = {
'VERSION': '3.1.0',
'DATERANGE': '2014-2021',
'URL': 'https://adminlte.io',
'TITLE': 'AdminLTE.io'
}
GLOBAL_SERVICES = [
'iam',
'cloudfront'
]
KEYWORD_SERVICES = [
'lambda'
]
CURRENT_REGION = 'us-east-1'
######
## This is for capturing
# TEXT = plain text
# DICT = self.0[1]
# ATTR = self.0
# SKIP = literally skip, not showing
SERVICES_IDENTIFIER_MAPPING = {
'apigatewaycommon': ['DICT', 'api', 'Name'],
'apigatewayrest': ['DICT', 'api', 'name'],
'cloudfrontdist': ['ATTR', 'dist'],
'cloudtrailaccount': ['TEXT', 'General'],
'cloudtrailcommon': ['DICT', 'trail', 'TrailARN'],
'cloudwatchtrails': ['ATTR', 'logname'],
'cloudwatchcommon': ['DICT', 'log', 'logGroupName'],
'dynamodbgeneric': ['TEXT', 'General'],
'dynamodbcommon': ['ATTR', 'tablename'],
'ec2autoscaling': ['DICT', 'asg', 'AutoScalingGroupName'],
'ec2compopt': ['TEXT', 'ComputeOptimizer'],
'ec2costexplorerrecs': ['TEXT', 'ReservedInstance&SavingPlans'],
'ec2ebssnapshot': ['TEXT', 'AllEC2Snapshots'],
'ec2ebsvolume': ['DICT', 'ebsVolumeData', 'VolumeId'],
'ec2eip': ['DICT', 'eip', 'PublicIp'],
'ec2elbclassic': ['DICT', 'elb', 'LoadBalancerName'],
'ec2elbcommon': ['DICT', 'elb', 'LoadBalancerArn'],
'ec2instance': ['DICT', 'ec2InstanceData', 'InstanceId'],
'ec2secgroup': ['DICT', 'secGroup', 'GroupId'],
'ec2vpc': ['DICT', 'vpc', 'VpcId'],
'ec2nacl': ['DICT', 'nacl', 'NetworkAclId'],
'efsdriver': ['DICT', 'efs', 'FileSystemId'],
'ekscommon': ['ATTR', 'cluster'],
'elasticachememcached': ['DICT', 'cluster', 'ARN'],
'elasticacheredis': ['DICT', 'cluster', 'ARN'],
'elasticachereplicationgroup': ['DICT', 'group', 'ReplicationGroupId'],
'guarddutydriver': ['ATTR', 'detector_id'],
'iamaccount': ['TEXT', 'General'],
'iamgroup': ['DICT', 'group', 'GroupName'],
'iamrole': ['DICT', 'role', 'RoleName'],
'iamuser': ['DICT', 'user', 'user'],
'kmscommon': ['DICT', 'kms', 'Arn'],
'lambdacommon': ['ATTR', 'function_name', ],
'opensearchcommon': ['ATTR', 'domain'],
'rdsmariadb': ['DICT', 'db', ['DBInstanceIdentifier']],
'rdsmysql': ['DICT', 'db', ['DBInstanceIdentifier']],
'rdsmssql': ['DICT', 'db', ['DBInstanceIdentifier']],
'rdspostgres': ['DICT', 'db', ['DBInstanceIdentifier']],
'rdsmysqlaurora': ['DICT', 'db', ['DBClusterIdentifier', 'DBInstanceIdentifier']],
'rdspostgresaurora': ['DICT', 'db', ['DBClusterIdentifier', 'DBInstanceIdentifier']],
'rdssecuritygroup': ['ATTR', 'sg'],
'rdssecretsmanager': ['DICT', 'secret', 'Name'],
'rdssecretsvsdb': ['SKIP'],
'redshiftcluster': ['DICT', 'cluster', 'ClusterIdentifier'],
's3bucket': ['ATTR', 'bucket'],
's3control': ['TEXT', 'S3AccountLevel'],
's3macie': ['TEXT', 'Macie']
}
@staticmethod
def init():
global cache
cache = {}
@staticmethod
def setAccountInfo(__AWS_CONFIG):
print(" -- Acquiring identify info...")
ssBoto = Config.get('ssBoto', None)
stsClient = ssBoto.client('sts')
resp = stsClient.get_caller_identity()
stsInfo = {
'UserId': resp.get('UserId'),
'Account': resp.get('Account'),
'Arn': resp.get('Arn')
}
Config.set('stsInfo', stsInfo)
acctId = stsInfo['Account']
adir = 'adminlte/aws/' + acctId
Config.set('HTML_ACCOUNT_FOLDER_FULLPATH', _C.ROOT_DIR + '/' + adir)
Config.set('HTML_ACCOUNT_FOLDER_PATH', adir)
@staticmethod
def set(key, val):
cache[key] = val
@staticmethod
def get(key, defaultValue = False):
## <TODO>, fix the DEBUG variable
DEBUG = False
if key in cache:
return cache[key]
if defaultValue == False:
if DEBUG:
traceback.print_exc()
return defaultValue
@staticmethod
def retrieveAllCache():
return cache
## do checking for prefix=cloud, if found, use first 8character instead
## other than that, first 3 prefix should be unique
@staticmethod
def getDriversClassPrefix(driver):
name = Config.extractDriversClassPrefix(driver)
return 'regionInfo::' + name
@staticmethod
def extractDriversClassPrefix(driver):
## handling for S3
if driver[:2].lower() == 's3':
return 's3'
if driver[:7].lower() == 'elastic':
classPrefix = driver[:10]
else:
classPrefix = driver[:3]
if len(driver) > 3 and driver[:5] == 'cloud':
classPrefix = driver[:8]
return classPrefix
try:
if configHasInit:
pass
except NameError:
dashboard = {}
Config.init()
configHasInit = True
if __name__ == "__main__":
print(os.getcwd())