Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select checks openapi #546

Merged
merged 4 commits into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 26 additions & 6 deletions lib/trento_web/controllers/cluster_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@ defmodule TrentoWeb.ClusterController do

alias Trento.{Clusters, Hosts}

alias Trento.Integration.Checks
alias Trento.Integration.Checks, as: ChecksIntegration
nelsonkopliku marked this conversation as resolved.
Show resolved Hide resolved

use OpenApiSpex.ControllerSpecs
alias TrentoWeb.OpenApi.Schema.{Checks, Cluster, Common}

tags ["Landscape"]
use OpenApiSpex.ControllerSpecs

operation :list,
summary: "List Pacemaker Clusters",
tags: ["Landscape"],
description: "List all the discovered Pacemaker Clusters on the target infrastructure",
responses: [
ok:
{"A collection of the discovered Pacemaker Clusters", "application/json",
TrentoWeb.OpenApi.Schema.Cluster.PacemakerClustersCollection}
Cluster.PacemakerClustersCollection}
]

@spec list(Plug.Conn.t(), map) :: Plug.Conn.t()
Expand Down Expand Up @@ -44,7 +45,7 @@ defmodule TrentoWeb.ClusterController do
operation :runner_callback, false
@spec runner_callback(Plug.Conn.t(), map) :: Plug.Conn.t()
def runner_callback(conn, params) do
case Checks.handle_callback(params) do
case ChecksIntegration.handle_callback(params) do
:ok ->
conn
|> put_status(:accepted)
Expand All @@ -57,7 +58,26 @@ defmodule TrentoWeb.ClusterController do
end
end

operation :select_checks, false
operation :select_checks,
summary: "Select Checks",
tags: ["Checks"],
description: "Select the Checks eligible for execution on the target infrastructure",
parameters: [
selected_checks: [
in: :body,
required: true,
type: Checks.CheckSelectionRequest
]
],
responses: [
accepted:
{"The Selection has been successfully collected", "application/json",
%OpenApiSpex.Schema{example: %{}}},
bad_request:
{"Something went wrong with the collection of the Checks Selection", "application/json",
Common.BadRequestResponse}
]

@spec select_checks(Plug.Conn.t(), map) :: Plug.Conn.t()
def select_checks(conn, %{"cluster_id" => cluster_id, "checks" => checks}) do
case Clusters.select_checks(cluster_id, checks) do
Expand Down
17 changes: 17 additions & 0 deletions lib/trento_web/openapi/schema/checks.ex
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,21 @@ defmodule TrentoWeb.OpenApi.Schema.Checks do
}
})
end

defmodule CheckSelectionRequest do
nelsonkopliku marked this conversation as resolved.
Show resolved Hide resolved
@moduledoc false

OpenApiSpex.schema(%{
title: "CheckSelectionRequest",
description:
"A list of desired checks that should be executed on the target infrastructure",
type: :object,
properties: %{
checks: %Schema{
type: :array,
items: %Schema{type: :string}
}
}
})
end
end
20 changes: 20 additions & 0 deletions lib/trento_web/openapi/schema/common.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
defmodule TrentoWeb.OpenApi.Schema.Common do
@moduledoc false

require OpenApiSpex
alias OpenApiSpex.Schema

defmodule BadRequestResponse do
@moduledoc false

OpenApiSpex.schema(%{
title: "BadRequestResponse",
description: "Something wrong happened while executing requested operation",
type: :object,
properties: %{
error: %Schema{type: :string, description: "The error message"}
},
example: %{error: "some error message"}
})
end
end