Skip to content

Commit

Permalink
naive config validation
Browse files Browse the repository at this point in the history
  • Loading branch information
abc3 committed Nov 15, 2023
1 parent ef2221a commit 389e88c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/supavisor/db_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ defmodule Supavisor.DbHandler do
end

def handle_event(:info, {_proto, _, bin}, _, %{replica_type: :read} = data) do
Logger.debug("Got read replica message #{inspect(bin)}")
pkts = Server.decode(bin)

resp =
Expand Down Expand Up @@ -277,6 +278,7 @@ defmodule Supavisor.DbHandler do
end

def handle_event(:info, {_proto, _, bin}, _, %{caller: caller} = data) when is_pid(caller) do
Logger.debug("Got write replica message #{inspect(bin)}")
# check if the response ends with "ready for query"
{ready, data} =
if String.ends_with?(bin, Server.ready_for_query()) do
Expand Down
11 changes: 9 additions & 2 deletions lib/supavisor/tenants.ex
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ defmodule Supavisor.Tenants do
)
end

@spec get_cluster_config(String.t(), String.t()) :: [ClusterTenants.t()] | nil
@spec get_cluster_config(String.t(), String.t()) :: [ClusterTenants.t()] | {:error, any()}
def get_cluster_config(external_id, user) do
case Repo.all(ClusterTenants, cluster_alias: external_id) do
[%{cluster_alias: cluster_alias, active: true} | _] ->
Expand All @@ -161,9 +161,16 @@ defmodule Supavisor.Tenants do
)

Repo.all(query)
|> Enum.reduce_while([], fn cluster, acc ->
if cluster.tenant.require_user do
{:cont, [cluster | acc]}
else
{:halt, {:error, {:config, cluster.tenant.external_id}}}
end
end)

_ ->
nil
{:error, :not_found}
end
end

Expand Down

0 comments on commit 389e88c

Please sign in to comment.