Skip to content

Commit

Permalink
Need to b64 decode cockroach config secret
Browse files Browse the repository at this point in the history
forgot to add this as well
  • Loading branch information
michaeljguarino committed Aug 10, 2024
1 parent 0129590 commit ff10f37
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion apps/core/lib/core/clients/console.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ defmodule Core.Clients.Console do
def clusters(client) do
Req.post(client, graphql: @clusters_q)
|> case do
{:ok, %Req.Response{body: %{"clusters" => %{"edges" => edges}}}} -> {:ok, Enum.map(edges, & &1["node"])}
{:ok, %Req.Response{body: %{"data" => %{"clusters" => %{"edges" => edges}}}}} ->
{:ok, Enum.map(edges, & &1["node"])}
res ->
Logger.warn "Failed to fetch clusters: #{inspect(res)}"
{:error, "could not fetch clusters"}
Expand Down
2 changes: 1 addition & 1 deletion apps/core/lib/core/schema/cockroach_cluster.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ defmodule Core.Schema.CockroachCluster do
model
|> cast(attrs, ~w(name cloud region url certificate endpoints)a)
|> unique_constraint(:name)
|> validate_required(~w(name cloud region url certificate endpoints)a)
|> validate_required(~w(name cloud url certificate endpoints)a)
end
end
12 changes: 9 additions & 3 deletions apps/core/lib/core/services/cloud/poller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ defmodule Core.Services.Cloud.Poller do

def repository(), do: GenServer.call(__MODULE__, :repo)

def handle_call(:repo, %{repo: id} = state) when is_binary(id),
def handle_call(:repo, _, %{repo: id} = state) when is_binary(id),
do: {:reply, {:ok, id}, state}
def handle_call(:repo, state), do: {:reply, {:error, "repo not pulled"}, state}
def handle_call(:repo, _, state), do: {:reply, {:error, "repo not pulled"}, state}

def handle_info(:repo, %{client: client} = state) do
case Console.repo(client, Core.conf(:mgmt_repo)) do
Expand Down Expand Up @@ -61,6 +61,7 @@ defmodule Core.Services.Cloud.Poller do
cloud: to_cloud(distro),
region: meta["region"]
}, name)
|> log_err("failed to insert cloud cluster")
end

defp upsert_roach(%{"name" => name} = roach) do
Expand All @@ -70,14 +71,16 @@ defmodule Core.Services.Cloud.Poller do
certificate: roach["certificate"],
endpoints: roach["endpoints"]
}, name)
|> log_err("failed to insert cockroach cluster")
end

defp read_secret() do
CoreV1.read_namespaced_secret!("plural", "plrl-cloud-config")
|> Kazan.run()
|> case do
{:ok, %CoreV1.Secret{data: %{"cockroaches" => roaches}}} ->
Jason.decode(roaches)
Base.decode64!(roaches)
|> Jason.decode()
_ -> {:error, "could not find secret"}
end
end
Expand All @@ -86,4 +89,7 @@ defmodule Core.Services.Cloud.Poller do
defp to_cloud("GKE"), do: :gcp
defp to_cloud("AKS"), do: :azure
defp to_cloud(_), do: :aws

defp log_err({:error, _} = err, msg), do: "#{msg}: #{inspect(err)}"
defp log_err(pass, _), do: pass
end

0 comments on commit ff10f37

Please sign in to comment.