Skip to content

Commit

Permalink
feat: make more settings optional
Browse files Browse the repository at this point in the history
  • Loading branch information
GabDug committed Jan 2, 2024
1 parent a45746c commit 7e2e9b5
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 23 deletions.
4 changes: 4 additions & 0 deletions src/firefighter/confluence/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ def update_oncall_page(self, users: dict[str, User]) -> bool:
Returns:
bool: has the page been updated?
"""
if not settings.CONFLUENCE_ON_CALL_PAGE_ID:
logger.info("No Confluence OnCall page ID, skipping.")
return False

content = (self.client.get_page(settings.CONFLUENCE_ON_CALL_PAGE_ID)).json()

page_version = get_in(content, "version.number")
Expand Down
13 changes: 12 additions & 1 deletion src/firefighter/firefighter/settings/components/confluence.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,26 @@
CONFLUENCE_RUNBOOKS_FOLDER_ID: int = config(
"CONFLUENCE_RUNBOOKS_FOLDER_ID", cast=int
)
"The Confluence page ID where runbooks are stored."

CONFLUENCE_POSTMORTEM_TEMPLATE_PAGE_ID: int = config(
"CONFLUENCE_POSTMORTEM_TEMPLATE_PAGE_ID", cast=int
)
"The Confluence page ID of the template to use for postmortems."

CONFLUENCE_POSTMORTEM_FOLDER_ID: int = config(
"CONFLUENCE_POSTMORTEM_FOLDER_ID", cast=int
)
"The Confluence page ID where to create and nest postmortems."

CONFLUENCE_POSTMORTEM_SPACE: str = config("CONFLUENCE_POSTMORTEM_SPACE")
"XXX To rename CONFLUENCE_DEFAULT_SPACE. The Confluence space where to create pages by default, mainly for postmortems."

CONFLUENCE_ON_CALL_PAGE_ID: int | None = config(
"CONFLUENCE_ON_CALL_PAGE_ID", cast=int, default=None
)
"The Confluence page ID where to export the current on-call schedule. If not set, export tasks will be skipped."

CONFLUENCE_ON_CALL_PAGE_ID: int = config("CONFLUENCE_ON_CALL_PAGE_ID", cast=int)
CONFLUENCE_USERNAME: str = config("CONFLUENCE_USERNAME")
"The Confluence username to use."
CONFLUENCE_API_KEY: str = config("CONFLUENCE_API_KEY")
Expand Down
2 changes: 1 addition & 1 deletion src/firefighter/firefighter/settings/components/raid.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from firefighter.firefighter.settings.settings_utils import config

ENABLE_RAID: bool = config("ENABLE_RAID", cast=bool, default=False)
"Enable the Raid app. Jira must be enabled and configured as well."
"Enable the Raid app. Jira app must be enabled and configured as well."

if ENABLE_RAID:
INSTALLED_APPS += ("firefighter.raid",)
Expand Down
32 changes: 21 additions & 11 deletions src/firefighter/firefighter/settings/components/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,35 @@
"""The Slack bot token to use."""
SLACK_SIGNING_SECRET: str = config("SLACK_SIGNING_SECRET")
"""The Slack signing secret to use."""
SLACK_SEVERITY_HELP_GUIDE_URL: str = config("SLACK_SEVERITY_HELP_GUIDE_URL")
SLACK_INCIDENT_HELP_GUIDE_URL: str = config("SLACK_INCIDENT_HELP_GUIDE_URL")
SLACK_CURRENT_ONCALL_URL: str = config("SLACK_CURRENT_ONCALL_URL")
SLACK_POSTMORTEM_HELP_URL: str = config("SLACK_POSTMORTEM_HELP_URL")
SLACK_EMERGENCY_COMMUNICATION_GUIDE_URL: str = config(
"SLACK_EMERGENCY_COMMUNICATION_GUIDE_URL"
)
SLACK_EMERGENCY_USERGROUP_ID: str = config("SLACK_EMERGENCY_USERGROUP_ID")
SLACK_INCIDENT_COMMAND: str = config("SLACK_INCIDENT_COMMAND")

SLACK_INCIDENT_COMMAND: str = config("SLACK_INCIDENT_COMMAND", default="/incident")
"""The Slack slash command to use to create and manage incidents."""
SLACK_INCIDENT_COMMAND_ALIASES: list[str] = config(
"SLACK_INCIDENT_COMMAND_ALIASES", cast=Csv(), default=""
)
"Comma-separated list of aliases for the incident command."

SLACK_CURRENT_ONCALL_URL: str = config("SLACK_CURRENT_ONCALL_URL")
SLACK_POSTMORTEM_HELP_URL: str = config("SLACK_POSTMORTEM_HELP_URL")

SLACK_INCIDENT_HELP_GUIDE_URL: str | None = config(
"SLACK_INCIDENT_HELP_GUIDE_URL", default=None
)
"URL to add in the Slack help message (/incident help). Useful to point to your own documentation."
SLACK_EMERGENCY_COMMUNICATION_GUIDE_URL: str | None = config(
"SLACK_EMERGENCY_COMMUNICATION_GUIDE_URL", default=None
)
"""URL to add in the Slack emergency message. Useful to point to your own documentation."""
SLACK_EMERGENCY_USERGROUP_ID: str | None = config(
"SLACK_EMERGENCY_USERGROUP_ID", default=None
)
"""The Slack usergroup ID to use for emergency notifications. If not set, no group will be mentionned in the message."""

SLACK_APP_EMOJI: str = config("SLACK_APP_EMOJI", default=":fire_extinguisher:")
"""Emoji to represent the app in Slack surfaces. Can be an actual emoji, or a string for a custom emoji present in your Workspace, like ":incident_logo:"."""

_default_skip_check = "generate_manifest" in sys.argv
_is_default_skip_check_cmd = "generate_manifest" in sys.argv
FF_SLACK_SKIP_CHECKS: bool = config(
"FF_SLACK_SKIP_CHECKS", cast=bool, default=_default_skip_check
"FF_SLACK_SKIP_CHECKS", cast=bool, default=_is_default_skip_check_cmd
)
"""Skip Slack checks. Only use for testing or demo."""
18 changes: 14 additions & 4 deletions src/firefighter/slack/messages/slack_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@

CURRENT_ONCALL_URL: str = settings.SLACK_CURRENT_ONCALL_URL
POSTMORTEM_HELP_URL: str = settings.SLACK_POSTMORTEM_HELP_URL
EMERGENCY_COMMUNICATION_GUIDE_URL: str = (
EMERGENCY_COMMUNICATION_GUIDE_URL: str | None = (
settings.SLACK_EMERGENCY_COMMUNICATION_GUIDE_URL
)
SLACK_EMERGENCY_USERGROUP_ID: str = settings.SLACK_EMERGENCY_USERGROUP_ID
SLACK_EMERGENCY_USERGROUP_ID: str | None = settings.SLACK_EMERGENCY_USERGROUP_ID
APP_DISPLAY_NAME: str = settings.APP_DISPLAY_NAME
SLACK_APP_EMOJI: str = settings.SLACK_APP_EMOJI

Expand Down Expand Up @@ -253,7 +253,7 @@ class SlackMessageIncidentDeclaredAnnouncementGeneral(SlackMessageSurface):
incident: Incident

def __init__(self, incident: Incident) -> None:
"""The message to post in general incident channel (#tech-incidents) when an incident is opened.
"""The message to post in general incident channel (tag=tech_incidents) when an incident is opened.
Args:
incident (Incident): Your incident
Expand Down Expand Up @@ -631,6 +631,16 @@ def __init__(self, incident: Incident):
super().__init__()

def get_blocks(self) -> list[Block]:
mention_emergency_process = (
f"\n\n:arrow_right: <{EMERGENCY_COMMUNICATION_GUIDE_URL}|COM PROCESS> "
if SLACK_EMERGENCY_USERGROUP_ID
else ""
)
mention_usergroup = (
f":arrow_left:\n\n :loudspeaker: <!subteam^{SLACK_EMERGENCY_USERGROUP_ID}> *must* be informed."
if SLACK_EMERGENCY_USERGROUP_ID
else ""
)
return [
HeaderBlock(
text=PlainTextObject(
Expand All @@ -639,7 +649,7 @@ def get_blocks(self) -> list[Block]:
),
SectionBlock(
text=MarkdownTextObject(
text=f"As a {self.incident.priority.name} incident, it may drastically impact our customers for hours. If so, we created a emergency procedure to communicate with them. \n\n:arrow_right: <{EMERGENCY_COMMUNICATION_GUIDE_URL}|COM PROCESS> :arrow_left:\n\n :loudspeaker: <!subteam^{SLACK_EMERGENCY_USERGROUP_ID}> *must* be informed."
text=f"As a {self.incident.priority.name} incident, it may drastically impact our customers for hours. If so, we created a emergency procedure to communicate with them.{mention_emergency_process}{mention_usergroup}"
)
),
]
Expand Down
6 changes: 2 additions & 4 deletions src/firefighter/slack/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,15 @@ def upsert_by_email(
try:
user = User.objects.get(email=email)
except User.DoesNotExist:
logger.info("No user in DB. Fetching it from firefighter.slack...")
logger.info("No user in DB. Fetching it from Slack...")
else:
return user

# If not in DB, fetch the user's info from firefighter.slack...
try:
user_info = client.users_lookupByEmail(email=email)
if not user_info.get("ok"):
logger.error(
f"Could not fetch user from firefighter.slack. User: email={email}"
)
logger.error(f"Could not fetch user from Slack. User: email={email}")
return None
except slack_sdk.errors.SlackApiError:
logger.exception(f"Could not find Slack user with email: {email}")
Expand Down
8 changes: 6 additions & 2 deletions src/firefighter/slack/slack_templating.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
logger = logging.getLogger(__name__)

COMMAND: str = settings.SLACK_INCIDENT_COMMAND
INCIDENT_DOC_URL: str = settings.SLACK_INCIDENT_HELP_GUIDE_URL
INCIDENT_DOC_URL: str | None = settings.SLACK_INCIDENT_HELP_GUIDE_URL


def shorten_long(text: str, width: int, **kwargs: Any) -> str:
Expand Down Expand Up @@ -102,8 +102,12 @@ def slack_block_help_commands() -> SectionBlock:

@cache
def slack_block_help_description() -> SectionBlock:
if INCIDENT_DOC_URL is None:
return SectionBlock(
text=f"{settings.APP_DISPLAY_NAME} is our tool for incident management."
)
return SectionBlock(
text=f"{settings.APP_DISPLAY_NAME} is our tool for the incident management, more about incidents is visible <{INCIDENT_DOC_URL}|here>."
text=f"{settings.APP_DISPLAY_NAME} is our tool for incident management, more about incidents is visible <{INCIDENT_DOC_URL}|here>."
)


Expand Down

0 comments on commit 7e2e9b5

Please sign in to comment.