Page MenuHomePhorge

No OneTemporary

Authored By
Unknown
Size
14 KB
Referenced Files
None
Subscribers
None
diff --git a/lib/mix/pleroma.ex b/lib/mix/pleroma.ex
index def050d48..0a6752bfb 100644
--- a/lib/mix/pleroma.ex
+++ b/lib/mix/pleroma.ex
@@ -1,120 +1,115 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Pleroma do
@apps [
:ecto,
:ecto_sql,
:postgrex,
:db_connection,
:cachex,
:flake_id,
:swoosh,
:timex
]
@cachex_children ["object", "user", "scrubber"]
@doc "Common functions to be reused in mix tasks"
def start_pleroma(additional_childs \\ []) do
Pleroma.Config.Holder.save_default()
Pleroma.Config.Oban.warn()
Application.put_env(:phoenix, :serve_endpoints, false, persistent: true)
if Pleroma.Config.get(:env) != :test do
Application.put_env(:logger, :console, level: :debug)
end
adapter = Application.get_env(:tesla, :adapter)
apps =
if adapter == Tesla.Adapter.Gun do
[:gun | @apps]
else
[:hackney | @apps]
end
Enum.each(apps, &Application.ensure_all_started/1)
children =
[
Pleroma.Repo,
Supervisor.child_spec({Task, &Pleroma.Config.Environment.load_and_update/0},
id: :update_env
),
Pleroma.Web.Endpoint
] ++ additional_childs
- children =
- if adapter == Tesla.Adapter.Gun do
- [Pleroma.Application.GunSupervisor | children]
- else
- [Pleroma.Application.HackneySupervisor | children]
- end
+ children = [Pleroma.Application.Dependencies.adapter_module() | children]
cachex_children =
Enum.map(@cachex_children, &Pleroma.Application.Dependencies.cachex_spec({&1, []}))
Supervisor.start_link(children ++ cachex_children,
strategy: :one_for_one,
name: Pleroma.Supervisor
)
end
def load_pleroma do
Application.load(:pleroma)
end
def get_option(options, opt, prompt, defval \\ nil, defname \\ nil) do
Keyword.get(options, opt) || shell_prompt(prompt, defval, defname)
end
def shell_prompt(prompt, defval \\ nil, defname \\ nil) do
prompt_message = "#{prompt} [#{defname || defval}] "
input =
if mix_shell?(),
do: Mix.shell().prompt(prompt_message),
else: :io.get_line(prompt_message)
case input do
"\n" ->
case defval do
nil ->
shell_prompt(prompt, defval, defname)
defval ->
defval
end
input ->
String.trim(input)
end
end
def shell_yes?(message) do
if mix_shell?(),
do: Mix.shell().yes?("Continue?"),
else: shell_prompt(message, "Continue?") in ~w(Yn Y y)
end
def shell_info(message) do
if mix_shell?(),
do: Mix.shell().info(message),
else: IO.puts(message)
end
def shell_error(message) do
if mix_shell?(),
do: Mix.shell().error(message),
else: IO.puts(:stderr, message)
end
@doc "Performs a safe check whether `Mix.shell/0` is available (does not raise if Mix is not loaded)"
def mix_shell?, do: :erlang.function_exported(Mix, :shell, 0)
def escape_sh_path(path) do
~S(') <> String.replace(path, ~S('), ~S(\')) <> ~S(')
end
end
diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex
index 1736aac23..8652e10a0 100644
--- a/lib/pleroma/application.ex
+++ b/lib/pleroma/application.ex
@@ -1,178 +1,182 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Application do
use Application
alias Pleroma.Config
require Logger
@name Mix.Project.config()[:name]
@version Mix.Project.config()[:version]
@repository Mix.Project.config()[:source_url]
@env Mix.env()
@type env() :: :test | :benchmark | :dev | :prod
def name, do: @name
def version, do: @version
def named_version, do: @name <> " " <> @version
def repository, do: @repository
def user_agent do
if Process.whereis(Pleroma.Web.Endpoint) do
case Config.get([:http, :user_agent], :default) do
:default ->
info = "#{Pleroma.Web.base_url()} <#{Config.get([:instance, :email], "")}>"
named_version() <> "; " <> info
custom ->
custom
end
else
# fallback, if endpoint is not started yet
"Pleroma Data Loader"
end
end
# See http://elixir-lang.org/docs/stable/elixir/Application.html
# for more information on OTP Applications
+ @impl true
def start(_type, _args) do
# Scrubbers are compiled at runtime and therefore will cause a conflict
# every time the application is restarted, so we disable module
# conflicts at runtime
Code.compiler_options(ignore_module_conflict: true)
# Disable warnings_as_errors at runtime, it breaks Phoenix live reload
# due to protocol consolidation warnings
Code.compiler_options(warnings_as_errors: false)
Pleroma.Telemetry.Logger.attach()
Config.Holder.save_default()
Pleroma.HTML.compile_scrubbers()
Pleroma.Config.Oban.warn()
Config.DeprecationWarnings.warn()
Pleroma.Plugs.HTTPSecurityPlug.warn_if_disabled()
Pleroma.Application.Requirements.verify!()
Pleroma.Application.Dependencies.save_dynamic_children_config_relations()
setup_instrumenters()
load_custom_modules()
check_system_commands()
Pleroma.Docs.JSON.compile()
if Application.get_env(:tesla, :adapter) == Tesla.Adapter.Gun do
if version = Pleroma.OTPVersion.version() do
[major, minor] =
version
|> String.split(".")
|> Enum.map(&String.to_integer/1)
|> Enum.take(2)
if (major == 22 and minor < 2) or major < 22 do
raise "
!!!OTP VERSION WARNING!!!
You are using gun adapter with OTP version #{version}, which doesn't support correct handling of unordered certificates chains. Please update your Erlang/OTP to at least 22.2.
"
end
else
raise "
!!!OTP VERSION WARNING!!!
To support correct handling of unordered certificates chains - OTP version must be > 22.2.
"
end
end
# Define workers and child supervisors to be supervised
children = [
Pleroma.Repo,
Pleroma.Application.DependenciesSupervisor,
Pleroma.Application.DependenciesState
]
# See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
# for other strategies and supported options
Supervisor.start_link(children, strategy: :one_for_one, name: Pleroma.Supervisor)
end
+ @impl true
def start_phase(:update_env, :normal, _args) do
# Load and update the environment from the config settings in the database
Pleroma.Config.Environment.load_and_update()
end
+ @impl true
def start_phase(:static_deps, :normal, _args) do
# Start static children,
# which don't require any configuration or can be configured in runtime
@env
|> Pleroma.Application.Dependencies.static()
|> Pleroma.Application.DependenciesSupervisor.start_children(:static)
end
+ @impl true
def start_phase(:dynamic_deps, :normal, _args) do
# Start dynamic children,
# which require restart after some config changes
@env
|> Pleroma.Application.Dependencies.dynamic()
|> Pleroma.Application.DependenciesSupervisor.start_children(:dynamic)
end
def load_custom_modules do
dir = Config.get([:modules, :runtime_dir])
if dir && File.exists?(dir) do
dir
|> Pleroma.Utils.compile_dir()
|> case do
{:error, _errors, _warnings} ->
raise "Invalid custom modules"
{:ok, modules, _warnings} ->
if @env != :test do
Enum.each(modules, fn mod ->
Logger.info("Custom module loaded: #{inspect(mod)}")
end)
end
:ok
end
end
end
defp setup_instrumenters do
require Prometheus.Registry
if Application.get_env(:prometheus, Pleroma.Repo.Instrumenter) do
:ok =
:telemetry.attach(
"prometheus-ecto",
[:pleroma, :repo, :query],
&Pleroma.Repo.Instrumenter.handle_event/4,
%{}
)
Pleroma.Repo.Instrumenter.setup()
end
Pleroma.Web.Endpoint.MetricsExporter.setup()
Pleroma.Web.Endpoint.PipelineInstrumenter.setup()
Pleroma.Web.Endpoint.Instrumenter.setup()
end
defp check_system_commands do
filters = Config.get([Pleroma.Upload, :filters])
check_filter = fn filter, command_required ->
with true <- filter in filters,
false <- Pleroma.Utils.command_available?(command_required) do
Logger.error(
"#{filter} is specified in list of Pleroma.Upload filters, but the #{command_required} command is not found"
)
end
end
check_filter.(Pleroma.Upload.Filters.Exiftool, "exiftool")
check_filter.(Pleroma.Upload.Filters.Mogrify, "mogrify")
check_filter.(Pleroma.Upload.Filters.Mogrifun, "mogrify")
end
end
diff --git a/lib/pleroma/application/dependencies.ex b/lib/pleroma/application/dependencies.ex
index d796a0473..c0170c7ed 100644
--- a/lib/pleroma/application/dependencies.ex
+++ b/lib/pleroma/application/dependencies.ex
@@ -1,163 +1,164 @@
# # Pleroma: A lightweight social networking server
# # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# # SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Application.Dependencies do
alias Pleroma.Application.GunSupervisor
alias Pleroma.Application.HackneySupervisor
alias Pleroma.Config
alias Pleroma.Web.Endpoint
require Cachex.Spec
@type config_path() :: {atom(), atom()} | {atom(), atom(), [atom()]}
@type relation() :: {config_path(), module()}
@spec static(Pleroma.Application.env()) :: [:supervisor.child_spec() | module()]
def static(env) do
[
Pleroma.Emoji,
Pleroma.Stats,
Pleroma.JobQueueMonitor,
%{
id: :web_push_init,
start: {Task, :start_link, [&Pleroma.Web.Push.init/0]},
restart: :temporary
}
]
|> add_cachex_children()
|> maybe_add_init_internal_fetch_actor_task(env)
|> maybe_add(:sockets, env)
end
@spec dynamic(Pleroma.Application.env()) :: [:supervisor.child_spec() | module()]
def dynamic(env) do
[
Pleroma.Plugs.RateLimiter.Supervisor,
Oban,
Endpoint,
Pleroma.Gopher.Server,
Pleroma.Web.ChatChannel.ChatChannelState
]
|> add_http_children(env)
|> maybe_add(:streamer, env)
end
@spec cachex_spec({String.t(), keyword()}) :: :supervisor.child_spec()
def cachex_spec({type, opts}) do
%{
id: String.to_atom("cachex_" <> type),
start: {Cachex, :start_link, [String.to_atom(type <> "_cache"), opts]},
type: :worker
}
end
defp add_cachex_children(children) do
cachex_children =
[
{"used_captcha", ttl_interval: seconds_valid_interval()},
{"user", default_ttl: 25_000, ttl_interval: 1000, limit: 2500},
{"object", default_ttl: 25_000, ttl_interval: 1000, limit: 2500},
{"rich_media", default_ttl: :timer.minutes(120), limit: 5000},
{"scrubber", limit: 2500},
{"idempotency", expiration: cachex_expiration(6 * 60 * 60, 60), limit: 2500},
{"web_resp", limit: 2500},
{"emoji_packs", expiration: cachex_expiration(5 * 60, 60), limit: 10},
{"failed_proxy_url", limit: 2500},
{"banned_urls", default_ttl: :timer.hours(24 * 30), limit: 5_000}
]
|> Enum.map(&cachex_spec/1)
children ++ cachex_children
end
defp cachex_expiration(default, interval) do
Cachex.Spec.expiration(default: :timer.seconds(default), interval: :timer.seconds(interval))
end
defp seconds_valid_interval do
[Pleroma.Captcha, :seconds_valid]
|> Config.get!()
|> :timer.seconds()
end
defp maybe_add_init_internal_fetch_actor_task(children, :test), do: children
defp maybe_add_init_internal_fetch_actor_task(children, _) do
children ++
[
%{
id: :internal_fetch_init,
start: {Task, :start_link, [&Pleroma.Web.ActivityPub.InternalFetchActor.init/0]},
restart: :temporary
}
]
end
defp maybe_add(children, _, env) when env in [:test, :benchmark], do: children
defp maybe_add(children, :sockets, _), do: [Pleroma.Web.FedSockets.Supervisor | children]
defp maybe_add(children, :streamer, _), do: [Pleroma.Web.Streamer.registry() | children]
defp add_http_children(children, :test) do
[HackneySupervisor, GunSupervisor | children]
end
defp add_http_children(children, _), do: [adapter_module() | children]
- defp adapter_module do
+ @spec adapter_module() :: module()
+ def adapter_module do
if Application.get_env(:tesla, :adapter) == Tesla.Adapter.Gun do
GunSupervisor
else
HackneySupervisor
end
end
@spec save_dynamic_children_config_relations() :: :ok
def save_dynamic_children_config_relations do
relations = [
{{:pleroma, :chat}, Pleroma.Web.ChatChannel.ChatChannelState},
{{:pleroma, Oban}, Oban},
{{:pleroma, :rate_limit}, Pleroma.Plugs.RateLimiter.Supervisor},
{{:pleroma, :streamer}, Pleroma.Web.Streamer.registry()},
{{:pleroma, :pools}, GunSupervisor},
{{:pleroma, :connections_pool}, GunSupervisor},
{{:pleroma, :hackney_pools}, HackneySupervisor},
{{:pleroma, :gopher}, Pleroma.Gopher.Server},
{{:pleroma, Pleroma.Captcha, [:seconds_valid]}, Endpoint},
{{:pleroma, Pleroma.Upload, [:proxy_remote]}, adapter_module()},
{{:pleroma, :instance, [:upload_limit]}, Endpoint},
{{:pleroma, :fed_sockets, [:enabled]}, Endpoint}
]
Config.put(:config_relations, relations)
end
@spec config_relations() :: [relation()]
def config_relations, do: Config.get(:config_relations)
@spec find_relation(config_path()) :: relation() | {:error, :relation_not_found}
def find_relation(path) do
with nil <- Enum.find(config_relations(), fn {key, _} -> key == path end) do
{:error, :relation_not_found}
end
end
@spec find_relation(atom(), atom(), any()) :: relation() | nil
def find_relation(group, key, value) do
Enum.find(config_relations(), fn
{{g, k}, _} ->
g == group and k == key
{{g, k, subkeys}, _} ->
Keyword.keyword?(value) and g == group and k == key and
Enum.any?(Keyword.keys(value), &(&1 in subkeys))
end)
end
@spec find_relations(module()) :: [relation()] | {:error, :relations_not_found}
def find_relations(module) do
with [] <- Enum.filter(config_relations(), fn {_, m} -> m == module end) do
{:error, :relations_not_found}
end
end
end

File Metadata

Mime Type
text/x-diff
Expires
Sun, Nov 1, 3:05 PM (10 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1803125
Default Alt Text
(14 KB)

Event Timeline