Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid overwriting ssl opts with url if already set in config #4498

Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion lib/ecto/repo/supervisor.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
defmodule Ecto.Repo.Supervisor do
@moduledoc false
use Supervisor
require Logger

@defaults [timeout: 15000, pool_size: 10]
@integer_url_query_params ["timeout", "pool_size", "idle_interval"]
Expand All @@ -25,7 +26,22 @@ defmodule Ecto.Repo.Supervisor do
case repo_init(type, repo, config) do
{:ok, config} ->
{url, config} = Keyword.pop(config, :url)
{:ok, Keyword.merge(config, parse_url(url || ""))}
url_config = parse_url(url || "")

# if config already has `ssl` set, e.g.: `ssl: [cacertfile: "/path/to/file"]`
# the URL's `ssl=true` parameter is dropped
url_config =
if is_list(config[:ssl]) and url_config[:ssl] == true do
Logger.warning(
"Ignoring `ssl=true` parameter in URL because `ssl` is already set in the configuration: #{inspect(config[:ssl])}"
josevalim marked this conversation as resolved.
Show resolved Hide resolved
)

Keyword.delete(url_config, :ssl)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also log?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, forgot that part :) Thank you!

else
url_config
end

{:ok, Keyword.merge(config, url_config)}

:ignore ->
:ignore
Expand Down
14 changes: 14 additions & 0 deletions test/ecto/repo/supervisor_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ defmodule Ecto.Repo.SupervisorTest do
assert normalize(config) == [database: "mydb", extra: "extra", otp_app: :ecto, scheme: "ecto"]
end

@tag :capture_log
test "URL options do not overwrite SSL cacertfile from config" do
put_env(database: "hello", url: "ecto:///mydb?ssl=true", ssl: [cacertfile: "/path/to/file"])
{:ok, config} = init_config(:runtime, __MODULE__, :ecto, extra: "extra")

assert normalize(config) == [
database: "mydb",
extra: "extra",
otp_app: :ecto,
scheme: "ecto",
ssl: [cacertfile: "/path/to/file"]
]
end

test "is no-op for nil or empty URL" do
put_env(database: "hello", url: nil)
{:ok, config} = init_config(:runtime, __MODULE__, :ecto, [])
Expand Down
Loading