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 3 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
13 changes: 12 additions & 1 deletion lib/ecto/repo/supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,18 @@ 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
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
13 changes: 13 additions & 0 deletions test/ecto/repo/supervisor_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,19 @@ defmodule Ecto.Repo.SupervisorTest do
assert normalize(config) == [database: "mydb", extra: "extra", otp_app: :ecto, scheme: "ecto"]
end

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