Skip to content

Commit

Permalink
Make headend path an env var and add case for setting active headend …
Browse files Browse the repository at this point in the history
…as nil
  • Loading branch information
PaulJKim committed Sep 14, 2023
1 parent 1ac085e commit 5ca726c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ if config_env() != :test do
message_log_s3_folder: System.get_env("MESSAGE_LOG_S3_FOLDER"),
message_log_report_s3_folder: System.get_env("MESSAGE_LOG_REPORT_S3_FOLDER"),
monitoring_api_key: System.get_env("MONITORING_API_KEY")
active_headend_path: System.get_env("ACTIVE_HEADEND_S3_PATH", "/headend.json"),
end

if config_env() == :dev do
Expand Down
4 changes: 4 additions & 0 deletions lib/engine/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ defmodule Engine.Config do
updater = Application.get_env(:realtime_signs, :external_config_getter)

case updater.get_active_headend_ip() do
{:ok, ""} ->
Application.put_env(:realtime_signs, :sign_head_end_host, nil)
Logger.info("active_headend_ip: current: nil")

{:ok, active_headend_ip} ->
Application.put_env(:realtime_signs, :sign_head_end_host, active_headend_ip)
Logger.info("active_headend_ip: current: #{active_headend_ip}")
Expand Down
8 changes: 4 additions & 4 deletions lib/external_config/s3.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ defmodule ExternalConfig.S3 do

@behaviour ExternalConfig.Interface

@active_headend_path "/headend.json"

@impl ExternalConfig.Interface
def get(current_version) do
s3_client = Application.get_env(:realtime_signs, :s3_client)
Expand Down Expand Up @@ -37,8 +35,9 @@ defmodule ExternalConfig.S3 do
s3_client = Application.get_env(:realtime_signs, :s3_client)
aws_client = Application.get_env(:realtime_signs, :aws_client)
bucket = Application.get_env(:realtime_signs, :s3_bucket)
active_headend_path = Application.get_env(:realtime_signs, :active_headend_path)

case s3_client.get_object(bucket, @active_headend_path)
case s3_client.get_object(bucket, active_headend_path)
|> aws_client.request() do
{:ok, response} ->
body = Jason.decode!(response.body)
Expand All @@ -53,10 +52,11 @@ defmodule ExternalConfig.S3 do
s3_client = Application.get_env(:realtime_signs, :s3_client)
aws_client = Application.get_env(:realtime_signs, :aws_client)
bucket = Application.get_env(:realtime_signs, :s3_bucket)
active_headend_path = Application.get_env(:realtime_signs, :active_headend_path)

case s3_client.put_object(
bucket,
@active_headend_path,
active_headend_path,
Jason.encode!(%{active_headend_ip: ip})
)
|> aws_client.request() do
Expand Down

0 comments on commit 5ca726c

Please sign in to comment.