Skip to content

Commit

Permalink
feat: add cookie cleaning for postgres identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziinc committed Nov 15, 2023
1 parent 3433c22 commit 3b01318
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/logflare/cluster/postgres_strategy.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ defmodule Logflare.Cluster.PostgresStrategy do
new_config =
state.config
|> Keyword.put_new(:heartbeat_interval, 5_000)
|> Keyword.put(:channel_name, Atom.to_string(Node.get_cookie()))
|> Keyword.put(:channel_name, clean_cookie(Node.get_cookie()))
|> Keyword.put(:url, url)

meta = %{
Expand Down Expand Up @@ -114,4 +114,9 @@ defmodule Logflare.Cluster.PostgresStrategy do
database = Application.get_env(:logflare, Logflare.Repo)[:database]
~s|postgresql://#{username}:#{password}@#{hostname}:#{port}/#{database}|
end

defp clean_cookie(cookie) when is_atom(cookie), do: cookie |> Atom.to_string() |> clean_cookie()
defp clean_cookie(str) when is_binary(str) do
String.replace(str, ~r/\W/, "_") |> dbg()
end
end

0 comments on commit 3b01318

Please sign in to comment.