From 5665e2915905aad42b09c2e9317030a0e7e08a3d Mon Sep 17 00:00:00 2001 From: Fabrizio Sestito Date: Thu, 31 Mar 2022 10:36:26 +0200 Subject: [PATCH] Cleanup unusued api endpoint and fix callback payload --- .../integration/checks/adapter/mock_runner.ex | 6 ++-- .../application/integration/checks/checks.ex | 4 ++- .../controllers/cluster_controller.ex | 34 ------------------- lib/trento_web/router.ex | 6 ++-- 4 files changed, 9 insertions(+), 41 deletions(-) diff --git a/lib/trento/application/integration/checks/adapter/mock_runner.ex b/lib/trento/application/integration/checks/adapter/mock_runner.ex index 222b5384b2..b8b11de3d8 100644 --- a/lib/trento/application/integration/checks/adapter/mock_runner.ex +++ b/lib/trento/application/integration/checks/adapter/mock_runner.ex @@ -90,8 +90,10 @@ defmodule Trento.Integration.Checks.MockRunner do "http://localhost:4000/api/runner/callback", Jason.encode!(%{ "event" => "execution_started", - "cluster_id" => cluster_id, - "execution_id" => execution_id + "execution_id" => execution_id, + "payload" => %{ + "cluster_id" => cluster_id + } }), [{"Content-type", "application/json"}] ) diff --git a/lib/trento/application/integration/checks/checks.ex b/lib/trento/application/integration/checks/checks.ex index 3650213320..8339702595 100644 --- a/lib/trento/application/integration/checks/checks.ex +++ b/lib/trento/application/integration/checks/checks.ex @@ -47,7 +47,9 @@ defmodule Trento.Integration.Checks do def handle_callback(%{ "event" => "execution_started", "execution_id" => execution_id, - "cluster_id" => cluster_id + "payload" => %{ + "cluster_id" => cluster_id + } }) do case StartChecksExecution.new(%{cluster_id: cluster_id}) do {:ok, command} -> diff --git a/lib/trento_web/controllers/cluster_controller.ex b/lib/trento_web/controllers/cluster_controller.ex index 30a24ec442..f6e502eda8 100644 --- a/lib/trento_web/controllers/cluster_controller.ex +++ b/lib/trento_web/controllers/cluster_controller.ex @@ -47,40 +47,6 @@ defmodule TrentoWeb.ClusterController do end end - @spec store_checks_results(Plug.Conn.t(), map) :: Plug.Conn.t() - def store_checks_results( - conn, - %{"cluster_id" => cluster_id, "hosts" => hosts, "checks" => checks} - ) do - [host_id] = Map.keys(hosts) - - checks_results = - Enum.map( - checks, - fn {check_id, %{"hosts" => %{^host_id => %{"result" => result}}}} -> - %{ - check_id: check_id, - result: String.to_atom(result) - } - end - ) - |> Enum.reject(fn %{result: result} -> - result == :skipped - end) - - case Clusters.store_checks_results(cluster_id, host_id, checks_results) do - :ok -> - conn - |> put_status(:accepted) - |> json(%{}) - - {:error, reason} -> - conn - |> put_status(:bad_request) - |> json(%{error: reason}) - end - end - @spec request_checks_execution(Plug.Conn.t(), map) :: Plug.Conn.t() def request_checks_execution(conn, %{"cluster_id" => cluster_id}) do case Clusters.request_checks_execution(cluster_id) do diff --git a/lib/trento_web/router.ex b/lib/trento_web/router.ex index 0c1f3dc49b..f0fbc31abe 100644 --- a/lib/trento_web/router.ex +++ b/lib/trento_web/router.ex @@ -52,17 +52,15 @@ defmodule TrentoWeb.Router do delete "/sap_systems/:id/tags/:value", SapSystemController, :delete_tag get "/databases", SapSystemController, :list_databases - # TODO: this url is weird because the ansible callback expect so - # let's maybe change it in the future when we will change the agent as well - post "/checks/:cluster_id/results", ClusterController, :store_checks_results post "/clusters/:cluster_id/checks", ClusterController, :select_checks - post "/runner/callback", ClusterController, :runner_callback + post "/clusters/:cluster_id/checks/request_execution", ClusterController, :request_checks_execution + post "/runner/callback", ClusterController, :runner_callback get "/checks/catalog", CatalogController, :checks_catalog end