Skip to content

Commit

Permalink
Use internally env.getenv to ensure env.setup is called on the first hit
Browse files Browse the repository at this point in the history
  • Loading branch information
pablomm committed Aug 17, 2024
1 parent 60938c6 commit 8021988
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
5 changes: 3 additions & 2 deletions dmf/alerts/alerts.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from typing import Optional, TYPE_CHECKING, Tuple, Union
import os


from ..utils.typing import Literal
from ..env import env

if TYPE_CHECKING:
from .backend import AlertBackend
Expand Down Expand Up @@ -155,7 +156,7 @@ def resolve_credentials(
:param alert_token: Optional; Slack token to override the environment variable.
:return: A tuple containing the alert_token and the backend type ('slack').
"""
alert_token = alert_token or os.getenv(ALERT_TOKEN)
alert_token = alert_token or env.getenv(ALERT_TOKEN)

if not alert_token:
raise ValueError(
Expand Down
5 changes: 3 additions & 2 deletions dmf/alerts/slack_backend.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
import os

from datetime import datetime, timedelta
from pathlib import Path
from typing import Optional, Union
Expand All @@ -14,6 +14,7 @@
)

from .backend import AlertBackend, AlertException
from ..env import env

__all__ = ["SlackBackend"]

Expand Down Expand Up @@ -74,7 +75,7 @@ def __init__(

super().__init__(fail_silently=fail_silently)
self.client = WebClient(token=token)
self.channel = channel or os.getenv(DEFAULT_CHANNEL_ENV)
self.channel = channel or env.getenv(DEFAULT_CHANNEL_ENV)

def send_message(
self,
Expand Down
4 changes: 2 additions & 2 deletions dmf/alerts/telegram_backend.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import logging
import os
from datetime import datetime
from pathlib import Path
from typing import Optional, Union

from ..utils.typing import Literal
from ..env import env

try:
import requests
Expand Down Expand Up @@ -83,7 +83,7 @@ def __init__(
"""
super().__init__(fail_silently=fail_silently)
self.token = token
self.channel = channel or os.getenv(DEFAULT_CHANNEL_ENV)
self.channel = channel or env.getenv(DEFAULT_CHANNEL_ENV)

if not self.channel:
raise AlertException(
Expand Down

0 comments on commit 8021988

Please sign in to comment.