Skip to content

fix: postgrex ssl opts #20

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,18 @@ config :libcluster,
port: 5432,
# optional, connection parameters. Defaults to []
parameters: [],
# optional, defaults to false
# optional, defaults to false. Refer to Postgrex docs
# as of v0.18 postgrex, accepts `true` or a keyword list of options
ssl: true,
# optional, please refer to the Postgrex docs
ssl_opts: nil,
# optional, please refer to the Postgrex docs
socket_options: nil,
# optional, defaults to node cookie
# must be a valid postgres identifier (alphanumeric and underscores only) with valid length
channel_name: "cluster",
# optional, heartbeat interval in ms. defaults to 5s
heartbeat_interval: 10_000
# optional, auto-reconnect to notifications, defaults to true
auto_reconnect: false
],
]
]
Expand Down
11 changes: 8 additions & 3 deletions lib/strategy.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,22 @@ defmodule LibclusterPostgres.Strategy do
def init([state]) do
channel_name = Keyword.get(state.config, :channel_name, clean_cookie(Node.get_cookie()))

ssl =
if ssl_value = Keyword.get(state.config, :ssl) do
Keyword.get(state.config, :ssl_opts) || ssl_value
end

opts = [
hostname: Keyword.fetch!(state.config, :hostname),
username: Keyword.fetch!(state.config, :username),
password: Keyword.fetch!(state.config, :password),
database: Keyword.fetch!(state.config, :database),
port: Keyword.fetch!(state.config, :port),
ssl: Keyword.get(state.config, :ssl),
ssl_opts: Keyword.get(state.config, :ssl_opts),
ssl: ssl,
socket_options: Keyword.get(state.config, :socket_options, []),
parameters: Keyword.get(state.config, :parameters, []),
channel_name: channel_name
channel_name: channel_name,
auto_reconnect: Keyword.get(state.config, :auto_reconnect, true)
]

config =
Expand Down
4 changes: 2 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule LibclusterPostgres.MixProject do
[
name: "libcluster_postgres",
app: :libcluster_postgres,
version: "0.1.3",
version: "0.2.0",
elixir: "~> 1.14",
start_permanent: Mix.env() == :prod,
deps: deps(),
Expand All @@ -27,7 +27,7 @@ defmodule LibclusterPostgres.MixProject do
defp deps do
[
{:libcluster, "~> 3.3"},
{:postgrex, ">= 0.0.0"},
{:postgrex, ">= 0.18.0"},
{:ex_doc, ">= 0.0.0", only: :dev, runtime: false}
]
end
Expand Down