aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2023-09-27 18:16:27 +0300
committerJan Tuomi <jans.tuomi@gmail.com>2023-09-27 18:16:27 +0300
commitda9b89d089482354bce0fc95b66f30fd078405b1 (patch)
treeed7438ca68e996fcdc222b07e7a4a6c66876de66
parent47955f34dfbc7c3ae2dfa1f7c94b44e435743a94 (diff)
Use headers instead of auth syntax in EmailAlerter
-rw-r--r--Aggrofile5
-rw-r--r--aggro.py2
-rw-r--r--app/AggroConfig.py2
-rw-r--r--app/EmailAlerter.py15
4 files changed, 13 insertions, 11 deletions
diff --git a/Aggrofile b/Aggrofile
index 6f6864c..afd6bb7 100644
--- a/Aggrofile
+++ b/Aggrofile
@@ -6,7 +6,10 @@
},
"email_alerter": {
"api_url": "${AGGRO_EMAIL_ALERT_API_URL}",
- "api_auth": "${AGGRO_EMAIL_ALERT_API_AUTH}",
+ "api_headers": {
+ "Authorization": "${AGGRO_EMAIL_ALERT_API_AUTH}",
+ "Content-Type": "application/json"
+ },
"email_from": "${AGGRO_EMAIL_ALERT_FROM}",
"email_to": [
"${AGGRO_EMAIL_ALERT_TO}"
diff --git a/aggro.py b/aggro.py
index 695de44..4f315e4 100644
--- a/aggro.py
+++ b/aggro.py
@@ -48,7 +48,7 @@ if __name__ == "__main__":
if aggrofile_email_alerter:
email_alerter_config = AggroConfigEmailAlerter(
api_url=get_config(aggrofile_email_alerter, "api_url"),
- api_auth=get_config(aggrofile_email_alerter, "api_auth"),
+ api_headers=get_config(aggrofile_email_alerter, "api_headers"),
email_from=get_config(aggrofile_email_alerter, "email_from"),
email_to=get_config(aggrofile_email_alerter, "email_to"),
)
diff --git a/app/AggroConfig.py b/app/AggroConfig.py
index 01d1230..6dfbb94 100644
--- a/app/AggroConfig.py
+++ b/app/AggroConfig.py
@@ -12,7 +12,7 @@ class AggroConfigServer:
@dataclass
class AggroConfigEmailAlerter:
api_url: str
- api_auth: str
+ api_headers: dict[str, str]
email_from: str
email_to: list[str]
diff --git a/app/EmailAlerter.py b/app/EmailAlerter.py
index 823cbf1..d4406fc 100644
--- a/app/EmailAlerter.py
+++ b/app/EmailAlerter.py
@@ -11,17 +11,16 @@ class EmailAlerter:
return EmailAlerter(**asdict(config))
def __init__(
- self, api_url: str, api_auth: str, email_from: str, email_to: list[str]
+ self,
+ api_url: str,
+ api_headers: dict[str, str],
+ email_from: str,
+ email_to: list[str],
):
self.api_url = api_url
self.email_from = email_from
self.email_to = email_to
- api_auth_parts = api_auth.split(":")
- if len(api_auth_parts) != 2:
- raise Exception(
- "[EmailAlerter] supplied api_auth is not of form <key>:<value>"
- )
- self.api_auth = (api_auth_parts[0], api_auth_parts[1])
+ self.api_headers = api_headers
def send_alert(self, text: str):
try:
@@ -35,8 +34,8 @@ class EmailAlerter:
}
r = requests.post(
self.api_url,
- auth=self.api_auth,
data=data,
+ headers=self.api_headers,
)
if r.status_code >= 400:
raise Exception(