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
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773
10 changed files with 45 additions and 27 deletions

View file

@ -83,7 +83,7 @@ defmodule Mobilizon.Federation.ActivityPub.Federator do
def enqueue(type, payload, priority \\ 1) do
Logger.debug("enqueue something with type #{inspect(type)}")
if Application.fetch_env!(:mobilizon, :env) == :test do
if Application.compile_env(:mobilizon, :env) == :test do
handle(type, payload)
else
GenServer.cast(__MODULE__, {:enqueue, type, payload, priority})

View file

@ -205,7 +205,7 @@ defmodule Mobilizon.Federation.WebFinger do
{:ok, String.t()} | {:error, :link_not_found} | {:error, any()}
defp find_webfinger_endpoint(domain) when is_binary(domain) do
Logger.debug("Calling HostMetaClient for #{domain}")
prefix = if Application.fetch_env!(:mobilizon, :env) !== :dev, do: "https", else: "http"
prefix = if Application.compile_env(:mobilizon, :env) !== :dev, do: "https", else: "http"
with {:ok, %Tesla.Env{status: 200, body: body}} <-
HostMetaClient.get("#{prefix}://#{domain}/.well-known/host-meta"),
@ -229,7 +229,10 @@ defmodule Mobilizon.Federation.WebFinger do
_ ->
Logger.debug("Using default webfinger location")
prefix = if Application.fetch_env!(:mobilizon, :env) !== :dev, do: "https", else: "http"
prefix =
if Application.compile_env(:mobilizon, :env) !== :dev, do: "https", else: "http"
"#{prefix}://#{domain}/.well-known/webfinger?resource=acct:#{actor}"
end
end

View file

@ -13,7 +13,7 @@ defmodule Mix.Tasks.Mobilizon.Common do
def start_mobilizon do
if mix_task?(), do: Mix.Task.run("app.config")
unless System.get_env("DEBUG") || Application.fetch_env!(:mobilizon, :env) == :test do
unless System.get_env("DEBUG") || Application.compile_env(:mobilizon, :env) == :test do
Logger.configure(level: :error)
end
@ -73,7 +73,7 @@ defmodule Mix.Tasks.Mobilizon.Common do
IO.puts(:stderr, message)
end
if Application.fetch_env!(:mobilizon, :env) != :test do
if Application.compile_env(:mobilizon, :env) != :test do
exit({:shutdown, Keyword.get(options, :error_code, 1)})
end
end

View file

@ -21,7 +21,7 @@ defmodule Mobilizon do
@name Mix.Project.config()[:name]
@version Mix.Project.config()[:version]
@env Application.fetch_env!(:mobilizon, :env)
@env Application.compile_env(:mobilizon, :env)
@spec named_version :: String.t()
def named_version, do: "#{@name} #{@version}"

View file

@ -4,10 +4,10 @@ defmodule Mobilizon.Cldr do
"""
use Cldr,
locales: Application.get_env(:mobilizon, :cldr)[:locales],
locales: locales(),
add_fallback_locales: true,
gettext:
if(Application.fetch_env!(:mobilizon, :env) == :prod,
if(Application.compile_env(:mobilizon, :env) == :prod,
do: Mobilizon.Web.Gettext,
else: nil
),
@ -27,4 +27,8 @@ defmodule Mobilizon.Cldr do
default
end
end
defp locales do
Application.get_env(:mobilizon, :cldr)[:locales]
end
end

View file

@ -30,7 +30,7 @@ defmodule Mobilizon.Service.Activity.Utils do
@spec maybe_inserted_at :: map()
def maybe_inserted_at do
if Application.fetch_env!(:mobilizon, :env) == :test do
if Application.compile_env(:mobilizon, :env) == :test do
%{}
else
%{"inserted_at" => DateTime.utc_now()}

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