refactor: fix review comments
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
93e1ec7414
commit
b1740e3435
10 changed files with 63 additions and 199 deletions
|
|
@ -470,11 +470,19 @@ defmodule Mv.Config do
|
|||
# ---------------------------------------------------------------------------
|
||||
|
||||
@doc """
|
||||
Returns SMTP host. ENV `SMTP_HOST` overrides Settings.
|
||||
Returns SMTP host.
|
||||
|
||||
Policy:
|
||||
- ENV-only mode (`SMTP_HOST` set): read from ENV `SMTP_HOST`
|
||||
- Settings mode: read from Settings only
|
||||
"""
|
||||
@spec smtp_host() :: String.t() | nil
|
||||
def smtp_host do
|
||||
smtp_env_or_setting("SMTP_HOST", :smtp_host)
|
||||
if smtp_env_mode?() do
|
||||
System.get_env("SMTP_HOST") |> trim_nil()
|
||||
else
|
||||
get_from_settings(:smtp_host)
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
|
@ -522,7 +530,7 @@ defmodule Mv.Config do
|
|||
def smtp_password do
|
||||
if smtp_env_mode?() do
|
||||
case System.get_env("SMTP_PASSWORD") do
|
||||
nil -> smtp_password_from_file_or_settings()
|
||||
nil -> smtp_password_from_file()
|
||||
value -> trim_nil(value)
|
||||
end
|
||||
else
|
||||
|
|
@ -530,7 +538,7 @@ defmodule Mv.Config do
|
|||
end
|
||||
end
|
||||
|
||||
defp smtp_password_from_file_or_settings do
|
||||
defp smtp_password_from_file do
|
||||
case System.get_env("SMTP_PASSWORD_FILE") do
|
||||
nil -> nil
|
||||
path -> read_smtp_password_file(path)
|
||||
|
|
@ -568,14 +576,6 @@ defmodule Mv.Config do
|
|||
present?(smtp_host())
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns true when SMTP ENV mode is active.
|
||||
"""
|
||||
@spec smtp_env_configured?() :: boolean()
|
||||
def smtp_env_configured? do
|
||||
smtp_env_mode?()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns true when SMTP is managed by environment variables.
|
||||
|
||||
|
|
@ -599,6 +599,7 @@ defmodule Mv.Config do
|
|||
[]
|
||||
|> maybe_add_missing("SMTP_USERNAME", smtp_username_env_set?())
|
||||
|> maybe_add_missing("SMTP_PASSWORD/SMTP_PASSWORD_FILE", smtp_password_env_set?())
|
||||
|> Enum.reverse()
|
||||
else
|
||||
[]
|
||||
end
|
||||
|
|
@ -665,8 +666,6 @@ defmodule Mv.Config do
|
|||
@spec mail_from_email_env_set?() :: boolean()
|
||||
def mail_from_email_env_set?, do: env_set?("MAIL_FROM_EMAIL")
|
||||
|
||||
defp parse_smtp_port_env(nil), do: nil
|
||||
|
||||
defp parse_smtp_port_env(value) when is_binary(value) do
|
||||
case Integer.parse(String.trim(value)) do
|
||||
{port, _} when port > 0 -> port
|
||||
|
|
@ -676,16 +675,8 @@ defmodule Mv.Config do
|
|||
|
||||
defp parse_smtp_port_env(_), do: nil
|
||||
|
||||
# Reads a plain string SMTP setting: ENV first, then Settings.
|
||||
defp smtp_env_or_setting(env_key, setting_key) do
|
||||
case System.get_env(env_key) do
|
||||
nil -> get_from_settings(setting_key)
|
||||
value -> trim_nil(value)
|
||||
end
|
||||
end
|
||||
|
||||
defp maybe_add_missing(acc, _label, true), do: acc
|
||||
defp maybe_add_missing(acc, label, false), do: acc ++ [label]
|
||||
defp maybe_add_missing(acc, label, false), do: [label | acc]
|
||||
|
||||
# Reads an integer setting attribute from Settings.
|
||||
defp get_from_settings_integer(key) do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue