fixup! 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 10:15:28 +02:00
parent 009f90e0d7
commit d2372d5700
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773
6 changed files with 19 additions and 27 deletions

View file

@ -19,6 +19,8 @@ defmodule Mobilizon.Federation.ActivityPub.Federator do
@max_jobs 20 @max_jobs 20
@env Application.compile_env(:mobilizon, :env)
@spec init(any()) :: {:ok, any()} @spec init(any()) :: {:ok, any()}
def init(args) do def init(args) do
{:ok, args} {:ok, args}
@ -83,7 +85,7 @@ defmodule Mobilizon.Federation.ActivityPub.Federator do
def enqueue(type, payload, priority \\ 1) do def enqueue(type, payload, priority \\ 1) do
Logger.debug("enqueue something with type #{inspect(type)}") Logger.debug("enqueue something with type #{inspect(type)}")
if Application.compile_env(:mobilizon, :env) == :test do if @env == :test do
handle(type, payload) handle(type, payload)
else else
GenServer.cast(__MODULE__, {:enqueue, type, payload, priority}) GenServer.cast(__MODULE__, {:enqueue, type, payload, priority})

View file

@ -19,6 +19,8 @@ defmodule Mobilizon.Federation.WebFinger do
require Logger require Logger
import SweetXml import SweetXml
@env Application.compile_env(:mobilizon, :env)
@doc """ @doc """
Returns the Web Host Metadata (for `/.well-known/host-meta`) representation for the instance, following RFC6414. Returns the Web Host Metadata (for `/.well-known/host-meta`) representation for the instance, following RFC6414.
""" """
@ -205,7 +207,7 @@ defmodule Mobilizon.Federation.WebFinger do
{:ok, String.t()} | {:error, :link_not_found} | {:error, any()} {:ok, String.t()} | {:error, :link_not_found} | {:error, any()}
defp find_webfinger_endpoint(domain) when is_binary(domain) do defp find_webfinger_endpoint(domain) when is_binary(domain) do
Logger.debug("Calling HostMetaClient for #{domain}") Logger.debug("Calling HostMetaClient for #{domain}")
prefix = if Application.compile_env(:mobilizon, :env) !== :dev, do: "https", else: "http" prefix = if @env !== :dev, do: "https", else: "http"
with {:ok, %Tesla.Env{status: 200, body: body}} <- with {:ok, %Tesla.Env{status: 200, body: body}} <-
HostMetaClient.get("#{prefix}://#{domain}/.well-known/host-meta"), HostMetaClient.get("#{prefix}://#{domain}/.well-known/host-meta"),
@ -230,8 +232,7 @@ defmodule Mobilizon.Federation.WebFinger do
_ -> _ ->
Logger.debug("Using default webfinger location") Logger.debug("Using default webfinger location")
prefix = prefix = if @env !== :dev, do: "https", else: "http"
if Application.compile_env(:mobilizon, :env) !== :dev, do: "https", else: "http"
"#{prefix}://#{domain}/.well-known/webfinger?resource=acct:#{actor}" "#{prefix}://#{domain}/.well-known/webfinger?resource=acct:#{actor}"
end end

View file

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

View file

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

View file

@ -6,6 +6,8 @@ defmodule Mobilizon.Service.Activity.Utils do
alias Mobilizon.Activities.Activity alias Mobilizon.Activities.Activity
alias Mobilizon.Service.Activity, as: ActivityService alias Mobilizon.Service.Activity, as: ActivityService
@env Application.compile_env(:mobilizon, :env)
def transform_activity(%Activity{} = activity) do def transform_activity(%Activity{} = activity) do
activity activity
|> Map.update(:subject_params, %{}, &transform_params/1) |> Map.update(:subject_params, %{}, &transform_params/1)
@ -30,7 +32,7 @@ defmodule Mobilizon.Service.Activity.Utils do
@spec maybe_inserted_at :: map() @spec maybe_inserted_at :: map()
def maybe_inserted_at do def maybe_inserted_at do
if Application.compile_env(:mobilizon, :env) == :test do if @env == :test do
%{} %{}
else else
%{"inserted_at" => DateTime.utc_now()} %{"inserted_at" => DateTime.utc_now()}

View file

@ -3,7 +3,7 @@ defmodule Mobilizon.Web.Endpoint do
Endpoint for Mobilizon app Endpoint for Mobilizon app
""" """
if Application.compile_env(:mobilizon, :env) !== :test && sentry_dsn_config() != nil do if Application.compile_env(:mobilizon, :env) !== :test do
use Sentry.PlugCapture use Sentry.PlugCapture
end end
@ -61,7 +61,8 @@ defmodule Mobilizon.Web.Endpoint do
plug(Plug.RequestId) plug(Plug.RequestId)
plug(Plug.Logger) plug(Plug.Logger)
upload_limit = Keyword.get(instance_config(), :upload_limit, 10_485_760) upload_limit =
Keyword.get(Application.compile_env(:mobilizon, :instance, []), :upload_limit, 10_485_760)
plug( plug(
Plug.Parsers, Plug.Parsers,
@ -79,19 +80,7 @@ defmodule Mobilizon.Web.Endpoint do
String.replace_leading(url(), "http", "ws") String.replace_leading(url(), "http", "ws")
end end
defp sentry_dsn_config do if Application.compile_env(:mobilizon, :env) !== :test 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) plug(Sentry.PlugContext)
end end
end end