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

View file

@ -19,6 +19,8 @@ defmodule Mobilizon.Federation.WebFinger do
require Logger
import SweetXml
@env Application.compile_env(:mobilizon, :env)
@doc """
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()}
defp find_webfinger_endpoint(domain) when is_binary(domain) do
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}} <-
HostMetaClient.get("#{prefix}://#{domain}/.well-known/host-meta"),
@ -230,8 +232,7 @@ defmodule Mobilizon.Federation.WebFinger do
_ ->
Logger.debug("Using default webfinger location")
prefix =
if Application.compile_env(:mobilizon, :env) !== :dev, do: "https", else: "http"
prefix = if @env !== :dev, do: "https", else: "http"
"#{prefix}://#{domain}/.well-known/webfinger?resource=acct:#{actor}"
end

View file

@ -9,11 +9,13 @@ defmodule Mix.Tasks.Mobilizon.Common do
"""
require Logger
@env Application.compile_env(:mobilizon, :env)
@spec start_mobilizon :: any()
def start_mobilizon do
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)
end
@ -73,7 +75,7 @@ defmodule Mix.Tasks.Mobilizon.Common do
IO.puts(:stderr, message)
end
if Application.compile_env(:mobilizon, :env) != :test do
if @env != :test do
exit({:shutdown, Keyword.get(options, :error_code, 1)})
end
end

View file

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

View file

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

View file

@ -3,7 +3,7 @@ defmodule Mobilizon.Web.Endpoint do
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
end
@ -61,7 +61,8 @@ defmodule Mobilizon.Web.Endpoint do
plug(Plug.RequestId)
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.Parsers,
@ -79,19 +80,7 @@ defmodule Mobilizon.Web.Endpoint do
String.replace_leading(url(), "http", "ws")
end
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
if Application.compile_env(:mobilizon, :env) !== :test do
plug(Sentry.PlugContext)
end
end