Skip to content

Commit

Permalink
fix: use Upptime SlackRequest model structure
Browse files Browse the repository at this point in the history
  • Loading branch information
gcharest authored Sep 12, 2024
1 parent 9321de8 commit 45a7c41
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions app/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ class Config:
extra = Extra.forbid


class UpptimeStatusPayload(BaseModel):
text: str | None = None

class Config:
extra = Extra.forbid


class AccessRequest(BaseModel):
"""
AccessRequest represents a request for access to an AWS account.
Expand Down Expand Up @@ -423,10 +430,18 @@ def handle_webhook(id: str, payload: WebhookPayload | str, request: Request):
request.state.bot.client,
f"Error parsing AWS event due to {e.__class__.__qualname__}: ```{payload}```",
)
raise HTTPException(
status_code=500,
detail=f"Failed to parse AWS event message due to {e.__class__.__qualname__}: {e}",
)
try:
payload = UpptimeStatusPayload.parse_raw(payload)
except Exception as e:
logging.error(e)
log_ops_message(
request.state.bot.client,
f"Error parsing Upptime status payload due to {e.__class__.__qualname__}: ```{payload}```",
)
raise HTTPException(
status_code=500,
detail=f"Failed to parse payload due to {e.__class__.__qualname__}: {e}",
)
if payload.Type == "SubscriptionConfirmation":
requests.get(payload.SubscribeURL, timeout=60)
logging.info(f"Subscribed webhook {id} to topic {payload.TopicArn}")
Expand All @@ -451,6 +466,8 @@ def handle_webhook(id: str, payload: WebhookPayload | str, request: Request):
logging.info("No blocks to post, returning")
return
payload = WebhookPayload(blocks=blocks)
else:
payload = WebhookPayload(**payload.dict())
payload.channel = webhook["channel"]["S"]
payload = append_incident_buttons(payload, id)
try:
Expand Down

0 comments on commit 45a7c41

Please sign in to comment.