Skip to content

Commit

Permalink
fix: Determine the SNS module to use at runtime (#1356)
Browse files Browse the repository at this point in the history
We can't bake in the `ex_aws` module at compile time because we might be
overwriting it at runtime.
  • Loading branch information
arkadyan authored Sep 7, 2023
1 parent e6e19e4 commit 0563636
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions apps/concierge_site/lib/controllers/rejected_email_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ defmodule ConciergeSite.RejectedEmailController do
alias AlertProcessor.Model.User
require Logger

@ex_aws Application.compile_env!(:alert_processor, :ex_aws)

def handle_message(conn, _params) do
with {:ok, raw_body, conn} <- read_body(conn),
{:ok, params} <- Poison.decode(raw_body),
:ok <- @ex_aws.SNS.verify_message(params) do
:ok <- sns().verify_message(params) do
do_handle_message(params)
send_resp(conn, :no_content, "")
else
Expand All @@ -27,6 +25,12 @@ defmodule ConciergeSite.RejectedEmailController do
end
end

defp sns do
mod = String.to_existing_atom("#{Application.get_env(:alert_processor, :ex_aws)}.SNS")
Logger.info("Using SNS module #{mod}")
mod
end

defp do_handle_message(%{"Type" => "SubscriptionConfirmation", "SubscribeURL" => url}) do
{:ok, %{status_code: 200}} = HTTPoison.get(url)
log_info("event=subscription_confirmation")
Expand Down

0 comments on commit 0563636

Please sign in to comment.