This repository has been archived by the owner on Sep 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 83
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
Showing
102 changed files
with
4,317 additions
and
1,803 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
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
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
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
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
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,32 +1,60 @@ | ||
"""Utilities for retrieving channel credentials from config-setting.""" | ||
from typing import Tuple | ||
|
||
from chaos_genius.controllers.config_controller import get_config_object | ||
|
||
|
||
def get_creds(name): | ||
return HELPER_FUNC_DICT[name](name) | ||
# TODO: make a new type here to better represent the return value | ||
# ref: https://github.com/chaos-genius/chaos_genius/pull/836#discussion_r838085548 | ||
def get_email_creds() -> Tuple[str, int, str, str, str]: | ||
"""Retrieves email channel configuration. | ||
Returns: | ||
A tuple of (host, port, username, password, sender_email) | ||
Raises: | ||
Exception: if email channel was not configured. | ||
""" | ||
# TODO: remove hardcoding of "email" - use a constant or a function | ||
# ref: https://github.com/chaos-genius/chaos_genius/pull/836#discussion_r838110482 | ||
config_obj = get_config_object("email") | ||
if not config_obj: | ||
raise Exception("Email alert channel was not configured") | ||
|
||
email_config = config_obj.as_dict.get("config_setting") | ||
|
||
def get_email_creds(name): | ||
config_obj = get_config_object(name) | ||
if config_obj is None: | ||
return "", "", "", "", "" | ||
if not email_config: | ||
raise Exception("Email alert channel was not configured") | ||
|
||
configs = config_obj.as_dict.get("config_setting", {}) | ||
return ( | ||
configs.get("server", ""), | ||
configs.get("port", ""), | ||
configs.get("username", ""), | ||
configs.get("password", ""), | ||
configs.get("sender_email", ""), | ||
email_config.get("server", ""), | ||
email_config.get("port", 0), | ||
email_config.get("username", ""), | ||
email_config.get("password", ""), | ||
email_config.get("sender_email", ""), | ||
) | ||
|
||
|
||
def get_slack_creds(name): | ||
config_obj = get_config_object(name) | ||
if config_obj is None: | ||
return "" | ||
def get_slack_creds() -> str: | ||
"""Retrieves slack channel configuration. | ||
Returns: | ||
The slack webhook URL | ||
Raises: | ||
Exception: if slack channel was not configured. | ||
""" | ||
config_obj = get_config_object("slack") | ||
if not config_obj: | ||
raise Exception("Slack alert channel was not configured") | ||
|
||
configs = config_obj.as_dict.get("config_setting", {}) | ||
return configs.get("webhook_url", "") | ||
configs = config_obj.as_dict.get("config_setting") | ||
if not configs: | ||
raise Exception("Slack alert channel was not configured") | ||
|
||
if "webhook_url" not in configs: | ||
raise Exception( | ||
"Slack alert channel configuration is invalid. webhook_url was not found." | ||
) | ||
|
||
HELPER_FUNC_DICT = {"email": get_email_creds, "slack": get_slack_creds} | ||
return configs["webhook_url"] |
Oops, something went wrong.