-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontroller.py
44 lines (36 loc) · 1.68 KB
/
controller.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
__author__ = "Alon Shrestha"
from config import resourceConfig
from core import startStopInstances, patchExecution, patchExecutionStatusReport, miniPatchComplianceReport
def mainHandler(event, context):
# Collect parameters
receivedAction = event["stringParameters"]["action"]
environment = event["stringParameters"]["environment"]
receivedAccounts = event["stringParameters"]["account"]
accountList = []
for getAccount in resourceConfig.resources:
accountList.append(getAccount)
# Check if provided accounts exist in config.
for account in receivedAccounts:
if account not in accountList:
raise ValueError(f"Account: {account} not found in config")
print(f"Account: {receivedAccounts} found on config. Moving for Action: {receivedAction}")
# Call Action Method
if receivedAction == "StartInst": # Start stopped instance before patching.
startStopInstances.runStartStop(receivedAction, receivedAccounts, environment)
elif receivedAction == "RunPatch": # Run patch.
patchExecution.runPatchManager(receivedAccounts, environment)
elif receivedAction == "GenerateReport": # Generate after patch report.
patchExecutionStatusReport.generateCommandStatus(environment)
miniPatchComplianceReport.generateMiniPatchComplianceReport(receivedAccounts, environment)
elif receivedAction == "StopInst": # Stop started instance before patching.
startStopInstances.runStartStop(receivedAction, receivedAccounts, environment)
mainHandler(
{
"stringParameters": {
"action": "StartInst",
"environment": "DEV",
"account": ["AccountA"]
}
},
""
)