Skip to content

Commit

Permalink
Fix the order of case clauses when parsing database SSL config
Browse files Browse the repository at this point in the history
  • Loading branch information
alco committed May 14, 2024
1 parent a6c2563 commit 3750552
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions components/electric/config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -214,22 +214,32 @@ connector_config =
# database will be treated as a fatal error.
#
# 2. Or it is not required, in which case Electric will still try connecting with SSL first
# and will only fallback to using unencrypted connection if that fails.
# and will only fall back to using unencrypted connection if that fails.
#
# When DATABASE_REQUIRE_SSL is set by the user, the sslmode query parameter in DATABASE_URL is ignored.
require_ssl? =
case {require_ssl_config, conn_config[:sslmode]} do
{nil, :require} -> true
{nil, _} -> false
{nil, nil} -> default_database_require_ssl
{true, _} -> true
{false, _} -> false
{nil, nil} ->
# neither DATABASE_REQUIRE_SSL nor ?sslmode=... are present, use the default setting
default_database_require_ssl

{true, _} ->
# DATABASE_REQUIRE_SSL=true: require database connections to use SSL
true

{nil, :require} ->
# ?sslmode=require and DATABASE_REQUIRE_SSL is not set: require database connections to use SSL
true

_ ->
# any other value of ?sslmode=... or DATABASE_REQUIRE_SSL means SSL is not required
false
end

# When require_ssl?=true, epgsql will try to connect using SSL and fail if the server does not accept encrypted
# connections.
#
# When require_ssl?=false, epgsql will try to connect using SSL first, then fallback to an unencrypted connection
# When require_ssl?=false, epgsql will try to connect using SSL first, then fall back to an unencrypted connection
# if that fails.
use_ssl? =
if require_ssl? do
Expand Down

0 comments on commit 3750552

Please sign in to comment.