Fix depreciated calls of fetch_env!/2 and get_env/2

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2022-09-21 08:53:50 +02:00
parent 655ae4f9a1
commit bbbaa81a6e
10 changed files with 45 additions and 27 deletions

View File

@@ -8,12 +8,10 @@ defmodule Mobilizon.Web.AuthController do
require Logger
plug(:put_layout, false)
config = Application.get_env(:mobilizon, Mobilizon.Web.Endpoint, [])
plug(Plug.Session,
store: :cookie,
key: "_auth_callback",
signing_salt: Keyword.get(config, :secret_key_base)
signing_salt: Keyword.get(endpoint_config, :secret_key_base)
)
plug(Ueberauth)
@@ -142,4 +140,8 @@ defmodule Mobilizon.Web.AuthController do
defp redirect_to_error(conn, :unknown_error, provider_name) do
redirect(conn, to: "/login?code=Error with Login Provider&provider=#{provider_name}")
end
defp endpoint_config do
Application.get_env(:mobilizon, Mobilizon.Web.Endpoint, [])
end
end

View File

@@ -3,8 +3,7 @@ defmodule Mobilizon.Web.Endpoint do
Endpoint for Mobilizon app
"""
if Application.fetch_env!(:mobilizon, :env) !== :test &&
Application.get_env(:sentry, :dsn) != nil do
if Application.compile_env(:mobilizon, :env) !== :test && sentry_dsn_config() != nil do
use Sentry.PlugCapture
end
@@ -13,7 +12,7 @@ defmodule Mobilizon.Web.Endpoint do
plug(Mobilizon.Web.Plugs.DetectLocalePlug)
if Application.fetch_env!(:mobilizon, :env) !== :dev do
if Application.compile_env(:mobilizon, :env) !== :dev do
plug(Mobilizon.Web.Plugs.HTTPSecurityPlug)
end
@@ -31,9 +30,7 @@ defmodule Mobilizon.Web.Endpoint do
longpoll: false
)
endpoint_config = Application.get_env(:mobilizon, Mobilizon.Web.Endpoint)
if Keyword.get(endpoint_config, :has_reverse_proxy, false) == true do
if Keyword.get(endpoint_config(), :has_reverse_proxy, false) == true do
plug(RemoteIp)
end
@@ -64,8 +61,7 @@ defmodule Mobilizon.Web.Endpoint do
plug(Plug.RequestId)
plug(Plug.Logger)
upload_limit =
Keyword.get(Application.get_env(:mobilizon, :instance, []), :upload_limit, 10_485_760)
upload_limit = Keyword.get(instance_config(), :upload_limit, 10_485_760)
plug(
Plug.Parsers,
@@ -83,8 +79,19 @@ defmodule Mobilizon.Web.Endpoint do
String.replace_leading(url(), "http", "ws")
end
if Application.fetch_env!(:mobilizon, :env) !== :test &&
Application.get_env(:sentry, :dsn) != nil do
defp sentry_dsn_config do
Application.get_env(:sentry, :dsn)
end
defp endpoint_config do
Application.get_env(:mobilizon, Mobilizon.Web.Endpoint)
end
defp instance_config do
Application.get_env(:mobilizon, :instance, [])
end
if Application.compile_env(:mobilizon, :env) !== :test && sentry_dsn_config() != nil do
plug(Sentry.PlugContext)
end
end

View File

@@ -83,8 +83,6 @@ defmodule Mobilizon.Web.ReverseProxy do
| {:inline_content_types, boolean | [String.t()]}
| {:redirect_on_failure, boolean}
@hackney Application.get_env(:mobilizon, :hackney, :hackney)
@default_hackney_options []
@inline_content_types [
@@ -171,7 +169,7 @@ defmodule Mobilizon.Web.ReverseProxy do
Logger.debug("#{__MODULE__} #{method} #{url} #{inspect(headers)}")
method = method |> String.downcase() |> String.to_existing_atom()
case @hackney.request(method, url, headers, "", hackney_opts) do
case hackney().request(method, url, headers, "", hackney_opts) do
{:ok, code, headers, client} when code in @valid_resp_codes ->
{:ok, code, downcase_headers(headers), client}
@@ -231,7 +229,7 @@ defmodule Mobilizon.Web.ReverseProxy do
duration,
Keyword.get(opts, :max_read_duration, @max_read_duration)
),
{:ok, data} <- @hackney.stream_body(client),
{:ok, data} <- hackney().stream_body(client),
{:ok, duration} <- increase_read_duration({duration, now}),
sent_so_far = sent_so_far + byte_size(data),
:ok <- body_size_constraint(sent_so_far, Keyword.get(opts, :max_body_size)),
@@ -452,4 +450,8 @@ defmodule Mobilizon.Web.ReverseProxy do
uri = URI.parse(url)
uri.scheme != nil && uri.host =~ "."
end
defp hackney do
Application.get_env(:mobilizon, :hackney, :hackney)
end
end

View File

@@ -212,7 +212,7 @@ defmodule Mobilizon.Web.Router do
get("/:sig/:url/:filename", MediaProxyController, :remote)
end
if Application.fetch_env!(:mobilizon, :env) in [:dev, :e2e] do
if Application.compile_env(:mobilizon, :env) in [:dev, :e2e] do
# If using Phoenix
forward("/sent_emails", Plug.Swoosh.MailboxPreview)
end