-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
66f7fc2
commit 727176d
Showing
1 changed file
with
29 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,36 @@ | ||
from lib.impact.helpers import check_key, get_config_key | ||
|
||
class Status: | ||
def __init__(self, logger): | ||
self.logger = logger | ||
|
||
def get_status(self, resource_arn, resource_values): | ||
self.logger.info("Calculating status for resource: %s", resource_arn) | ||
|
||
config = resource_values.get("config", {}) | ||
if config: | ||
if config.get("status"): | ||
if config.get("status") == "running": | ||
return {"running": config.get("status")} | ||
else: | ||
return {"not-running": config.get("status")} | ||
if config.get("attached") is True: | ||
return {"attached": config.get("attached")} | ||
if config.get("attached") is False: | ||
return {"not-attached": config.get("attached")} | ||
|
||
return {"unknown": {}} | ||
status = get_config_key(resource_values, "status") | ||
attached = get_config_key(resource_values, "attached") | ||
|
||
status_checks = { | ||
"status": status, | ||
"attached": attached, | ||
} | ||
|
||
# If no config and no associations, return unknown | ||
if not check_key(resource_values, "config") and not check_key( | ||
resource_values, "associations" | ||
): | ||
return {"unknown": status_checks} | ||
|
||
if attached is not None: | ||
if attached is True: | ||
return {"attached": status_checks} | ||
if attached is False: | ||
return {"not-attached": status_checks} | ||
|
||
if status is not None: | ||
if status == "running": | ||
return {"running": status_checks} | ||
if status != "running": | ||
return {"not-running": status_checks} | ||
|
||
return {"unknown": status_checks} |