honkoma/lib/pleroma/otp_version.ex

74 lines
1.8 KiB
Elixir
Raw Normal View History

2020-03-03 09:19:29 +00:00
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
2020-02-11 07:12:57 +00:00
2020-03-03 09:19:29 +00:00
defmodule Pleroma.OTPVersion do
@type check_status() :: :ok | :undefined | {:error, String.t()}
2020-02-11 07:12:57 +00:00
@spec check!() :: :ok | no_return()
def check! do
case check() do
:ok ->
:ok
{:error, version} ->
raise "
!!!OTP VERSION WARNING!!!
You are using gun adapter with OTP version #{version}, which doesn't support correct handling of unordered certificates chains.
"
:undefined ->
raise "
!!!OTP VERSION WARNING!!!
To support correct handling of unordered certificates chains - OTP version must be > 22.2.
"
end
end
2020-03-03 09:19:29 +00:00
@spec check() :: check_status()
def check do
2020-02-11 07:12:57 +00:00
# OTP Version https://erlang.org/doc/system_principles/versions.html#otp-version
2020-03-03 09:19:29 +00:00
[
2020-02-11 07:12:57 +00:00
Path.join(:code.root_dir(), "OTP_VERSION"),
Path.join([:code.root_dir(), "releases", :erlang.system_info(:otp_release), "OTP_VERSION"])
]
2020-03-03 09:19:29 +00:00
|> get_version_from_files()
|> do_check()
2020-02-11 07:12:57 +00:00
end
2020-03-03 09:19:29 +00:00
@spec check([Path.t()]) :: check_status()
def check(paths) do
2020-02-11 07:12:57 +00:00
paths
2020-03-03 09:19:29 +00:00
|> get_version_from_files()
|> do_check()
2020-02-11 07:12:57 +00:00
end
2020-03-03 09:19:29 +00:00
defp get_version_from_files([]), do: nil
2020-02-11 07:12:57 +00:00
2020-03-03 09:19:29 +00:00
defp get_version_from_files([path | paths]) do
2020-02-11 07:12:57 +00:00
if File.exists?(path) do
File.read!(path)
else
2020-03-03 09:19:29 +00:00
get_version_from_files(paths)
2020-02-11 07:12:57 +00:00
end
end
2020-03-03 09:19:29 +00:00
defp do_check(nil), do: :undefined
defp do_check(version) do
version = String.replace(version, ~r/\r|\n|\s/, "")
[major, minor] =
version
|> String.split(".")
|> Enum.map(&String.to_integer/1)
|> Enum.take(2)
if (major == 22 and minor >= 2) or major > 22 do
:ok
else
{:error, version}
2020-02-11 07:12:57 +00:00
end
end
end