Skip to content

Commit

Permalink
Add back check_ips_as_dns_id/2 (#38)
Browse files Browse the repository at this point in the history
* Add back check_ips_as_dns_id/2
  • Loading branch information
mruoss authored Jul 25, 2024
1 parent 3df514c commit d3f4487
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion lib/flame_k8s_backend/http.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,15 @@ defmodule FlameK8sBackend.HTTP do
{:ok, String.t()} | {:error, String.t()}
defp request(http, verb, path, body \\ nil) do
headers = [{~c"Authorization", ~c"Bearer #{http.token}"}]
http_opts = [ssl: [verify: :verify_peer, cacertfile: http.cacertfile]]

http_opts = [
ssl: [
verify: :verify_peer,
cacertfile: http.cacertfile,
customize_hostname_check: [match_fun: &check_ips_as_dns_id/2]
]
]

url = http.base_url <> path

request =
Expand All @@ -57,4 +65,19 @@ defmodule FlameK8sBackend.HTTP do
"failed #{String.upcase("#{verb}")} #{url} with #{inspect(reason)} #{inspect(http.headers)}"}
end
end

if String.to_integer(System.otp_release()) < 27 do
# Workaround for an issue in OTP<27
# https://github.com/erlang/otp/issues/7968
defp check_ips_as_dns_id({:dns_id, hostname}, {:iPAddress, ip}) do
with {:ok, ip_tuple} <- :inet.parse_address(hostname),
^ip <- Tuple.to_list(ip_tuple) do
true
else
_ -> :default
end
end
end

defp check_ips_as_dns_id(_, _), do: :default
end

0 comments on commit d3f4487

Please sign in to comment.