diff --git a/apps/core/lib/core/clients/console.ex b/apps/core/lib/core/clients/console.ex index 1d4f3a3c7..499bae395 100644 --- a/apps/core/lib/core/clients/console.ex +++ b/apps/core/lib/core/clients/console.ex @@ -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"} @@ -59,7 +60,7 @@ defmodule Core.Clients.Console do def repo(client, url) do Req.post(client, graphql: {@repo_q, %{url: url}}) |> case do - {:ok, %Req.Response{body: %{"gitRepository" => %{"id" => id}}}} -> {:ok, id} + {:ok, %Req.Response{body: %{"data" => %{"gitRepository" => %{"id" => id}}}}} -> {:ok, id} res -> Logger.warn "Failed to fetch clusters: #{inspect(res)}" {:error, "could not fetch repo"} @@ -81,7 +82,7 @@ defmodule Core.Clients.Console do |> service_resp("deleteServiceDeployment") end - defp service_resp({:ok, %Req.Response{status: 200, body: body}}, field) do + defp service_resp({:ok, %Req.Response{status: 200, body: %{"data" => body}}}, field) do case body[field] do %{"id" => id} -> {:ok, id} err -> diff --git a/apps/core/lib/core/schema/cockroach_cluster.ex b/apps/core/lib/core/schema/cockroach_cluster.ex index 0e92016a5..f4cff9294 100644 --- a/apps/core/lib/core/schema/cockroach_cluster.ex +++ b/apps/core/lib/core/schema/cockroach_cluster.ex @@ -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 diff --git a/apps/core/lib/core/services/cloud/configuration.ex b/apps/core/lib/core/services/cloud/configuration.ex index 74140670c..55b4827b2 100644 --- a/apps/core/lib/core/services/cloud/configuration.ex +++ b/apps/core/lib/core/services/cloud/configuration.ex @@ -23,7 +23,6 @@ defmodule Core.Services.Cloud.Configuration do postgres_certificate: certificate(inst) }) |> Map.put(:size, "#{size}") - |> Enum.map(fn {k, v} -> %{name: Macro.camelize("#{k}"), value: v} end) end defp certificate(%ConsoleInstance{cockroach: %CockroachCluster{certificate: cert}}), do: cert diff --git a/apps/core/lib/core/services/cloud/poller.ex b/apps/core/lib/core/services/cloud/poller.ex index 46c35fb5e..22275f835 100644 --- a/apps/core/lib/core/services/cloud/poller.ex +++ b/apps/core/lib/core/services/cloud/poller.ex @@ -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 @@ -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 @@ -70,6 +71,7 @@ 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 @@ -77,7 +79,8 @@ defmodule Core.Services.Cloud.Poller do |> 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 @@ -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 diff --git a/apps/core/test/services/cloud/workflow_test.exs b/apps/core/test/services/cloud/workflow_test.exs index 105717a88..ee35cbc9d 100644 --- a/apps/core/test/services/cloud/workflow_test.exs +++ b/apps/core/test/services/cloud/workflow_test.exs @@ -24,7 +24,9 @@ defmodule Core.Services.Cloud.WorkflowTest do }, user) expect(Core.Services.Cloud.Poller, :repository, fn -> {:ok, "some-id"} end) - expect(Core.Clients.Console, :create_service, fn _, ^cluster_id, _ -> {:ok, Ecto.UUID.generate()} end) + expect(Req, :post, fn _, [graphql: {_, %{clusterId: ^cluster_id}}] -> + {:ok, %Req.Response{status: 200, body: %{"data" => %{"createServiceDeployment" => %{"id" => Ecto.UUID.generate()}}}}} + end) {:ok, %{external_id: svc_id} = instance} = Workflow.provision(instance) @@ -32,7 +34,9 @@ defmodule Core.Services.Cloud.WorkflowTest do assert instance.instance_status.db assert instance.instance_status.svc - expect(Core.Clients.Console, :delete_service, fn _, ^svc_id -> {:ok, svc_id} end) + expect(Req, :post, fn _, [graphql: {_, %{id: ^svc_id}}] -> + {:ok, %Req.Response{status: 200, body: %{"data" => %{"deleteServiceDeployment" => %{"id" => svc_id}}}}} + end) {:ok, instance} = Workflow.deprovision(instance) diff --git a/apps/core/test/test_helper.exs b/apps/core/test/test_helper.exs index fa1d67468..da5d8b514 100644 --- a/apps/core/test/test_helper.exs +++ b/apps/core/test/test_helper.exs @@ -35,5 +35,6 @@ Mimic.copy(System) Mimic.copy(Core.Clients.Vault) Mimic.copy(Core.Clients.Console) Mimic.copy(Core.Services.Cloud.Poller) +Mimic.copy(Req) {:ok, _} = Application.ensure_all_started(:ex_machina)