1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
defmodule Hex.Application do
@moduledoc false
use Application
def start(_, _) do
dev_setup()
Mix.SCM.append(Hex.SCM)
Mix.RemoteConverger.register(Hex.RemoteConverger)
warn_ssl()
start_httpc()
opts = [strategy: :one_for_one, name: Hex.Supervisor]
Supervisor.start_link(children(), opts)
end
if Mix.env() in [:dev, :test] do
defp dev_setup do
:erlang.system_flag(:backtrace_depth, 20)
end
else
defp dev_setup, do: :ok
end
defp warn_ssl() do
case Application.load(:ssl) do
:ok ->
if :application.get_key(:ssl, :vsn) == {:ok, ~c"10.2"} do
Hex.Shell.warn("""
You are using an OTP release with the application ssl-10.2 which has a vulnerability \
making it susceptible to man-in-the-middle attacks. You are strongly recommended to \
upgrade to newer version, ssl-10.2.1+ or OTP-23.2.2+.
""")
end
{:error, _} ->
:ok
end
end
defp start_httpc() do
:inets.start(:httpc, profile: :hex)
opts = [
max_sessions: 8,
max_keep_alive_length: 4,
keep_alive_timeout: 120_000
]
:httpc.set_options(opts, :hex)
end
if Mix.env() == :test do
defp children do
[
Hex.Netrc.Cache,
Hex.State,
Hex.Server,
{Hex.Parallel, [:hex_fetcher]}
]
end
else
defp children do
[
Hex.Netrc.Cache,
Hex.State,
Hex.Server,
{Hex.Parallel, [:hex_fetcher]},
Hex.Registry.Server,
Hex.UpdateChecker
]
end
end
end
|