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 9, 2024
1 parent 0129590 commit dec1b7d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 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
8 changes: 7 additions & 1 deletion apps/core/lib/core/services/cloud/poller.ex
Original file line number Diff line number Diff line change
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 dec1b7d

Please sign in to comment.