From d2372d5700012456064d9ed67b504e677acd799d Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 21 Sep 2022 10:15:28 +0200 Subject: [PATCH] fixup! Fix depreciated calls of fetch_env!/2 and get_env/2 Signed-off-by: Thomas Citharel --- lib/federation/activity_pub/federator.ex | 4 +++- lib/federation/web_finger/web_finger.ex | 7 ++++--- lib/mix/tasks/mobilizon/common.ex | 6 ++++-- lib/mobilizon/cldr.ex | 6 +----- lib/service/activity/utils.ex | 4 +++- lib/web/endpoint.ex | 19 ++++--------------- 6 files changed, 19 insertions(+), 27 deletions(-) diff --git a/lib/federation/activity_pub/federator.ex b/lib/federation/activity_pub/federator.ex index 4bba2022..6b2f68b4 100644 --- a/lib/federation/activity_pub/federator.ex +++ b/lib/federation/activity_pub/federator.ex @@ -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}) diff --git a/lib/federation/web_finger/web_finger.ex b/lib/federation/web_finger/web_finger.ex index adeec633..1f97361f 100644 --- a/lib/federation/web_finger/web_finger.ex +++ b/lib/federation/web_finger/web_finger.ex @@ -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 diff --git a/lib/mix/tasks/mobilizon/common.ex b/lib/mix/tasks/mobilizon/common.ex index 3a16c80b..910dc7e3 100644 --- a/lib/mix/tasks/mobilizon/common.ex +++ b/lib/mix/tasks/mobilizon/common.ex @@ -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 diff --git a/lib/mobilizon/cldr.ex b/lib/mobilizon/cldr.ex index a84a68c5..d24f063e 100644 --- a/lib/mobilizon/cldr.ex +++ b/lib/mobilizon/cldr.ex @@ -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 diff --git a/lib/service/activity/utils.ex b/lib/service/activity/utils.ex index d4939cbf..7594e728 100644 --- a/lib/service/activity/utils.ex +++ b/lib/service/activity/utils.ex @@ -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()} diff --git a/lib/web/endpoint.ex b/lib/web/endpoint.ex index 4612d960..f26c15c6 100644 --- a/lib/web/endpoint.ex +++ b/lib/web/endpoint.ex @@ -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