From 32ff8c629d2c492e3ecb598060e52a1b4942162a Mon Sep 17 00:00:00 2001 From: Carmine Di Monaco Date: Tue, 16 Jul 2024 11:21:59 +0200 Subject: [PATCH] Open api spex object refactor (#2780) * Add struct?: false to all openapispex schemas * Refactored controllers according to the new openapispex * Bump openapispex to 3.19.1 * fix e2e tests --- lib/trento/activity_log.ex | 29 +- .../controllers/v1/cluster_controller.ex | 4 +- .../controllers/v1/discovery_controller.ex | 12 +- .../controllers/v1/host_controller.ex | 4 +- .../controllers/v1/profile_controller.ex | 8 +- .../controllers/v1/settings_controller.ex | 27 +- .../v1/suma_credentials_controller.ex | 15 +- .../controllers/v1/tags_controller.ex | 2 +- lib/trento_web/openapi/v1/schema/ability.ex | 56 +- .../openapi/v1/schema/activity_log.ex | 67 +-- .../v1/schema/available_software_updates.ex | 458 +++++++++------- .../openapi/v1/schema/bad_request.ex | 37 +- lib/trento_web/openapi/v1/schema/chart.ex | 117 ++-- lib/trento_web/openapi/v1/schema/checks.ex | 28 +- .../openapi/v1/schema/checks_catalog.ex | 315 ++++++----- lib/trento_web/openapi/v1/schema/cluster.ex | 277 +++++----- lib/trento_web/openapi/v1/schema/database.ex | 168 +++--- .../openapi/v1/schema/discovery_event.ex | 31 +- lib/trento_web/openapi/v1/schema/forbidden.ex | 37 +- lib/trento_web/openapi/v1/schema/health.ex | 31 +- lib/trento_web/openapi/v1/schema/host.ex | 180 +++--- lib/trento_web/openapi/v1/schema/http_std.ex | 96 ++-- lib/trento_web/openapi/v1/schema/not_found.ex | 31 +- lib/trento_web/openapi/v1/schema/platform.ex | 218 ++++---- .../openapi/v1/schema/precondition_failed.ex | 39 +- .../v1/schema/precondition_required.ex | 37 +- .../openapi/v1/schema/prometheus.ex | 27 +- lib/trento_web/openapi/v1/schema/provider.ex | 154 +++--- lib/trento_web/openapi/v1/schema/ready.ex | 29 +- .../openapi/v1/schema/resource_health.ex | 17 +- .../openapi/v1/schema/sap_system.ex | 255 +++++---- .../openapi/v1/schema/saptune_status.ex | 221 ++++---- .../openapi/v1/schema/sles_subscription.ex | 37 +- .../openapi/v1/schema/suma_credentials.ex | 86 +-- lib/trento_web/openapi/v1/schema/tag.ex | 46 +- .../openapi/v1/schema/unauthorized.ex | 37 +- .../openapi/v1/schema/unprocessable_entity.ex | 35 +- lib/trento_web/openapi/v1/schema/user.ex | 447 ++++++++------- lib/trento_web/openapi/v2/schema/cluster.ex | 516 ++++++++++-------- mix.exs | 2 +- mix.lock | 8 +- test/e2e/cypress/e2e/users.cy.js | 2 +- test/trento/activity_log_test.exs | 2 +- .../v1/suse_manager_controller_test.exs | 33 +- 44 files changed, 2300 insertions(+), 1978 deletions(-) diff --git a/lib/trento/activity_log.ex b/lib/trento/activity_log.ex index 89bf4a16f2..ccd42102f0 100644 --- a/lib/trento/activity_log.ex +++ b/lib/trento/activity_log.ex @@ -13,29 +13,32 @@ defmodule Trento.ActivityLog do alias Trento.Repo @spec get_settings() :: - {:ok, Settings.t()} | {:error, :activity_log_settings_not_configured} + {:ok, Settings.t()} | {:error, :not_found} def get_settings do case Repo.one(Settings.base_query()) do %Settings{} = settings -> {:ok, settings} - nil -> {:error, :activity_log_settings_not_configured} + nil -> {:error, :not_found} end end @spec change_retention_period(integer(), RetentionPeriodUnit.t()) :: {:ok, Settings.t()} | {:error, :activity_log_settings_not_configured} - | {:error, any()} def change_retention_period(value, unit) do - with {:ok, settings} <- get_settings() do - settings - |> Settings.changeset(%{ - retention_time: %{ - value: value, - unit: unit - } - }) - |> Repo.update() - |> log_error("Error while updating activity log retention period") + case get_settings() do + {:ok, settings} -> + settings + |> Settings.changeset(%{ + retention_time: %{ + value: value, + unit: unit + } + }) + |> Repo.update() + |> log_error("Error while updating activity log retention period") + + {:error, :not_found} -> + {:error, :activity_log_settings_not_configured} end end diff --git a/lib/trento_web/controllers/v1/cluster_controller.ex b/lib/trento_web/controllers/v1/cluster_controller.ex index 4674e3d55b..9c1cb91ea5 100644 --- a/lib/trento_web/controllers/v1/cluster_controller.ex +++ b/lib/trento_web/controllers/v1/cluster_controller.ex @@ -79,8 +79,8 @@ defmodule TrentoWeb.V1.ClusterController do unprocessable_entity: OpenApiSpex.JsonErrorResponse.response() ] - def select_checks(%{body_params: body_params} = conn, %{cluster_id: cluster_id}) do - %{checks: checks} = body_params + def select_checks(conn, %{cluster_id: cluster_id}) do + %{checks: checks} = OpenApiSpex.body_params(conn) with :ok <- Clusters.select_checks(cluster_id, checks) do conn diff --git a/lib/trento_web/controllers/v1/discovery_controller.ex b/lib/trento_web/controllers/v1/discovery_controller.ex index 625b68bf9e..60cb30817d 100644 --- a/lib/trento_web/controllers/v1/discovery_controller.ex +++ b/lib/trento_web/controllers/v1/discovery_controller.ex @@ -24,12 +24,16 @@ defmodule TrentoWeb.V1.DiscoveryController do conn, _ ) do - body_params = Map.get(conn, :body_params) + %{ + agent_id: agent_id, + discovery_type: discovery_type, + payload: payload + } = OpenApiSpex.body_params(conn) event = %{ - "agent_id" => body_params.agent_id, - "discovery_type" => body_params.discovery_type, - "payload" => body_params.payload + "agent_id" => agent_id, + "discovery_type" => discovery_type, + "payload" => payload } with :ok <- Discovery.handle(event) do diff --git a/lib/trento_web/controllers/v1/host_controller.ex b/lib/trento_web/controllers/v1/host_controller.ex index 2934c068aa..7ec5198c66 100644 --- a/lib/trento_web/controllers/v1/host_controller.ex +++ b/lib/trento_web/controllers/v1/host_controller.ex @@ -109,8 +109,8 @@ defmodule TrentoWeb.V1.HostController do unprocessable_entity: OpenApiSpex.JsonErrorResponse.response() ] - def select_checks(%{body_params: body_params} = conn, %{id: host_id}) do - %{checks: checks} = body_params + def select_checks(conn, %{id: host_id}) do + %{checks: checks} = OpenApiSpex.body_params(conn) with :ok <- Hosts.select_checks(host_id, checks) do conn diff --git a/lib/trento_web/controllers/v1/profile_controller.ex b/lib/trento_web/controllers/v1/profile_controller.ex index fcf7347013..2fc63ff9e4 100644 --- a/lib/trento_web/controllers/v1/profile_controller.ex +++ b/lib/trento_web/controllers/v1/profile_controller.ex @@ -34,8 +34,9 @@ defmodule TrentoWeb.V1.ProfileController do forbidden: Schema.Forbidden.response() ] - def update(%{body_params: profile_params} = conn, _) do + def update(conn, _) do %User{} = user = Pow.Plug.current_user(conn) + profile_params = OpenApiSpex.body_params(conn) with {:ok, %User{} = updated_user} <- Users.update_user_profile(user, profile_params) do render(conn, "profile.json", user: updated_user) @@ -90,9 +91,10 @@ defmodule TrentoWeb.V1.ProfileController do forbidden: Schema.Forbidden.response() ] - def confirm_totp_enrollment(%{body_params: body_params} = conn, _) do + def confirm_totp_enrollment(conn, _) do %User{} = user = Pow.Plug.current_user(conn) - totp_code = Map.get(body_params, :totp_code) + + %{totp_code: totp_code} = OpenApiSpex.body_params(conn) with {:ok, %User{totp_enabled_at: totp_enabled_at}} <- Users.confirm_totp_enrollment(user, totp_code) do diff --git a/lib/trento_web/controllers/v1/settings_controller.ex b/lib/trento_web/controllers/v1/settings_controller.ex index 24935cb6fe..df698dcc19 100644 --- a/lib/trento_web/controllers/v1/settings_controller.ex +++ b/lib/trento_web/controllers/v1/settings_controller.ex @@ -87,8 +87,8 @@ defmodule TrentoWeb.V1.SettingsController do not_found: Schema.NotFound.response() ] - def update_api_key_settings(%{body_params: body_params} = conn, _) do - %{expire_at: expire_at} = body_params + def update_api_key_settings(conn, _) do + %{expire_at: expire_at} = OpenApiSpex.body_params(conn) with {:ok, updated_settings} <- Settings.update_api_key_settings(expire_at) do api_key = @@ -116,9 +116,12 @@ defmodule TrentoWeb.V1.SettingsController do unprocessable_entity: Schema.UnprocessableEntity.response() ] - def update_activity_log_settings(%{body_params: body_params} = conn, _) do + def update_activity_log_settings( + conn, + _ + ) do %{retention_time: %{value: retention_period, unit: retention_period_unit}} = - body_params + OpenApiSpex.body_params(conn) with {:ok, updated_settings} <- ActivityLog.change_retention_period(retention_period, retention_period_unit) do @@ -139,18 +142,10 @@ defmodule TrentoWeb.V1.SettingsController do ] def get_activity_log_settings(conn, _) do - case ActivityLog.get_settings() do - {:ok, settings} -> - render(conn, "activity_log_settings.json", %{ - activity_log_settings: settings - }) - - _ -> - # Here we rebind the error returned by the ActivityLog.get_settings/0 function - # to a "not_found" in order to disambiguate from a similar error being returned by the - # ActivityLog.change_retention_period/2 function. This error gets picked up by the FallbackController - # and leads to dispatching to the appropriate error response. - {:error, :not_found} + with {:ok, settings} <- ActivityLog.get_settings() do + render(conn, "activity_log_settings.json", %{ + activity_log_settings: settings + }) end end diff --git a/lib/trento_web/controllers/v1/suma_credentials_controller.ex b/lib/trento_web/controllers/v1/suma_credentials_controller.ex index 8e2f50033e..6ee4fc0187 100644 --- a/lib/trento_web/controllers/v1/suma_credentials_controller.ex +++ b/lib/trento_web/controllers/v1/suma_credentials_controller.ex @@ -49,10 +49,10 @@ defmodule TrentoWeb.V1.SUMACredentialsController do ] @spec create(Plug.Conn.t(), any) :: Plug.Conn.t() - def create(%{body_params: body_params} = conn, _) do - attrs = decode_body(body_params) + def create(conn, _) do + settings_params = OpenApiSpex.body_params(conn) - with {:ok, saved_settings} <- SoftwareUpdates.save_settings(attrs) do + with {:ok, saved_settings} <- SoftwareUpdates.save_settings(settings_params) do conn |> put_status(:created) |> render("suma_credentials.json", %{settings: saved_settings}) @@ -72,10 +72,10 @@ defmodule TrentoWeb.V1.SUMACredentialsController do ] @spec update(Plug.Conn.t(), any) :: Plug.Conn.t() - def update(%{body_params: body_params} = conn, _) do - attrs = decode_body(body_params) + def update(conn, _) do + update_settings_paylod = OpenApiSpex.body_params(conn) - with {:ok, saved_settings} <- SoftwareUpdates.change_settings(attrs) do + with {:ok, saved_settings} <- SoftwareUpdates.change_settings(update_settings_paylod) do conn |> put_status(:ok) |> render("suma_credentials.json", %{settings: saved_settings}) @@ -116,7 +116,4 @@ defmodule TrentoWeb.V1.SUMACredentialsController do end def get_policy_resource(_), do: Trento.SoftwareUpdates.Settings - - defp decode_body(body) when is_struct(body), do: Map.from_struct(body) - defp decode_body(body), do: body end diff --git a/lib/trento_web/controllers/v1/tags_controller.ex b/lib/trento_web/controllers/v1/tags_controller.ex index 2374f2938b..f070aac24f 100644 --- a/lib/trento_web/controllers/v1/tags_controller.ex +++ b/lib/trento_web/controllers/v1/tags_controller.ex @@ -52,7 +52,7 @@ defmodule TrentoWeb.V1.TagsController do } = conn, %{id: id} ) do - %{value: value} = Map.get(conn, :body_params) + %{value: value} = OpenApiSpex.body_params(conn) with {:ok, %Tag{value: value}} <- Tags.add_tag(value, id, resource_type) do conn diff --git a/lib/trento_web/openapi/v1/schema/ability.ex b/lib/trento_web/openapi/v1/schema/ability.ex index 2545e1399f..2aca752c7c 100644 --- a/lib/trento_web/openapi/v1/schema/ability.ex +++ b/lib/trento_web/openapi/v1/schema/ability.ex @@ -7,37 +7,43 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Ability do defmodule AbilityItem do @moduledoc false - OpenApiSpex.schema(%{ - title: "Ability", - description: "Ability entry", - type: :object, - additionalProperties: false, - properties: %{ - id: %Schema{type: :integer, description: "Ability ID", nullable: false}, - name: %Schema{type: :string, description: "Ability name", nullable: false}, - resource: %Schema{ - type: :string, - description: "Resource attached to ability", - nullable: false + OpenApiSpex.schema( + %{ + title: "Ability", + description: "Ability entry", + type: :object, + additionalProperties: false, + properties: %{ + id: %Schema{type: :integer, description: "Ability ID", nullable: false}, + name: %Schema{type: :string, description: "Ability name", nullable: false}, + resource: %Schema{ + type: :string, + description: "Resource attached to ability", + nullable: false + }, + label: %Schema{ + type: :string, + description: "Description of the ability", + nullable: false + } }, - label: %Schema{ - type: :string, - description: "Description of the ability", - nullable: false - } + required: [:id, :name, :resource] }, - required: [:id, :name, :resource] - }) + struct?: false + ) end defmodule AbilityCollection do @moduledoc false - OpenApiSpex.schema(%{ - title: "AbilityCollection", - description: "A collection of abilities in the system", - type: :array, - items: AbilityItem - }) + OpenApiSpex.schema( + %{ + title: "AbilityCollection", + description: "A collection of abilities in the system", + type: :array, + items: AbilityItem + }, + struct?: false + ) end end diff --git a/lib/trento_web/openapi/v1/schema/activity_log.ex b/lib/trento_web/openapi/v1/schema/activity_log.ex index 69357033ac..aff8d989ff 100644 --- a/lib/trento_web/openapi/v1/schema/activity_log.ex +++ b/lib/trento_web/openapi/v1/schema/activity_log.ex @@ -4,37 +4,40 @@ defmodule TrentoWeb.OpenApi.V1.Schema.ActivityLog do require OpenApiSpex alias OpenApiSpex.Schema - OpenApiSpex.schema(%{ - title: "ActivityLog", - description: "Activity Log for the current installation.", - type: :array, - items: %Schema{ - title: "ActivityLogEntry", - type: :object, - additionalProperties: false, - properties: %{ - id: %Schema{ - type: :string, - description: "Identifier of Activity Log entry.", - format: :uuid + OpenApiSpex.schema( + %{ + title: "ActivityLog", + description: "Activity Log for the current installation.", + type: :array, + items: %Schema{ + title: "ActivityLogEntry", + type: :object, + additionalProperties: false, + properties: %{ + id: %Schema{ + type: :string, + description: "Identifier of Activity Log entry.", + format: :uuid + }, + type: %Schema{ + type: :string, + description: "Type of Activity Log entry." + }, + actor: %Schema{ + type: :string, + description: "Actor causing an Activity Log entry. E.g. System or a specific user." + }, + metadata: %Schema{ + type: :object + }, + occurred_on: %Schema{ + type: :string, + description: "Timestamp upon Activity Log entry insertion." + } }, - type: %Schema{ - type: :string, - description: "Type of Activity Log entry." - }, - actor: %Schema{ - type: :string, - description: "Actor causing an Activity Log entry. E.g. System or a specific user." - }, - metadata: %Schema{ - type: :object - }, - occurred_on: %Schema{ - type: :string, - description: "Timestamp upon Activity Log entry insertion." - } - }, - required: [:id, :type, :actor, :metadata, :occurred_on] - } - }) + required: [:id, :type, :actor, :metadata, :occurred_on] + } + }, + struct?: false + ) end diff --git a/lib/trento_web/openapi/v1/schema/available_software_updates.ex b/lib/trento_web/openapi/v1/schema/available_software_updates.ex index 0fb84c6b87..fc63c2397d 100644 --- a/lib/trento_web/openapi/v1/schema/available_software_updates.ex +++ b/lib/trento_web/openapi/v1/schema/available_software_updates.ex @@ -6,269 +6,303 @@ defmodule TrentoWeb.OpenApi.V1.Schema.AvailableSoftwareUpdates do defmodule UpgradablePackage do @moduledoc false - OpenApiSpex.schema(%{ - title: "UpgradablePackage", - description: "Upgradable package", - type: :object, - additionalProperties: false, - properties: %{ - arch: %Schema{type: :string, description: "Package name"}, - from_epoch: %Schema{type: :string, description: "From epoch"}, - from_release: %Schema{type: :string, description: "From which release"}, - from_version: %Schema{type: :string, description: "From version"}, - name: %Schema{type: :string, description: "Upgradable package name"}, - to_epoch: %Schema{type: :string, description: "To epoch"}, - to_package_id: %Schema{type: :string, description: "To package id"}, - to_release: %Schema{type: :string, description: "To release"}, - to_version: %Schema{type: :string, description: "To version"} - } - }) + OpenApiSpex.schema( + %{ + title: "UpgradablePackage", + description: "Upgradable package", + type: :object, + additionalProperties: false, + properties: %{ + arch: %Schema{type: :string, description: "Package name"}, + from_epoch: %Schema{type: :string, description: "From epoch"}, + from_release: %Schema{type: :string, description: "From which release"}, + from_version: %Schema{type: :string, description: "From version"}, + name: %Schema{type: :string, description: "Upgradable package name"}, + to_epoch: %Schema{type: :string, description: "To epoch"}, + to_package_id: %Schema{type: :string, description: "To package id"}, + to_release: %Schema{type: :string, description: "To release"}, + to_version: %Schema{type: :string, description: "To version"} + } + }, + struct?: false + ) end defmodule RelevantPatch do @moduledoc false - OpenApiSpex.schema(%{ - title: "RelevantPatch", - description: "Relevant patch", - type: :object, - additionalProperties: false, - properties: %{ - id: %Schema{type: :integer, description: "Advisory's id"}, - advisory_name: %Schema{type: :string, description: "Advisory name"}, - advisory_status: %Schema{type: :string, description: "Advisory status"}, - advisory_synopsis: %Schema{type: :string, description: "Advisory's synopsis"}, - advisory_type: %Schema{ - type: :string, - description: "Advisory's type", - enum: [:security_advisory, :bugfix, :enhancement] - }, - date: %Schema{type: :string, description: "Advisory's date"}, - update_date: %Schema{type: :string, description: "Advisory's update date"} - } - }) + OpenApiSpex.schema( + %{ + title: "RelevantPatch", + description: "Relevant patch", + type: :object, + additionalProperties: false, + properties: %{ + id: %Schema{type: :integer, description: "Advisory's id"}, + advisory_name: %Schema{type: :string, description: "Advisory name"}, + advisory_status: %Schema{type: :string, description: "Advisory status"}, + advisory_synopsis: %Schema{type: :string, description: "Advisory's synopsis"}, + advisory_type: %Schema{ + type: :string, + description: "Advisory's type", + enum: [:security_advisory, :bugfix, :enhancement] + }, + date: %Schema{type: :string, description: "Advisory's date"}, + update_date: %Schema{type: :string, description: "Advisory's update date"} + } + }, + struct?: false + ) end defmodule PatchesForPackage do @moduledoc false - OpenApiSpex.schema(%{ - title: "PatchesForPackage", - description: "Relevant patches covered by a package upgrade", - type: :object, - additionalProperties: false, - properties: %{ - package_id: %Schema{type: :string, description: ""}, - patches: %Schema{ - type: :array, - additionalProperties: false, - items: %Schema{ - title: "PatchForPackage", - description: "A list of relevant patches that the upgrade covers", + OpenApiSpex.schema( + %{ + title: "PatchesForPackage", + description: "Relevant patches covered by a package upgrade", + type: :object, + additionalProperties: false, + properties: %{ + package_id: %Schema{type: :string, description: ""}, + patches: %Schema{ + type: :array, additionalProperties: false, - properties: %{ - advisory_type: %Schema{type: :string, description: "Advisory type"}, - advisory: %Schema{type: :string, description: "Advisory name for the patch"}, - synopsis: %Schema{type: :string, description: "Advisory synopsis for the patch"}, - issue_date: %Schema{type: :string, description: "Advisory issue date"}, - last_modified_date: %Schema{ - type: :string, - description: "Advisory last modified date" + items: %Schema{ + title: "PatchForPackage", + description: "A list of relevant patches that the upgrade covers", + additionalProperties: false, + properties: %{ + advisory_type: %Schema{type: :string, description: "Advisory type"}, + advisory: %Schema{type: :string, description: "Advisory name for the patch"}, + synopsis: %Schema{type: :string, description: "Advisory synopsis for the patch"}, + issue_date: %Schema{type: :string, description: "Advisory issue date"}, + last_modified_date: %Schema{ + type: :string, + description: "Advisory last modified date" + } } } } } - } - }) + }, + struct?: false + ) end defmodule AvailableSoftwareUpdatesResponse do @moduledoc false - OpenApiSpex.schema(%{ - title: "AvailableSoftwareUpdatesResponse", - description: "Response returned from the available software updates endpoint", - type: :object, - additionalProperties: false, - properties: %{ - relevant_patches: %Schema{ - title: "RelevantPatches", - description: "A list relevant patches for the host", - type: :array, - items: RelevantPatch - }, - upgradable_packages: %Schema{ - title: "UpgradablePackages", - description: "A list of upgradable packages for the host", - type: :array, - items: UpgradablePackage + OpenApiSpex.schema( + %{ + title: "AvailableSoftwareUpdatesResponse", + description: "Response returned from the available software updates endpoint", + type: :object, + additionalProperties: false, + properties: %{ + relevant_patches: %Schema{ + title: "RelevantPatches", + description: "A list relevant patches for the host", + type: :array, + items: RelevantPatch + }, + upgradable_packages: %Schema{ + title: "UpgradablePackages", + description: "A list of upgradable packages for the host", + type: :array, + items: UpgradablePackage + } } - } - }) + }, + struct?: false + ) end defmodule PatchesForPackagesResponse do @moduledoc false - OpenApiSpex.schema(%{ - title: "PatchesForPackagesResponse", - description: "Response returned from the patches for packages endpoint", - type: :object, - additionalProperties: false, - properties: %{ - patches: %Schema{ - title: "PatchesForPackages", - description: "A list of the relevant patches covered by the provided package upgrades", - type: :array, - items: PatchesForPackage + OpenApiSpex.schema( + %{ + title: "PatchesForPackagesResponse", + description: "Response returned from the patches for packages endpoint", + type: :object, + additionalProperties: false, + properties: %{ + patches: %Schema{ + title: "PatchesForPackages", + description: + "A list of the relevant patches covered by the provided package upgrades", + type: :array, + items: PatchesForPackage + } } - } - }) + }, + struct?: false + ) end defmodule ErrataDetails do @moduledoc false - OpenApiSpex.schema(%{ - title: "ErrataDetails", - description: "Details for the erratum matching the given advisory name", - type: :object, - additionalProperties: false, - properties: %{ - id: %Schema{type: :number, format: :int, description: "Advisory ID number"}, - issue_date: %Schema{ - type: :string, - format: "date", - description: "Advisory issue date" - }, - update_date: %Schema{ - type: :string, - format: "date", - description: "Advisory update date" - }, - last_modified_date: %Schema{ - type: :string, - format: "date", - description: "Advisory last modified date" - }, - synopsis: %Schema{type: :string, description: "Advisory synopsis"}, - release: %Schema{type: :number, format: :int, description: "Advisory Release number"}, - advisory_status: %Schema{type: :string, description: "Advisory status"}, - vendor_advisory: %Schema{type: :string, description: "Vendor advisory"}, - type: %Schema{type: :string, description: "Advisory type"}, - product: %Schema{type: :string, description: "Advisory product"}, - errata_from: %Schema{type: :string, description: "Advisory errata"}, - topic: %Schema{type: :string, description: "Advisory topic"}, - description: %Schema{type: :string, description: "Advisory description"}, - references: %Schema{type: :string, description: "Advisory references"}, - notes: %Schema{type: :string, description: "Advisory notes"}, - solution: %Schema{type: :string, description: "Advisory solution"}, - reboot_suggested: %Schema{ - type: :boolean, - description: - "A boolean flag signaling whether a system reboot is advisable following the application of the errata. Typical example is upon kernel update." - }, - restart_suggested: %Schema{ - type: :boolean, - description: - "A boolean flag signaling a weather reboot of the package manager is advisable following the application of the errata. This is commonly used to address update stack issues before proceeding with other updates." + OpenApiSpex.schema( + %{ + title: "ErrataDetails", + description: "Details for the erratum matching the given advisory name", + type: :object, + additionalProperties: false, + properties: %{ + id: %Schema{type: :number, format: :int, description: "Advisory ID number"}, + issue_date: %Schema{ + type: :string, + format: "date", + description: "Advisory issue date" + }, + update_date: %Schema{ + type: :string, + format: "date", + description: "Advisory update date" + }, + last_modified_date: %Schema{ + type: :string, + format: "date", + description: "Advisory last modified date" + }, + synopsis: %Schema{type: :string, description: "Advisory synopsis"}, + release: %Schema{type: :number, format: :int, description: "Advisory Release number"}, + advisory_status: %Schema{type: :string, description: "Advisory status"}, + vendor_advisory: %Schema{type: :string, description: "Vendor advisory"}, + type: %Schema{type: :string, description: "Advisory type"}, + product: %Schema{type: :string, description: "Advisory product"}, + errata_from: %Schema{type: :string, description: "Advisory errata"}, + topic: %Schema{type: :string, description: "Advisory topic"}, + description: %Schema{type: :string, description: "Advisory description"}, + references: %Schema{type: :string, description: "Advisory references"}, + notes: %Schema{type: :string, description: "Advisory notes"}, + solution: %Schema{type: :string, description: "Advisory solution"}, + reboot_suggested: %Schema{ + type: :boolean, + description: + "A boolean flag signaling whether a system reboot is advisable following the application of the errata. Typical example is upon kernel update." + }, + restart_suggested: %Schema{ + type: :boolean, + description: + "A boolean flag signaling a weather reboot of the package manager is advisable following the application of the errata. This is commonly used to address update stack issues before proceeding with other updates." + } } - } - }) + }, + struct?: false + ) end defmodule CVEs do @moduledoc false - OpenApiSpex.schema(%{ - title: "CVEs", - description: "List of CVEs applicable to the errata with the given advisory name.", - type: :array, - additionalProperties: false, - items: %Schema{ - title: "CVE", - description: "A fix for a publicly known security vulnerability", - type: :string - } - }) + OpenApiSpex.schema( + %{ + title: "CVEs", + description: "List of CVEs applicable to the errata with the given advisory name.", + type: :array, + additionalProperties: false, + items: %Schema{ + title: "CVE", + description: "A fix for a publicly known security vulnerability", + type: :string + } + }, + struct?: false + ) end defmodule AdvisoryFixes do @moduledoc false - OpenApiSpex.schema(%{ - title: "AdvisoryFixes", - description: "Response returned from the get advisory fixes endpoint", - type: :object, - additionalProperties: %Schema{type: :string} - }) + OpenApiSpex.schema( + %{ + title: "AdvisoryFixes", + description: "Response returned from the get advisory fixes endpoint", + type: :object, + additionalProperties: %Schema{type: :string} + }, + struct?: false + ) end defmodule AffectedPackages do @moduledoc false - OpenApiSpex.schema(%{ - title: "AffectedPackages", - description: "Response returned from the get affected packages endpoint", - type: :array, - additionalProperties: false, - items: %Schema{ - title: "AffectedPackage", - description: "Metadata for a package effected by an advisory", - type: :object, - properties: %{ - name: %Schema{ - type: :string, - description: "Package name" - }, - arch_label: %Schema{ - type: :string, - description: "Package architecture" - }, - version: %Schema{ - type: :string, - description: "Package upstream version" - }, - release: %Schema{ - type: :string, - description: "Package RPM release number" - }, - epoch: %Schema{ - type: :string, - description: "Package epoch number" + OpenApiSpex.schema( + %{ + title: "AffectedPackages", + description: "Response returned from the get affected packages endpoint", + type: :array, + additionalProperties: false, + items: %Schema{ + title: "AffectedPackage", + description: "Metadata for a package effected by an advisory", + type: :object, + properties: %{ + name: %Schema{ + type: :string, + description: "Package name" + }, + arch_label: %Schema{ + type: :string, + description: "Package architecture" + }, + version: %Schema{ + type: :string, + description: "Package upstream version" + }, + release: %Schema{ + type: :string, + description: "Package RPM release number" + }, + epoch: %Schema{ + type: :string, + description: "Package epoch number" + } } } - } - }) + }, + struct?: false + ) end defmodule AffectedSystems do @moduledoc false - OpenApiSpex.schema(%{ - title: "AffectedSystems", - description: "Response returned from the get affected systems endpoint", - type: :array, - additionalProperties: false, - items: %Schema{ - title: "AffectedSystem", - description: "Metadata for a system effected by an advisory", - type: :object, - properties: %{ - name: %Schema{ - type: :string, - description: "System name" + OpenApiSpex.schema( + %{ + title: "AffectedSystems", + description: "Response returned from the get affected systems endpoint", + type: :array, + additionalProperties: false, + items: %Schema{ + title: "AffectedSystem", + description: "Metadata for a system effected by an advisory", + type: :object, + properties: %{ + name: %Schema{ + type: :string, + description: "System name" + } } } - } - }) + }, + struct?: false + ) end defmodule ErrataDetailsResponse do @moduledoc false - OpenApiSpex.schema(%{ - title: "ErrataDetailsResponse", - description: "Response returned from the errata details endpoint", - type: :object, - additionalProperties: false, - properties: %{ - errata_details: ErrataDetails, - cves: CVEs, - fixes: AdvisoryFixes, - affected_packages: AffectedPackages, - affected_systems: AffectedSystems - } - }) + OpenApiSpex.schema( + %{ + title: "ErrataDetailsResponse", + description: "Response returned from the errata details endpoint", + type: :object, + additionalProperties: false, + properties: %{ + errata_details: ErrataDetails, + cves: CVEs, + fixes: AdvisoryFixes, + affected_packages: AffectedPackages, + affected_systems: AffectedSystems + } + }, + struct?: false + ) end end diff --git a/lib/trento_web/openapi/v1/schema/bad_request.ex b/lib/trento_web/openapi/v1/schema/bad_request.ex index cc42b36eda..d90675464a 100644 --- a/lib/trento_web/openapi/v1/schema/bad_request.ex +++ b/lib/trento_web/openapi/v1/schema/bad_request.ex @@ -8,26 +8,29 @@ defmodule TrentoWeb.OpenApi.V1.Schema.BadRequest do alias OpenApiSpex.Operation alias OpenApiSpex.Schema - OpenApiSpex.schema(%{ - title: "BadRequest", - type: :object, - additionalProperties: false, - properties: %{ - errors: %Schema{ - type: :array, - items: %Schema{ - type: :object, - properties: %{ - detail: %Schema{ - type: :string, - example: "Invalid request payload." - }, - title: %Schema{type: :string, example: "Bad Request"} + OpenApiSpex.schema( + %{ + title: "BadRequest", + type: :object, + additionalProperties: false, + properties: %{ + errors: %Schema{ + type: :array, + items: %Schema{ + type: :object, + properties: %{ + detail: %Schema{ + type: :string, + example: "Invalid request payload." + }, + title: %Schema{type: :string, example: "Bad Request"} + } } } } - } - }) + }, + struct?: false + ) def response do Operation.response( diff --git a/lib/trento_web/openapi/v1/schema/chart.ex b/lib/trento_web/openapi/v1/schema/chart.ex index 7313dbb47d..13d54e839d 100644 --- a/lib/trento_web/openapi/v1/schema/chart.ex +++ b/lib/trento_web/openapi/v1/schema/chart.ex @@ -6,73 +6,82 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Chart do defmodule ChartTimeSeries do @moduledoc false - OpenApiSpex.schema(%{ - title: "ChartTimeSeries", - description: - "A Time Series for a chart, has a series of float values distributed through time", - type: :object, - additionalProperties: false, - properties: %{ - label: %Schema{type: :string, description: "The name of series"}, - series: %Schema{ - type: :array, - description: "The values of the series", - items: %Schema{ - type: :object, - description: "A timestamp/value pair", - properties: %{ - timestamp: %Schema{ - type: :string, - format: "date-time", - description: "ISO8601 timestamp" - }, - value: %Schema{ - type: :number, - example: 270_396.2030, - format: :float, - description: "Float value" + OpenApiSpex.schema( + %{ + title: "ChartTimeSeries", + description: + "A Time Series for a chart, has a series of float values distributed through time", + type: :object, + additionalProperties: false, + properties: %{ + label: %Schema{type: :string, description: "The name of series"}, + series: %Schema{ + type: :array, + description: "The values of the series", + items: %Schema{ + type: :object, + description: "A timestamp/value pair", + properties: %{ + timestamp: %Schema{ + type: :string, + format: "date-time", + description: "ISO8601 timestamp" + }, + value: %Schema{ + type: :number, + example: 270_396.2030, + format: :float, + description: "Float value" + } } } } } - } - }) + }, + struct?: false + ) end defmodule HostCpuChart do @moduledoc false - OpenApiSpex.schema(%{ - title: "HostCpuChart", - additionalProperties: false, - description: "A Time Series chart with information about the cpu usage of a host", - type: :object, - properties: %{ - busy_iowait: ChartTimeSeries, - busy_irqs: ChartTimeSeries, - busy_other: ChartTimeSeries, - busy_system: ChartTimeSeries, - busy_user: ChartTimeSeries, - idle: ChartTimeSeries - } - }) + OpenApiSpex.schema( + %{ + title: "HostCpuChart", + additionalProperties: false, + description: "A Time Series chart with information about the cpu usage of a host", + type: :object, + properties: %{ + busy_iowait: ChartTimeSeries, + busy_irqs: ChartTimeSeries, + busy_other: ChartTimeSeries, + busy_system: ChartTimeSeries, + busy_user: ChartTimeSeries, + idle: ChartTimeSeries + } + }, + struct?: false + ) end defmodule HostMemoryChart do @moduledoc false - OpenApiSpex.schema(%{ - title: "HostMemoryChart", - description: "A Time series chart with information about the memory usage of a host", - type: :object, - additionalProperties: false, - properties: %{ - ram_total: ChartTimeSeries, - ram_cache_and_buffer: ChartTimeSeries, - ram_free: ChartTimeSeries, - ram_used: ChartTimeSeries, - swap_used: ChartTimeSeries - } - }) + OpenApiSpex.schema( + %{ + title: "HostMemoryChart", + description: "A Time series chart with information about the memory usage of a host", + type: :object, + additionalProperties: false, + properties: %{ + ram_total: ChartTimeSeries, + ram_cache_and_buffer: ChartTimeSeries, + ram_free: ChartTimeSeries, + ram_used: ChartTimeSeries, + swap_used: ChartTimeSeries + } + }, + struct?: false + ) end end diff --git a/lib/trento_web/openapi/v1/schema/checks.ex b/lib/trento_web/openapi/v1/schema/checks.ex index b2a23ea88a..9564e28372 100644 --- a/lib/trento_web/openapi/v1/schema/checks.ex +++ b/lib/trento_web/openapi/v1/schema/checks.ex @@ -3,17 +3,21 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Checks.ChecksSelectionRequest do require OpenApiSpex alias OpenApiSpex.Schema - OpenApiSpex.schema(%{ - title: "ChecksSelectionRequest", - description: "A list of desired checks that should be executed on the target infrastructure", - additionalProperties: false, - type: :object, - properties: %{ - checks: %Schema{ - type: :array, - items: %Schema{type: :string} - } + OpenApiSpex.schema( + %{ + title: "ChecksSelectionRequest", + description: + "A list of desired checks that should be executed on the target infrastructure", + additionalProperties: false, + type: :object, + properties: %{ + checks: %Schema{ + type: :array, + items: %Schema{type: :string} + } + }, + required: [:checks] }, - required: [:checks] - }) + struct?: false + ) end diff --git a/lib/trento_web/openapi/v1/schema/checks_catalog.ex b/lib/trento_web/openapi/v1/schema/checks_catalog.ex index a10bfc2c27..d9a26c620c 100644 --- a/lib/trento_web/openapi/v1/schema/checks_catalog.ex +++ b/lib/trento_web/openapi/v1/schema/checks_catalog.ex @@ -9,188 +9,213 @@ defmodule TrentoWeb.OpenApi.V1.Schema.ChecksCatalog do defmodule Check do @moduledoc false - OpenApiSpex.schema(%{ - title: "Check", - description: "An available check to be executed on the target infrastructure", - type: :object, - additionalProperties: false, - properties: %{ - id: %Schema{type: :string, description: "Check ID", format: :uuid}, - name: %Schema{type: :string, description: "Check Name"}, - description: %Schema{type: :string, description: "Check Description"}, - remediation: %Schema{type: :string, description: "Check Remediation"}, - implementation: %Schema{type: :string, description: "Check Implementation"}, - labels: %Schema{type: :string, description: "Check Labels"}, - premium: %Schema{ - type: :boolean, - description: "Indicates whether the current check is a Premium check" - }, - group: %Schema{ - type: :string, - description: "Check Group, available when requiring a Flat Catalog" - }, - provider: Provider.SupportedProviders - } - }) + OpenApiSpex.schema( + %{ + title: "Check", + description: "An available check to be executed on the target infrastructure", + type: :object, + additionalProperties: false, + properties: %{ + id: %Schema{type: :string, description: "Check ID", format: :uuid}, + name: %Schema{type: :string, description: "Check Name"}, + description: %Schema{type: :string, description: "Check Description"}, + remediation: %Schema{type: :string, description: "Check Remediation"}, + implementation: %Schema{type: :string, description: "Check Implementation"}, + labels: %Schema{type: :string, description: "Check Labels"}, + premium: %Schema{ + type: :boolean, + description: "Indicates whether the current check is a Premium check" + }, + group: %Schema{ + type: :string, + description: "Check Group, available when requiring a Flat Catalog" + }, + provider: Provider.SupportedProviders + } + }, + struct?: false + ) end defmodule FlatCatalog do @moduledoc false - OpenApiSpex.schema(%{ - title: "FlatCatalog", - description: "A flat list of the available Checks", - type: :array, - items: Check - }) + OpenApiSpex.schema( + %{ + title: "FlatCatalog", + description: "A flat list of the available Checks", + type: :array, + items: Check + }, + struct?: false + ) end defmodule ChecksGroup do @moduledoc false - OpenApiSpex.schema(%{ - title: "ChecksGroup", - description: "A Group of related Checks (Corosync, Pacemaker ...)", - additionalProperties: false, - type: :object, - properties: %{ - group: %Schema{type: :string, description: "Group Name"}, - checks: FlatCatalog - } - }) + OpenApiSpex.schema( + %{ + title: "ChecksGroup", + description: "A Group of related Checks (Corosync, Pacemaker ...)", + additionalProperties: false, + type: :object, + properties: %{ + group: %Schema{type: :string, description: "Group Name"}, + checks: FlatCatalog + } + }, + struct?: false + ) end defmodule ProviderCatalog do @moduledoc false - OpenApiSpex.schema(%{ - title: "ProviderCatalog", - description: "A Provider specific Catalog, and respective values", - additionalProperties: false, - type: :object, - properties: %{ - provider: %Schema{ - title: "ChecksProvider", - type: :string, - description: - "The provider determining the values for the attached checks (azure, aws ...)", - enum: [:azure, :aws, :gcp, :default] - }, - groups: %Schema{ - title: "ChecksGroups", - description: "A list of ChecksGroup for the respective provider", - type: :array, - items: ChecksGroup + OpenApiSpex.schema( + %{ + title: "ProviderCatalog", + description: "A Provider specific Catalog, and respective values", + additionalProperties: false, + type: :object, + properties: %{ + provider: %Schema{ + title: "ChecksProvider", + type: :string, + description: + "The provider determining the values for the attached checks (azure, aws ...)", + enum: [:azure, :aws, :gcp, :default] + }, + groups: %Schema{ + title: "ChecksGroups", + description: "A list of ChecksGroup for the respective provider", + type: :array, + items: ChecksGroup + } } - } - }) + }, + struct?: false + ) end defmodule GroupedCatalog do @moduledoc false - OpenApiSpex.schema(%{ - title: "GroupedCatalog", - description: - "A list of available Checks: grouped by provider (azure, aws ...) and checks groups (Corosync, Pacemaker ...)", - type: :array, - items: ProviderCatalog - }) + OpenApiSpex.schema( + %{ + title: "GroupedCatalog", + description: + "A list of available Checks: grouped by provider (azure, aws ...) and checks groups (Corosync, Pacemaker ...)", + type: :array, + items: ProviderCatalog + }, + struct?: false + ) end defmodule Catalog do @moduledoc false - OpenApiSpex.schema(%{ - title: "ChecksCatalog", - description: "A representation of the Checks Catalog", - oneOf: [ - GroupedCatalog, - FlatCatalog - ], - example: [ - %{ - groups: [ - %{ - checks: [ - %{ - description: "Corosync `token` timeout is set to `5000`\n", - id: "156F64", - implementation: - "---\n\n- name: \"{{ name }}.check\"\n lineinfile:\n path: /etc/corosync/corosync.conf\n regexp: '^(\\s+){{ key_name }}:'\n line: \"\\t{{ key_name }}: {{ expected[name] }}\"\n insertafter: 'totem {'\n register: config_updated\n when:\n - ansible_check_mode\n\n- block:\n - name: Post results\n import_role:\n name: post-results\n when:\n - ansible_check_mode\n vars:\n status: \"{{ config_updated is not changed }}\"", - labels: "generic", - name: "1.1.1", - premium: false, - remediation: - "## Abstract\nThe value of the Corosync `token` timeout is not set as recommended.\n\n## Remediation\n\nAdjust the corosync `token` timeout as recommended on the best practices, and reload the corosync configuration\n\n1. Set the correct `token` timeout in the totem session in the corosync config file `/etc/corosync/corosync.conf`. This action must be repeated in all nodes of the cluster.\n ```\n [...]\n totem { \n token: \n }\n [...]\n ``` \n2. Reload the corosync configuration:\n `crm corosync reload`\n\n## References\n- https://docs.microsoft.com/en-us/azure/virtual-machines/workloads/sap/high-availability-guide-suse-pacemaker\n" - }, - %{ - description: "Corosync is running with `token` timeout set to `5000`\n", - id: "53D035", - implementation: - "---\n\n- name: \"{{ name }}.check\"\n shell: 'corosync-cmapctl | grep \"runtime.config.totem.token (u32) = \" | sed \"s/^.*= //\"'\n check_mode: false\n register: config_updated\n changed_when: config_updated.stdout != expected['1.1.1']\n\n- block:\n - name: Post results\n import_role:\n name: post-results\n when:\n - ansible_check_mode\n vars:\n status: \"{{ config_updated is not changed }}\"", - labels: "generic", - name: "1.1.1.runtime", - premium: false, - remediation: - "## Abstract\nThe runtime value of the Corosync `token` timeout is not set as recommended.\n\n## Remediation\n\nAdjust the corosync `token` timeout as recommended on the best practices, and reload the corosync configuration\n\n\n1. Set the correct `token` timeout in the totem session in the corosync config file `/etc/corosync/corosync.conf`. This action must be repeated in all nodes of the cluster.\n ```\n [...]\n totem { \n token: \n }\n [...]\n ``` \n2. Reload the corosync configuration:\n `crm corosync reload`\n\n## References\n- https://docs.microsoft.com/en-us/azure/virtual-machines/workloads/sap/high-availability-guide-suse-pacemaker\n" - } - ], - group: "Corosync" - }, - %{ - checks: [ - %{ - description: "Fencing is enabled in the cluster attributes\n", - id: "205AF7", - implementation: - "---\n\n- name: \"{{ name }}.check\"\n command: 'crm_attribute -t crm_config -G -n stonith-enabled --quiet'\n check_mode: false\n register: config_updated\n changed_when: config_updated.stdout != expected[name]\n\n- block:\n - name: Post results\n import_role:\n name: post-results\n when:\n - ansible_check_mode\n vars:\n status: \"{{ config_updated is not changed }}\"", - labels: "generic", - name: "1.2.1", - premium: false, - remediation: - "## Abstract\nFencing is mandatory to guarantee data integrity for your SAP Applications.\nRunning a HA Cluster without fencing is not supported and might cause data loss.\n\n## Remediation\nExecute the following command to enable it:\n```\ncrm configure property stonith-enabled=true\n```\n\n## References\n- https://documentation.suse.com/sle-ha/15-SP3/html/SLE-HA-all/cha-ha-fencing.html#sec-ha-fencing-recommend\n" - } - ], - group: "Pacemaker" - } - ], - provider: "aws" - } - ] - }) + OpenApiSpex.schema( + %{ + title: "ChecksCatalog", + description: "A representation of the Checks Catalog", + oneOf: [ + GroupedCatalog, + FlatCatalog + ], + example: [ + %{ + groups: [ + %{ + checks: [ + %{ + description: "Corosync `token` timeout is set to `5000`\n", + id: "156F64", + implementation: + "---\n\n- name: \"{{ name }}.check\"\n lineinfile:\n path: /etc/corosync/corosync.conf\n regexp: '^(\\s+){{ key_name }}:'\n line: \"\\t{{ key_name }}: {{ expected[name] }}\"\n insertafter: 'totem {'\n register: config_updated\n when:\n - ansible_check_mode\n\n- block:\n - name: Post results\n import_role:\n name: post-results\n when:\n - ansible_check_mode\n vars:\n status: \"{{ config_updated is not changed }}\"", + labels: "generic", + name: "1.1.1", + premium: false, + remediation: + "## Abstract\nThe value of the Corosync `token` timeout is not set as recommended.\n\n## Remediation\n\nAdjust the corosync `token` timeout as recommended on the best practices, and reload the corosync configuration\n\n1. Set the correct `token` timeout in the totem session in the corosync config file `/etc/corosync/corosync.conf`. This action must be repeated in all nodes of the cluster.\n ```\n [...]\n totem { \n token: \n }\n [...]\n ``` \n2. Reload the corosync configuration:\n `crm corosync reload`\n\n## References\n- https://docs.microsoft.com/en-us/azure/virtual-machines/workloads/sap/high-availability-guide-suse-pacemaker\n" + }, + %{ + description: "Corosync is running with `token` timeout set to `5000`\n", + id: "53D035", + implementation: + "---\n\n- name: \"{{ name }}.check\"\n shell: 'corosync-cmapctl | grep \"runtime.config.totem.token (u32) = \" | sed \"s/^.*= //\"'\n check_mode: false\n register: config_updated\n changed_when: config_updated.stdout != expected['1.1.1']\n\n- block:\n - name: Post results\n import_role:\n name: post-results\n when:\n - ansible_check_mode\n vars:\n status: \"{{ config_updated is not changed }}\"", + labels: "generic", + name: "1.1.1.runtime", + premium: false, + remediation: + "## Abstract\nThe runtime value of the Corosync `token` timeout is not set as recommended.\n\n## Remediation\n\nAdjust the corosync `token` timeout as recommended on the best practices, and reload the corosync configuration\n\n\n1. Set the correct `token` timeout in the totem session in the corosync config file `/etc/corosync/corosync.conf`. This action must be repeated in all nodes of the cluster.\n ```\n [...]\n totem { \n token: \n }\n [...]\n ``` \n2. Reload the corosync configuration:\n `crm corosync reload`\n\n## References\n- https://docs.microsoft.com/en-us/azure/virtual-machines/workloads/sap/high-availability-guide-suse-pacemaker\n" + } + ], + group: "Corosync" + }, + %{ + checks: [ + %{ + description: "Fencing is enabled in the cluster attributes\n", + id: "205AF7", + implementation: + "---\n\n- name: \"{{ name }}.check\"\n command: 'crm_attribute -t crm_config -G -n stonith-enabled --quiet'\n check_mode: false\n register: config_updated\n changed_when: config_updated.stdout != expected[name]\n\n- block:\n - name: Post results\n import_role:\n name: post-results\n when:\n - ansible_check_mode\n vars:\n status: \"{{ config_updated is not changed }}\"", + labels: "generic", + name: "1.2.1", + premium: false, + remediation: + "## Abstract\nFencing is mandatory to guarantee data integrity for your SAP Applications.\nRunning a HA Cluster without fencing is not supported and might cause data loss.\n\n## Remediation\nExecute the following command to enable it:\n```\ncrm configure property stonith-enabled=true\n```\n\n## References\n- https://documentation.suse.com/sle-ha/15-SP3/html/SLE-HA-all/cha-ha-fencing.html#sec-ha-fencing-recommend\n" + } + ], + group: "Pacemaker" + } + ], + provider: "aws" + } + ] + }, + struct?: false + ) end defmodule CatalogNotfound do @moduledoc false - OpenApiSpex.schema(%{ - title: "CatalogNotfound", - description: "No Catalog was found for the provided query", - additionalProperties: false, - type: :object, - properties: %{ - error: %Schema{ - type: :string, - enum: [:not_found] - } + OpenApiSpex.schema( + %{ + title: "CatalogNotfound", + description: "No Catalog was found for the provided query", + additionalProperties: false, + type: :object, + properties: %{ + error: %Schema{ + type: :string, + enum: [:not_found] + } + }, + example: %{error: "not_found"} }, - example: %{error: "not_found"} - }) + struct?: false + ) end defmodule UnableToLoadCatalog do @moduledoc false - OpenApiSpex.schema(%{ - title: "UnableToLoadCatalog", - description: "Something wrong happened while loading the catalog. ie: it is not ready yet", - additionalProperties: false, - type: :object, - properties: %{ - error: %Schema{type: :string, description: "The error message"} + OpenApiSpex.schema( + %{ + title: "UnableToLoadCatalog", + description: + "Something wrong happened while loading the catalog. ie: it is not ready yet", + additionalProperties: false, + type: :object, + properties: %{ + error: %Schema{type: :string, description: "The error message"} + }, + example: %{error: "(not_ready|some other error message)"} }, - example: %{error: "(not_ready|some other error message)"} - }) + struct?: false + ) end end diff --git a/lib/trento_web/openapi/v1/schema/cluster.ex b/lib/trento_web/openapi/v1/schema/cluster.ex index 9d13f5ef23..9729deb260 100644 --- a/lib/trento_web/openapi/v1/schema/cluster.ex +++ b/lib/trento_web/openapi/v1/schema/cluster.ex @@ -10,164 +10,189 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Cluster do defmodule ClusterResource do @moduledoc false - OpenApiSpex.schema(%{ - title: "ClusterResource", - description: "A Cluster Resource", - type: :object, - additionalProperties: false, - properties: %{ - id: %Schema{type: :string}, - type: %Schema{type: :string}, - role: %Schema{type: :string}, - status: %Schema{type: :string}, - fail_count: %Schema{type: :integer} - } - }) + OpenApiSpex.schema( + %{ + title: "ClusterResource", + description: "A Cluster Resource", + type: :object, + additionalProperties: false, + properties: %{ + id: %Schema{type: :string}, + type: %Schema{type: :string}, + role: %Schema{type: :string}, + status: %Schema{type: :string}, + fail_count: %Schema{type: :integer} + } + }, + struct?: false + ) end defmodule HanaClusterNode do @moduledoc false - OpenApiSpex.schema(%{ - title: "HanaClusterNode", - description: "A HANA Cluster Node", - additionalProperties: false, - type: :object, - properties: %{ - name: %Schema{type: :string}, - site: %Schema{type: :string}, - hana_status: %Schema{type: :string}, - attributes: %Schema{ - type: :object, - description: "Node attributes", - additionalProperties: %Schema{type: :string} - }, - virtual_ip: %Schema{type: :string}, - resources: %Schema{ - description: "A list of Cluster resources", - type: :array, - items: ClusterResource + OpenApiSpex.schema( + %{ + title: "HanaClusterNode", + description: "A HANA Cluster Node", + additionalProperties: false, + type: :object, + properties: %{ + name: %Schema{type: :string}, + site: %Schema{type: :string}, + hana_status: %Schema{type: :string}, + attributes: %Schema{ + type: :object, + description: "Node attributes", + additionalProperties: %Schema{type: :string} + }, + virtual_ip: %Schema{type: :string}, + resources: %Schema{ + description: "A list of Cluster resources", + type: :array, + items: ClusterResource + } } - } - }) + }, + struct?: false + ) end defmodule SbdDevice do @moduledoc false - OpenApiSpex.schema(%{ - title: "SbdDevice", - description: "SBD Device", - additionalProperties: false, - type: :object, - properties: %{ - device: %Schema{type: :string}, - status: %Schema{type: :string} - } - }) + OpenApiSpex.schema( + %{ + title: "SbdDevice", + description: "SBD Device", + additionalProperties: false, + type: :object, + properties: %{ + device: %Schema{type: :string}, + status: %Schema{type: :string} + } + }, + struct?: false + ) end defmodule HanaClusterDetails do @moduledoc false - OpenApiSpex.schema(%{ - title: "HanaClusterDetails", - description: "Details of a HANA Pacemaker Cluster", - type: :object, - additionalProperties: false, - properties: %{ - system_replication_mode: %Schema{type: :string, description: "System Replication Mode"}, - system_replication_operation_mode: %Schema{ - type: :string, - description: "System Replication Operation Mode" - }, - secondary_sync_state: %Schema{type: :string, description: "Secondary Sync State"}, - sr_health_state: %Schema{type: :string, description: "SR health state"}, - fencing_type: %Schema{type: :string, description: "Fencing Type"}, - stopped_resources: %Schema{ - description: "A list of the stopped resources on this HANA Cluster", - type: :array, - items: ClusterResource + OpenApiSpex.schema( + %{ + title: "HanaClusterDetails", + description: "Details of a HANA Pacemaker Cluster", + type: :object, + additionalProperties: false, + properties: %{ + system_replication_mode: %Schema{type: :string, description: "System Replication Mode"}, + system_replication_operation_mode: %Schema{ + type: :string, + description: "System Replication Operation Mode" + }, + secondary_sync_state: %Schema{type: :string, description: "Secondary Sync State"}, + sr_health_state: %Schema{type: :string, description: "SR health state"}, + fencing_type: %Schema{type: :string, description: "Fencing Type"}, + stopped_resources: %Schema{ + description: "A list of the stopped resources on this HANA Cluster", + type: :array, + items: ClusterResource + }, + nodes: %Schema{ + type: :array, + items: HanaClusterNode + }, + sbd_devices: %Schema{ + type: :array, + items: SbdDevice + } }, - nodes: %Schema{ - type: :array, - items: HanaClusterNode - }, - sbd_devices: %Schema{ - type: :array, - items: SbdDevice - } + required: [:nodes] }, - required: [:nodes] - }) + struct?: false + ) end defmodule Details do @moduledoc false - OpenApiSpex.schema(%{ - title: "PacemakerClusterDetails", - description: "Details of the detected PacemakerCluster", - nullable: true, - oneOf: [ - HanaClusterDetails - ] - }) + OpenApiSpex.schema( + %{ + title: "PacemakerClusterDetails", + description: "Details of the detected PacemakerCluster", + nullable: true, + oneOf: [ + HanaClusterDetails + ] + }, + struct?: false + ) end defmodule PacemakerCluster do @moduledoc false - OpenApiSpex.schema(%{ - title: "PacemakerCluster", - description: "A discovered Pacemaker Cluster on the target infrastructure", - type: :object, - additionalProperties: false, - properties: %{ - id: %Schema{type: :string, description: "Cluster ID", format: :uuid}, - name: %Schema{type: :string, description: "Cluster name"}, - sid: %Schema{type: :string, description: "SID"}, - additional_sids: %Schema{ - type: :array, - items: %Schema{type: :string}, - description: "Additionally discovered SIDs, such as ASCS/ERS cluster SIDs" - }, - provider: Provider.SupportedProviders, - type: %Schema{ - type: :string, - description: "Detected type of the cluster", - enum: [:hana_scale_up, :hana_scale_out, :unknown] - }, - selected_checks: %Schema{ - title: "SelectedChecks", - description: "A list of check ids selected for an execution on this cluster", - type: :array, - items: %Schema{type: :string} - }, - health: ResourceHealth, - resources_number: %Schema{type: :integer, description: "Resource number", nullable: true}, - hosts_number: %Schema{type: :integer, description: "Hosts number", nullable: true}, - cib_last_written: %Schema{ - type: :string, - description: "CIB last written date", - nullable: true - }, - details: Details, - tags: Tags, - inserted_at: %Schema{type: :string, format: :datetime}, - updated_at: %Schema{type: :string, format: :datetime, nullable: true} - } - }) + OpenApiSpex.schema( + %{ + title: "PacemakerCluster", + description: "A discovered Pacemaker Cluster on the target infrastructure", + type: :object, + additionalProperties: false, + properties: %{ + id: %Schema{type: :string, description: "Cluster ID", format: :uuid}, + name: %Schema{type: :string, description: "Cluster name"}, + sid: %Schema{type: :string, description: "SID"}, + additional_sids: %Schema{ + type: :array, + items: %Schema{type: :string}, + description: "Additionally discovered SIDs, such as ASCS/ERS cluster SIDs" + }, + provider: Provider.SupportedProviders, + type: %Schema{ + type: :string, + description: "Detected type of the cluster", + enum: [:hana_scale_up, :hana_scale_out, :unknown] + }, + selected_checks: %Schema{ + title: "SelectedChecks", + description: "A list of check ids selected for an execution on this cluster", + type: :array, + items: %Schema{type: :string} + }, + health: ResourceHealth, + resources_number: %Schema{ + type: :integer, + description: "Resource number", + nullable: true + }, + hosts_number: %Schema{type: :integer, description: "Hosts number", nullable: true}, + cib_last_written: %Schema{ + type: :string, + description: "CIB last written date", + nullable: true + }, + details: Details, + tags: Tags, + inserted_at: %Schema{type: :string, format: :datetime}, + updated_at: %Schema{type: :string, format: :datetime, nullable: true} + } + }, + struct?: false + ) end defmodule PacemakerClustersCollection do @moduledoc false - OpenApiSpex.schema(%{ - title: "PacemakerClustersCollection", - description: "A list of the discovered Pacemaker Clusters", - type: :array, - items: PacemakerCluster - }) + OpenApiSpex.schema( + %{ + title: "PacemakerClustersCollection", + description: "A list of the discovered Pacemaker Clusters", + type: :array, + items: PacemakerCluster + }, + struct?: false + ) end end diff --git a/lib/trento_web/openapi/v1/schema/database.ex b/lib/trento_web/openapi/v1/schema/database.ex index b2123f2c02..1afd68ac53 100644 --- a/lib/trento_web/openapi/v1/schema/database.ex +++ b/lib/trento_web/openapi/v1/schema/database.ex @@ -9,98 +9,110 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Database do defmodule DatabaseInstance do @moduledoc false - OpenApiSpex.schema(%{ - title: "DatabaseInstance", - description: "A discovered HANA Database Instance on the target infrastructure", - type: :object, - additionalProperties: false, - properties: %{ - sap_system_id: %Schema{ - type: :string, - description: "SAP System ID", - format: :uuid, - deprecated: true - }, - database_id: %Schema{type: :string, description: "Database ID", format: :uuid}, - sid: %Schema{type: :string, description: "SID"}, - tenant: %Schema{type: :string, description: "Tenant"}, - instance_number: %Schema{type: :string, description: "Instance Number"}, - instance_hostname: %Schema{ - type: :string, - description: "Instance Hostname", - nullable: true - }, - features: %Schema{type: :string, description: "Instance Features"}, - http_port: %Schema{type: :integer, description: "Instance HTTP Port", nullable: true}, - https_port: %Schema{type: :integer, description: "Instance HTTPS Port", nullable: true}, - start_priority: %Schema{ - type: :string, - description: "Instance Start Priority", - nullable: true - }, - host_id: %Schema{ - type: :string, - description: "Identifier of the host where current instance is running", - format: :uuid - }, - system_replication: %Schema{type: :string, description: "System Replication"}, - system_replication_status: %Schema{ - type: :string, - description: "System Replication Status" - }, - health: ResourceHealth, - absent_at: %Schema{ - type: :string, - description: "Absent instance timestamp", - format: :datetime, - nullable: true - }, - inserted_at: %Schema{type: :string, format: :datetime}, - updated_at: %Schema{type: :string, format: :datetime, nullable: true} - } - }) + OpenApiSpex.schema( + %{ + title: "DatabaseInstance", + description: "A discovered HANA Database Instance on the target infrastructure", + type: :object, + additionalProperties: false, + properties: %{ + sap_system_id: %Schema{ + type: :string, + description: "SAP System ID", + format: :uuid, + deprecated: true + }, + database_id: %Schema{type: :string, description: "Database ID", format: :uuid}, + sid: %Schema{type: :string, description: "SID"}, + tenant: %Schema{type: :string, description: "Tenant"}, + instance_number: %Schema{type: :string, description: "Instance Number"}, + instance_hostname: %Schema{ + type: :string, + description: "Instance Hostname", + nullable: true + }, + features: %Schema{type: :string, description: "Instance Features"}, + http_port: %Schema{type: :integer, description: "Instance HTTP Port", nullable: true}, + https_port: %Schema{type: :integer, description: "Instance HTTPS Port", nullable: true}, + start_priority: %Schema{ + type: :string, + description: "Instance Start Priority", + nullable: true + }, + host_id: %Schema{ + type: :string, + description: "Identifier of the host where current instance is running", + format: :uuid + }, + system_replication: %Schema{type: :string, description: "System Replication"}, + system_replication_status: %Schema{ + type: :string, + description: "System Replication Status" + }, + health: ResourceHealth, + absent_at: %Schema{ + type: :string, + description: "Absent instance timestamp", + format: :datetime, + nullable: true + }, + inserted_at: %Schema{type: :string, format: :datetime}, + updated_at: %Schema{type: :string, format: :datetime, nullable: true} + } + }, + struct?: false + ) end defmodule DatabaseInstances do @moduledoc false - OpenApiSpex.schema(%{ - title: "DatabaseInstances", - description: - "A list of DatabaseInstances, part of a complete SAP System, or only a HANA Database", - type: :array, - items: DatabaseInstance - }) + OpenApiSpex.schema( + %{ + title: "DatabaseInstances", + description: + "A list of DatabaseInstances, part of a complete SAP System, or only a HANA Database", + type: :array, + items: DatabaseInstance + }, + struct?: false + ) end defmodule DatabaseItem do @moduledoc false - OpenApiSpex.schema(%{ - title: "Database", - description: "A discovered HANA Database on the target infrastructure", - type: :object, - additionalProperties: false, - properties: %{ - id: %Schema{type: :string, description: "Database ID", format: :uuid}, - sid: %Schema{type: :string, description: "SID"}, - health: ResourceHealth, - database_instances: DatabaseInstances, - tags: Tags, - inserted_at: %Schema{type: :string, format: :datetime}, - updated_at: %Schema{type: :string, format: :datetime, nullable: true} - } - }) + OpenApiSpex.schema( + %{ + title: "Database", + description: "A discovered HANA Database on the target infrastructure", + type: :object, + additionalProperties: false, + properties: %{ + id: %Schema{type: :string, description: "Database ID", format: :uuid}, + sid: %Schema{type: :string, description: "SID"}, + health: ResourceHealth, + database_instances: DatabaseInstances, + tags: Tags, + inserted_at: %Schema{type: :string, format: :datetime}, + updated_at: %Schema{type: :string, format: :datetime, nullable: true} + } + }, + struct?: false + ) end defmodule DatabasesCollection do @moduledoc false - OpenApiSpex.schema(%{ - title: "DatabasesCollection", - description: "A list of the discovered HANA Databases", - type: :array, - items: DatabaseItem - }) + OpenApiSpex.schema( + %{ + title: "DatabasesCollection", + description: "A list of the discovered HANA Databases", + type: :array, + items: DatabaseItem + }, + struct?: false + ) end end diff --git a/lib/trento_web/openapi/v1/schema/discovery_event.ex b/lib/trento_web/openapi/v1/schema/discovery_event.ex index ea1365a4b1..56135d4b2f 100644 --- a/lib/trento_web/openapi/v1/schema/discovery_event.ex +++ b/lib/trento_web/openapi/v1/schema/discovery_event.ex @@ -5,19 +5,22 @@ defmodule TrentoWeb.OpenApi.V1.Schema.DiscoveryEvent do require OpenApiSpex - OpenApiSpex.schema(%{ - title: "DiscoveryEvent", - description: "A discovery event", - type: :object, - additionalProperties: false, - properties: %{ - agent_id: %Schema{type: :string, format: :uuid}, - discovery_type: %Schema{type: :string}, - payload: %Schema{ - nullable: true, - oneOf: [%Schema{type: :object}, %Schema{type: :array}] - } + OpenApiSpex.schema( + %{ + title: "DiscoveryEvent", + description: "A discovery event", + type: :object, + additionalProperties: false, + properties: %{ + agent_id: %Schema{type: :string, format: :uuid}, + discovery_type: %Schema{type: :string}, + payload: %Schema{ + nullable: true, + oneOf: [%Schema{type: :object}, %Schema{type: :array}] + } + }, + required: [:agent_id, :discovery_type, :payload] }, - required: [:agent_id, :discovery_type, :payload] - }) + struct?: false + ) end diff --git a/lib/trento_web/openapi/v1/schema/forbidden.ex b/lib/trento_web/openapi/v1/schema/forbidden.ex index 76d284bfc7..7f11840542 100644 --- a/lib/trento_web/openapi/v1/schema/forbidden.ex +++ b/lib/trento_web/openapi/v1/schema/forbidden.ex @@ -7,26 +7,29 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Forbidden do alias OpenApiSpex.Operation alias OpenApiSpex.Schema - OpenApiSpex.schema(%{ - title: "Forbidden", - type: :object, - additionalProperties: false, - properties: %{ - errors: %Schema{ - type: :array, - items: %Schema{ - type: :object, - properties: %{ - detail: %Schema{ - type: :string, - example: "The requested operation could not be performed." - }, - title: %Schema{type: :string, example: "Forbidden"} + OpenApiSpex.schema( + %{ + title: "Forbidden", + type: :object, + additionalProperties: false, + properties: %{ + errors: %Schema{ + type: :array, + items: %Schema{ + type: :object, + properties: %{ + detail: %Schema{ + type: :string, + example: "The requested operation could not be performed." + }, + title: %Schema{type: :string, example: "Forbidden"} + } } } } - } - }) + }, + struct?: false + ) def response do Operation.response( diff --git a/lib/trento_web/openapi/v1/schema/health.ex b/lib/trento_web/openapi/v1/schema/health.ex index d1617f1eae..12a3f58206 100644 --- a/lib/trento_web/openapi/v1/schema/health.ex +++ b/lib/trento_web/openapi/v1/schema/health.ex @@ -7,21 +7,24 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Health do require OpenApiSpex - OpenApiSpex.schema(%Schema{ - title: "Health", - type: :object, - example: %{ - database: "pass" - }, - additionalProperties: false, - properties: %{ - database: %Schema{ - description: "The status of the database connection", - type: :string, - enum: ["pass", "fail"] + OpenApiSpex.schema( + %Schema{ + title: "Health", + type: :object, + example: %{ + database: "pass" + }, + additionalProperties: false, + properties: %{ + database: %Schema{ + description: "The status of the database connection", + type: :string, + enum: ["pass", "fail"] + } } - } - }) + }, + struct?: false + ) def response do Operation.response( diff --git a/lib/trento_web/openapi/v1/schema/host.ex b/lib/trento_web/openapi/v1/schema/host.ex index a74492fad7..b4199d3b9d 100644 --- a/lib/trento_web/openapi/v1/schema/host.ex +++ b/lib/trento_web/openapi/v1/schema/host.ex @@ -15,104 +15,116 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Host do defmodule IPv4 do @moduledoc false - OpenApiSpex.schema(%{ - title: "IPv4", - type: :string, - format: :ipv4 - }) + OpenApiSpex.schema( + %{ + title: "IPv4", + type: :string, + format: :ipv4 + }, + struct?: false + ) end defmodule IPv6 do @moduledoc false - OpenApiSpex.schema(%{ - title: "IPv6", - type: :string, - format: :ipv6 - }) + OpenApiSpex.schema( + %{ + title: "IPv6", + type: :string, + format: :ipv6 + }, + struct?: false + ) end defmodule HostItem do @moduledoc false - OpenApiSpex.schema(%{ - title: "Host", - description: "A discovered host on the target infrastructure", - type: :object, - additionalProperties: false, - properties: %{ - id: %Schema{type: :string, description: "Host ID", format: :uuid}, - hostname: %Schema{type: :string, description: "Host name"}, - ip_addresses: %Schema{ - type: :array, - description: "IP addresses", - items: %Schema{ - title: "IPAddress", - anyOf: [ - IPv4, - IPv6 - ] - } - }, - agent_version: %Schema{ - type: :string, - description: "Version of the agent installed on the host" - }, - health: ResourceHealth, - cluster_id: %Schema{ - type: :string, - description: "Identifier of the cluster this host is part of", - format: :uuid - }, - heartbeat: %Schema{ - type: :string, - description: "Host's last heartbeat status", - enum: [:critical, :passing, :unknown] - }, - provider: Provider.SupportedProviders, - provider_data: Provider.ProviderData, - tags: Tags, - sles_subscriptions: %Schema{ - title: "SlesSubscriptions", - description: "A list of the available SLES Subscriptions on a host", - type: :array, - items: SlesSubscription - }, - selected_checks: %Schema{ - title: "SelectedChecks", - description: "A list of check ids selected for an execution on this host", - type: :array, - items: %Schema{type: :string} - }, - saptune_status: SaptuneStatus, - deregistered_at: %Schema{ - title: "DeregisteredAt", - description: "Timestamp of the last deregistration of the host", - type: :string, - nullable: true, - format: :"date-time" - }, - last_heartbeat_timestamp: %Schema{ - title: "LastHeartbeatTimestamp", - description: "Timestamp of the last heartbeat received from the host", - type: :string, - nullable: true, - format: :"date-time" - }, - inserted_at: %Schema{type: :string, format: :datetime}, - updated_at: %Schema{type: :string, format: :datetime, nullable: true} - } - }) + OpenApiSpex.schema( + %{ + title: "Host", + description: "A discovered host on the target infrastructure", + type: :object, + additionalProperties: false, + properties: %{ + id: %Schema{type: :string, description: "Host ID", format: :uuid}, + hostname: %Schema{type: :string, description: "Host name"}, + ip_addresses: %Schema{ + type: :array, + description: "IP addresses", + items: %Schema{ + title: "IPAddress", + anyOf: [ + IPv4, + IPv6 + ] + } + }, + agent_version: %Schema{ + type: :string, + description: "Version of the agent installed on the host" + }, + health: ResourceHealth, + cluster_id: %Schema{ + type: :string, + description: "Identifier of the cluster this host is part of", + format: :uuid + }, + heartbeat: %Schema{ + type: :string, + description: "Host's last heartbeat status", + enum: [:critical, :passing, :unknown] + }, + provider: Provider.SupportedProviders, + provider_data: Provider.ProviderData, + tags: Tags, + sles_subscriptions: %Schema{ + title: "SlesSubscriptions", + description: "A list of the available SLES Subscriptions on a host", + type: :array, + items: SlesSubscription + }, + selected_checks: %Schema{ + title: "SelectedChecks", + description: "A list of check ids selected for an execution on this host", + type: :array, + items: %Schema{type: :string} + }, + saptune_status: SaptuneStatus, + deregistered_at: %Schema{ + title: "DeregisteredAt", + description: "Timestamp of the last deregistration of the host", + type: :string, + nullable: true, + format: :"date-time" + }, + last_heartbeat_timestamp: %Schema{ + title: "LastHeartbeatTimestamp", + description: "Timestamp of the last heartbeat received from the host", + type: :string, + nullable: true, + format: :"date-time" + }, + inserted_at: %Schema{type: :string, format: :datetime}, + updated_at: %Schema{type: :string, format: :datetime, nullable: true} + } + }, + struct?: false + ) end defmodule HostsCollection do @moduledoc false - OpenApiSpex.schema(%{ - title: "HostsCollection", - description: "A list of the discovered hosts", - type: :array, - items: HostItem - }) + OpenApiSpex.schema( + %{ + title: "HostsCollection", + description: "A list of the discovered hosts", + type: :array, + items: HostItem + }, + struct?: false + ) end end diff --git a/lib/trento_web/openapi/v1/schema/http_std.ex b/lib/trento_web/openapi/v1/schema/http_std.ex index fb47b534ee..a40fa72b2b 100644 --- a/lib/trento_web/openapi/v1/schema/http_std.ex +++ b/lib/trento_web/openapi/v1/schema/http_std.ex @@ -7,58 +7,64 @@ defmodule TrentoWeb.OpenApi.V1.Schema.HttpStd do defmodule Target do @moduledoc false - OpenApiSpex.schema(%{ - title: "HttpStd", - type: :object, - example: %{ - "targets" => ["myhost.de"], - "labels" => %{ - "labelname" => "mylabel" - } - }, - additionalProperties: false, - properties: %{ - labels: %Schema{ - type: :object, - description: "String valued labels", - additionalProperties: %Schema{type: :string} + OpenApiSpex.schema( + %{ + title: "HttpStd", + type: :object, + example: %{ + "targets" => ["myhost.de"], + "labels" => %{ + "labelname" => "mylabel" + } }, - targets: %Schema{ - type: :array, - description: "List of targets", - items: %Schema{ - title: "Targets", - anyOf: [ - %Schema{ - title: "IPv6", - type: :string, - format: :ipv6 - }, - %Schema{ - title: "IPv4", - type: :string, - format: :ipv4 - }, - %Schema{ - title: "Hostname", - type: :string, - format: :hostname - } - ] + additionalProperties: false, + properties: %{ + labels: %Schema{ + type: :object, + description: "String valued labels", + additionalProperties: %Schema{type: :string} + }, + targets: %Schema{ + type: :array, + description: "List of targets", + items: %Schema{ + title: "Targets", + anyOf: [ + %Schema{ + title: "IPv6", + type: :string, + format: :ipv6 + }, + %Schema{ + title: "IPv4", + type: :string, + format: :ipv4 + }, + %Schema{ + title: "Hostname", + type: :string, + format: :hostname + } + ] + } } } - } - }) + }, + struct?: false + ) end defmodule TargetList do @moduledoc false - OpenApiSpex.schema(%{ - title: "HttpSTDTargetList", - description: "Http discovery target list", - type: :array, - items: Target - }) + OpenApiSpex.schema( + %{ + title: "HttpSTDTargetList", + description: "Http discovery target list", + type: :array, + items: Target + }, + struct?: false + ) end end diff --git a/lib/trento_web/openapi/v1/schema/not_found.ex b/lib/trento_web/openapi/v1/schema/not_found.ex index 4e6c07f04a..e21523a522 100644 --- a/lib/trento_web/openapi/v1/schema/not_found.ex +++ b/lib/trento_web/openapi/v1/schema/not_found.ex @@ -7,23 +7,26 @@ defmodule TrentoWeb.OpenApi.V1.Schema.NotFound do alias OpenApiSpex.Operation alias OpenApiSpex.Schema - OpenApiSpex.schema(%{ - title: "NotFound", - type: :object, - additionalProperties: false, - properties: %{ - errors: %Schema{ - type: :array, - items: %Schema{ - type: :object, - properties: %{ - detail: %Schema{type: :string, example: "The requested resource cannot be found."}, - title: %Schema{type: :string, example: "Not Found"} + OpenApiSpex.schema( + %{ + title: "NotFound", + type: :object, + additionalProperties: false, + properties: %{ + errors: %Schema{ + type: :array, + items: %Schema{ + type: :object, + properties: %{ + detail: %Schema{type: :string, example: "The requested resource cannot be found."}, + title: %Schema{type: :string, example: "Not Found"} + } } } } - } - }) + }, + struct?: false + ) def response do Operation.response( diff --git a/lib/trento_web/openapi/v1/schema/platform.ex b/lib/trento_web/openapi/v1/schema/platform.ex index 91da64e8d8..bde0698d70 100644 --- a/lib/trento_web/openapi/v1/schema/platform.ex +++ b/lib/trento_web/openapi/v1/schema/platform.ex @@ -7,137 +7,155 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Platform do defmodule Settings do @moduledoc false - OpenApiSpex.schema(%{ - title: "PlatformSettings", - description: "Settings values for the current installation", - type: :object, - additionalProperties: false, - properties: %{ - eula_accepted: %Schema{ - type: :boolean, - description: "Whether the user has accepted EULA (on a Premium installation)", - deprecated: true - }, - premium_subscription: %Schema{ - type: :boolean, - description: "Whether current installation is a Premium one" + OpenApiSpex.schema( + %{ + title: "PlatformSettings", + description: "Settings values for the current installation", + type: :object, + additionalProperties: false, + properties: %{ + eula_accepted: %Schema{ + type: :boolean, + description: "Whether the user has accepted EULA (on a Premium installation)", + deprecated: true + }, + premium_subscription: %Schema{ + type: :boolean, + description: "Whether current installation is a Premium one" + } } - } - }) + }, + struct?: false + ) end defmodule ApiKeySettings do @moduledoc false - OpenApiSpex.schema(%{ - title: "ApiKeySettings", - description: "Settings for Api Key generation", - type: :object, - additionalProperties: false, - properties: %{ - created_at: %Schema{ - type: :string, - format: :"date-time", - description: "The creation date of api key" - }, - generated_api_key: %Schema{ - type: :string, - description: "The generated api key from api key settings" + OpenApiSpex.schema( + %{ + title: "ApiKeySettings", + description: "Settings for Api Key generation", + type: :object, + additionalProperties: false, + properties: %{ + created_at: %Schema{ + type: :string, + format: :"date-time", + description: "The creation date of api key" + }, + generated_api_key: %Schema{ + type: :string, + description: "The generated api key from api key settings" + }, + expire_at: %Schema{ + type: :string, + format: :"date-time", + description: "The expire date of api key", + nullable: true + } }, - expire_at: %Schema{ - type: :string, - format: :"date-time", - description: "The expire date of api key", - nullable: true - } + required: [:generated_api_key, :expire_at, :created_at] }, - required: [:generated_api_key, :expire_at, :created_at] - }) + struct?: false + ) end defmodule ApiKeySettingsUpdateRequest do @moduledoc false - OpenApiSpex.schema(%{ - title: "ApiKeySettingsUpdateRequest", - description: "Request body for api key settings update", - type: :object, - additionalProperties: false, - properties: %{ - expire_at: %Schema{ - type: :string, - format: :"date-time", - description: "The expire date of api key", - nullable: true - } + OpenApiSpex.schema( + %{ + title: "ApiKeySettingsUpdateRequest", + description: "Request body for api key settings update", + type: :object, + additionalProperties: false, + properties: %{ + expire_at: %Schema{ + type: :string, + format: :"date-time", + description: "The expire date of api key", + nullable: true + } + }, + required: [:expire_at] }, - required: [:expire_at] - }) + struct?: false + ) end defmodule GeneralInformation do @moduledoc false - OpenApiSpex.schema(%{ - title: "GeneralInformation", - description: "General information about the current installation", - type: :object, - additionalProperties: false, - properties: %{ - flavor: %Schema{ - type: :string, - description: "Flavor of the current installation", - enum: ["Community", "Premium"] - }, - version: %Schema{ - type: :string, - description: "Version of the current server component installation" - }, - sles_subscriptions: %Schema{ - type: :integer, - description: "The number of SLES Subscription discovered on the target infrastructure" + OpenApiSpex.schema( + %{ + title: "GeneralInformation", + description: "General information about the current installation", + type: :object, + additionalProperties: false, + properties: %{ + flavor: %Schema{ + type: :string, + description: "Flavor of the current installation", + enum: ["Community", "Premium"] + }, + version: %Schema{ + type: :string, + description: "Version of the current server component installation" + }, + sles_subscriptions: %Schema{ + type: :integer, + description: "The number of SLES Subscription discovered on the target infrastructure" + } } - } - }) + }, + struct?: false + ) end defmodule RetentionTimeSettings do @moduledoc false - OpenApiSpex.schema(%{ - title: "RetentionTimeSettings", - description: "Retention Time settings of the Activity Log", - type: :object, - additionalProperties: false, - properties: %{ - value: %Schema{ - type: :integer, - description: - "The integer retention duration, that is used in conjunction with the retention time unit.", - minimum: 1 + OpenApiSpex.schema( + %{ + title: "RetentionTimeSettings", + description: "Retention Time settings of the Activity Log", + type: :object, + additionalProperties: false, + properties: %{ + value: %Schema{ + type: :integer, + description: + "The integer retention duration, that is used in conjunction with the retention time unit.", + minimum: 1 + }, + unit: %Schema{ + type: :string, + description: + "The retention duration unit, that is used in conjunction with the retention time period.", + enum: [:day, :week, :month, :year] + } }, - unit: %Schema{ - type: :string, - description: - "The retention duration unit, that is used in conjunction with the retention time period.", - enum: [:day, :week, :month, :year] - } + required: [:value, :unit] }, - required: [:value, :unit] - }) + struct?: false + ) end defmodule ActivityLogSettings do @moduledoc false - OpenApiSpex.schema(%{ - title: "ActivityLogSettings", - description: "Activity Log settings of the current installation", - type: :object, - additionalProperties: false, - properties: %{ - retention_time: RetentionTimeSettings + OpenApiSpex.schema( + %{ + title: "ActivityLogSettings", + description: "Activity Log settings of the current installation", + type: :object, + additionalProperties: false, + properties: %{ + retention_time: RetentionTimeSettings + }, + required: [:retention_time] }, - required: [:retention_time] - }) + struct?: false + ) end end diff --git a/lib/trento_web/openapi/v1/schema/precondition_failed.ex b/lib/trento_web/openapi/v1/schema/precondition_failed.ex index 5f0aef0835..8f0ebb436f 100644 --- a/lib/trento_web/openapi/v1/schema/precondition_failed.ex +++ b/lib/trento_web/openapi/v1/schema/precondition_failed.ex @@ -7,27 +7,30 @@ defmodule TrentoWeb.OpenApi.V1.Schema.PreconditionFailed do alias OpenApiSpex.Operation alias OpenApiSpex.Schema - OpenApiSpex.schema(%{ - title: "PreconditionFailed", - type: :object, - additionalProperties: false, - properties: %{ - errors: %Schema{ - type: :array, - items: %Schema{ - type: :object, - properties: %{ - detail: %Schema{ - type: :string, - example: - "Mid-air collision detected, please refresh the resource you are trying to update." - }, - title: %Schema{type: :string, example: "Precondition Failed"} + OpenApiSpex.schema( + %{ + title: "PreconditionFailed", + type: :object, + additionalProperties: false, + properties: %{ + errors: %Schema{ + type: :array, + items: %Schema{ + type: :object, + properties: %{ + detail: %Schema{ + type: :string, + example: + "Mid-air collision detected, please refresh the resource you are trying to update." + }, + title: %Schema{type: :string, example: "Precondition Failed"} + } } } } - } - }) + }, + struct?: false + ) def response do Operation.response( diff --git a/lib/trento_web/openapi/v1/schema/precondition_required.ex b/lib/trento_web/openapi/v1/schema/precondition_required.ex index 6064cd6894..50d929e3a9 100644 --- a/lib/trento_web/openapi/v1/schema/precondition_required.ex +++ b/lib/trento_web/openapi/v1/schema/precondition_required.ex @@ -7,26 +7,29 @@ defmodule TrentoWeb.OpenApi.V1.Schema.PreconditionRequired do alias OpenApiSpex.Operation alias OpenApiSpex.Schema - OpenApiSpex.schema(%{ - title: "PreconditionRequired", - type: :object, - additionalProperties: false, - properties: %{ - errors: %Schema{ - type: :array, - items: %Schema{ - type: :object, - properties: %{ - detail: %Schema{ - type: :string, - example: "Request needs to be conditional, please provide If-Match header." - }, - title: %Schema{type: :string, example: "Precondition Required"} + OpenApiSpex.schema( + %{ + title: "PreconditionRequired", + type: :object, + additionalProperties: false, + properties: %{ + errors: %Schema{ + type: :array, + items: %Schema{ + type: :object, + properties: %{ + detail: %Schema{ + type: :string, + example: "Request needs to be conditional, please provide If-Match header." + }, + title: %Schema{type: :string, example: "Precondition Required"} + } } } } - } - }) + }, + struct?: false + ) def response do Operation.response( diff --git a/lib/trento_web/openapi/v1/schema/prometheus.ex b/lib/trento_web/openapi/v1/schema/prometheus.ex index cbebbfa06c..0d8761d912 100644 --- a/lib/trento_web/openapi/v1/schema/prometheus.ex +++ b/lib/trento_web/openapi/v1/schema/prometheus.ex @@ -7,18 +7,21 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Prometheus do defmodule ExporterStatus do @moduledoc false - OpenApiSpex.schema(%{ - title: "PrometheusExporterStatus", - type: :object, - example: %{ - "Node exporter" => "critical" + OpenApiSpex.schema( + %{ + title: "PrometheusExporterStatus", + type: :object, + example: %{ + "Node exporter" => "critical" + }, + additionalProperties: %Schema{ + enum: [:critical, :passing, :unknown], + description: + "Status of the exporter, the value could be one of passing, critical, unknown", + type: :string + } }, - additionalProperties: %Schema{ - enum: [:critical, :passing, :unknown], - description: - "Status of the exporter, the value could be one of passing, critical, unknown", - type: :string - } - }) + struct?: false + ) end end diff --git a/lib/trento_web/openapi/v1/schema/provider.ex b/lib/trento_web/openapi/v1/schema/provider.ex index d282b96414..4b484804c0 100644 --- a/lib/trento_web/openapi/v1/schema/provider.ex +++ b/lib/trento_web/openapi/v1/schema/provider.ex @@ -9,98 +9,116 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Provider do defmodule SupportedProviders do @moduledoc false - OpenApiSpex.schema(%{ - title: "SupportedProviders", - type: :string, - description: "Detected Provider where the resource is running", - enum: Provider.values() - }) + OpenApiSpex.schema( + %{ + title: "SupportedProviders", + type: :string, + description: "Detected Provider where the resource is running", + enum: Provider.values() + }, + struct?: false + ) end defmodule FilterableProviders do @moduledoc false - OpenApiSpex.schema(%{ - title: "FilterableProvider", - type: :string, - description: "A provider that can be used to filter the Catalog", - enum: [:azure, :aws, :gcp, :default] - }) + OpenApiSpex.schema( + %{ + title: "FilterableProvider", + type: :string, + description: "A provider that can be used to filter the Catalog", + enum: [:azure, :aws, :gcp, :default] + }, + struct?: false + ) end defmodule AzureProviderData do @moduledoc false - OpenApiSpex.schema(%{ - title: "AzureProviderData", - description: "Azure detected metadata", - type: :object, - additionalProperties: false, - properties: %{ - resource_group: %Schema{type: :string}, - location: %Schema{type: :string}, - vm_size: %Schema{type: :string}, - data_disk_number: %Schema{type: :integer}, - offer: %Schema{type: :string}, - sku: %Schema{type: :string}, - admin_username: %Schema{type: :string} - } - }) + OpenApiSpex.schema( + %{ + title: "AzureProviderData", + description: "Azure detected metadata", + type: :object, + additionalProperties: false, + properties: %{ + resource_group: %Schema{type: :string}, + location: %Schema{type: :string}, + vm_size: %Schema{type: :string}, + data_disk_number: %Schema{type: :integer}, + offer: %Schema{type: :string}, + sku: %Schema{type: :string}, + admin_username: %Schema{type: :string} + } + }, + struct?: false + ) end defmodule AwsProviderData do @moduledoc false - OpenApiSpex.schema(%{ - title: "AwsProviderData", - description: "AWS detected metadata", - type: :object, - additionalProperties: false, - properties: %{ - account_id: %Schema{type: :string}, - ami_id: %Schema{type: :string}, - availability_zone: %Schema{type: :string}, - data_disk_number: %Schema{type: :integer}, - instance_id: %Schema{type: :string}, - instance_type: %Schema{type: :string}, - region: %Schema{type: :string}, - vpc_id: %Schema{type: :string} - } - }) + OpenApiSpex.schema( + %{ + title: "AwsProviderData", + description: "AWS detected metadata", + type: :object, + additionalProperties: false, + properties: %{ + account_id: %Schema{type: :string}, + ami_id: %Schema{type: :string}, + availability_zone: %Schema{type: :string}, + data_disk_number: %Schema{type: :integer}, + instance_id: %Schema{type: :string}, + instance_type: %Schema{type: :string}, + region: %Schema{type: :string}, + vpc_id: %Schema{type: :string} + } + }, + struct?: false + ) end defmodule GcpProviderData do @moduledoc false - OpenApiSpex.schema(%{ - title: "GcpProviderData", - description: "GCP detected metadata", - type: :object, - additionalProperties: false, - properties: %{ - disk_number: %Schema{type: :integer}, - image: %Schema{type: :string}, - instance_name: %Schema{type: :string}, - machine_type: %Schema{type: :string}, - network: %Schema{type: :string}, - project_id: %Schema{type: :string}, - zone: %Schema{type: :string} - } - }) + OpenApiSpex.schema( + %{ + title: "GcpProviderData", + description: "GCP detected metadata", + type: :object, + additionalProperties: false, + properties: %{ + disk_number: %Schema{type: :integer}, + image: %Schema{type: :string}, + instance_name: %Schema{type: :string}, + machine_type: %Schema{type: :string}, + network: %Schema{type: :string}, + project_id: %Schema{type: :string}, + zone: %Schema{type: :string} + } + }, + struct?: false + ) end defmodule ProviderData do @moduledoc false - OpenApiSpex.schema(%{ - title: "ProviderMetadata", - nullable: true, - description: "Detected metadata for any provider", - oneOf: [ - AwsProviderData, - AzureProviderData, - GcpProviderData - ] - }) + OpenApiSpex.schema( + %{ + title: "ProviderMetadata", + nullable: true, + description: "Detected metadata for any provider", + oneOf: [ + AwsProviderData, + AzureProviderData, + GcpProviderData + ] + }, + struct?: false + ) end end diff --git a/lib/trento_web/openapi/v1/schema/ready.ex b/lib/trento_web/openapi/v1/schema/ready.ex index 68fe848e02..c98796f272 100644 --- a/lib/trento_web/openapi/v1/schema/ready.ex +++ b/lib/trento_web/openapi/v1/schema/ready.ex @@ -7,20 +7,23 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Ready do require OpenApiSpex - OpenApiSpex.schema(%Schema{ - title: "Ready", - type: :object, - example: %{ - ready: true - }, - additionalProperties: false, - properties: %{ - ready: %Schema{ - description: "Trento Web platform ready", - type: :boolean + OpenApiSpex.schema( + %Schema{ + title: "Ready", + type: :object, + example: %{ + ready: true + }, + additionalProperties: false, + properties: %{ + ready: %Schema{ + description: "Trento Web platform ready", + type: :boolean + } } - } - }) + }, + struct?: false + ) def response do Operation.response( diff --git a/lib/trento_web/openapi/v1/schema/resource_health.ex b/lib/trento_web/openapi/v1/schema/resource_health.ex index 585056997c..85cd7538a7 100644 --- a/lib/trento_web/openapi/v1/schema/resource_health.ex +++ b/lib/trento_web/openapi/v1/schema/resource_health.ex @@ -4,11 +4,14 @@ defmodule TrentoWeb.OpenApi.V1.Schema.ResourceHealth do require OpenApiSpex require Trento.Enums.Health, as: Health - OpenApiSpex.schema(%{ - title: "ResourceHealth", - type: :string, - nullable: true, - description: "Detected health of a Resource", - enum: Health.values() - }) + OpenApiSpex.schema( + %{ + title: "ResourceHealth", + type: :string, + nullable: true, + description: "Detected health of a Resource", + enum: Health.values() + }, + struct?: false + ) end diff --git a/lib/trento_web/openapi/v1/schema/sap_system.ex b/lib/trento_web/openapi/v1/schema/sap_system.ex index d32ed5ef37..cf8ba2c451 100644 --- a/lib/trento_web/openapi/v1/schema/sap_system.ex +++ b/lib/trento_web/openapi/v1/schema/sap_system.ex @@ -11,145 +11,160 @@ defmodule TrentoWeb.OpenApi.V1.Schema.SAPSystem do defmodule ApplicationInstance do @moduledoc false - OpenApiSpex.schema(%{ - title: "ApplicationInstance", - description: "A discovered Application Instance on the target infrastructure", - type: :object, - additionalProperties: false, - properties: %{ - sap_system_id: %Schema{type: :string, description: "SAP System ID", format: :uuid}, - sid: %Schema{type: :string, description: "SID"}, - instance_number: %Schema{type: :string, description: "Instance Number"}, - instance_hostname: %Schema{ - type: :string, - description: "Instance Hostname", - nullable: true - }, - absent_at: %Schema{ - type: :string, - description: "Absent instance timestamp", - format: :datetime, - nullable: true - }, - features: %Schema{type: :string, description: "Instance Features"}, - http_port: %Schema{type: :integer, description: "Instance HTTP Port", nullable: true}, - https_port: %Schema{type: :integer, description: "Instance HTTPS Port", nullable: true}, - start_priority: %Schema{ - type: :string, - description: "Instance Start Priority", - nullable: true - }, - host_id: %Schema{ - type: :string, - description: "Identifier of the host where current instance is running", - format: :uuid - }, - health: ResourceHealth, - inserted_at: %Schema{type: :string, format: :datetime}, - updated_at: %Schema{type: :string, format: :datetime, nullable: true} - } - }) + OpenApiSpex.schema( + %{ + title: "ApplicationInstance", + description: "A discovered Application Instance on the target infrastructure", + type: :object, + additionalProperties: false, + properties: %{ + sap_system_id: %Schema{type: :string, description: "SAP System ID", format: :uuid}, + sid: %Schema{type: :string, description: "SID"}, + instance_number: %Schema{type: :string, description: "Instance Number"}, + instance_hostname: %Schema{ + type: :string, + description: "Instance Hostname", + nullable: true + }, + absent_at: %Schema{ + type: :string, + description: "Absent instance timestamp", + format: :datetime, + nullable: true + }, + features: %Schema{type: :string, description: "Instance Features"}, + http_port: %Schema{type: :integer, description: "Instance HTTP Port", nullable: true}, + https_port: %Schema{type: :integer, description: "Instance HTTPS Port", nullable: true}, + start_priority: %Schema{ + type: :string, + description: "Instance Start Priority", + nullable: true + }, + host_id: %Schema{ + type: :string, + description: "Identifier of the host where current instance is running", + format: :uuid + }, + health: ResourceHealth, + inserted_at: %Schema{type: :string, format: :datetime}, + updated_at: %Schema{type: :string, format: :datetime, nullable: true} + } + }, + struct?: false + ) end defmodule SAPSystemItem do @moduledoc false - OpenApiSpex.schema(%{ - title: "SAPSystem", - description: "A discovered SAP System on the target infrastructure", - type: :object, - additionalProperties: false, - properties: %{ - id: %Schema{type: :string, description: "SAP System ID", format: :uuid}, - sid: %Schema{type: :string, description: "SID"}, - tenant: %Schema{type: :string, description: "Tenant"}, - db_host: %Schema{type: :string, description: "Address of the connected Database"}, - health: ResourceHealth, - ensa_version: %Schema{ - type: :string, - enum: EnsaVersion.values(), - description: "ENSA version of the SAP system" - }, - application_instances: %Schema{ - title: "ApplicationInstances", - description: "A list of the discovered Application Instances for current SAP Systems", - type: :array, - items: ApplicationInstance - }, - database_id: %Schema{type: :string, description: "Database ID", format: :uuid}, - database_sid: %Schema{type: :string, description: "Database SID"}, - database_instances: Database.DatabaseInstances, - tags: Tags, - inserted_at: %Schema{type: :string, format: :datetime}, - updated_at: %Schema{type: :string, format: :datetime, nullable: true} - } - }) + OpenApiSpex.schema( + %{ + title: "SAPSystem", + description: "A discovered SAP System on the target infrastructure", + type: :object, + additionalProperties: false, + properties: %{ + id: %Schema{type: :string, description: "SAP System ID", format: :uuid}, + sid: %Schema{type: :string, description: "SID"}, + tenant: %Schema{type: :string, description: "Tenant"}, + db_host: %Schema{type: :string, description: "Address of the connected Database"}, + health: ResourceHealth, + ensa_version: %Schema{ + type: :string, + enum: EnsaVersion.values(), + description: "ENSA version of the SAP system" + }, + application_instances: %Schema{ + title: "ApplicationInstances", + description: "A list of the discovered Application Instances for current SAP Systems", + type: :array, + items: ApplicationInstance + }, + database_id: %Schema{type: :string, description: "Database ID", format: :uuid}, + database_sid: %Schema{type: :string, description: "Database SID"}, + database_instances: Database.DatabaseInstances, + tags: Tags, + inserted_at: %Schema{type: :string, format: :datetime}, + updated_at: %Schema{type: :string, format: :datetime, nullable: true} + } + }, + struct?: false + ) end defmodule SAPSystemsCollection do @moduledoc false - OpenApiSpex.schema(%{ - title: "SAPSystemsCollection", - description: "A list of the discovered SAP Systems", - type: :array, - items: SAPSystemItem - }) + OpenApiSpex.schema( + %{ + title: "SAPSystemsCollection", + description: "A list of the discovered SAP Systems", + type: :array, + items: SAPSystemItem + }, + struct?: false + ) end defmodule SAPSystemHealthOverview do @moduledoc false - OpenApiSpex.schema(%{ - title: "SAPSystemHealthOverview", - description: "An overview of the health of a discovered SAP System and its components", - type: :object, - additionalProperties: false, - properties: %{ - id: %Schema{type: :string, description: "SAP System ID", format: :uuid}, - sid: %Schema{type: :string, description: "SID"}, - cluster_id: %Schema{ - type: :string, - description: "Cluster ID", - format: :uuid, - deprecated: true - }, - application_cluster_id: %Schema{ - type: :string, - description: "Application cluster ID", - format: :uuid - }, - database_cluster_id: %Schema{ - type: :string, - description: "Database cluster ID", - format: :uuid - }, - database_id: %Schema{type: :string, description: "Database ID", format: :uuid}, - sapsystem_health: ResourceHealth, - database_health: ResourceHealth, - hosts_health: ResourceHealth, - clusters_health: %Schema{ - allOf: [ - ResourceHealth, - %Schema{deprecated: true} - ] - }, - application_cluster_health: ResourceHealth, - database_cluster_health: ResourceHealth, - tenant: %Schema{type: :string, description: "Tenant database SID", deprecated: true}, - database_sid: %Schema{type: :string, description: "Database SID"} - } - }) + OpenApiSpex.schema( + %{ + title: "SAPSystemHealthOverview", + description: "An overview of the health of a discovered SAP System and its components", + type: :object, + additionalProperties: false, + properties: %{ + id: %Schema{type: :string, description: "SAP System ID", format: :uuid}, + sid: %Schema{type: :string, description: "SID"}, + cluster_id: %Schema{ + type: :string, + description: "Cluster ID", + format: :uuid, + deprecated: true + }, + application_cluster_id: %Schema{ + type: :string, + description: "Application cluster ID", + format: :uuid + }, + database_cluster_id: %Schema{ + type: :string, + description: "Database cluster ID", + format: :uuid + }, + database_id: %Schema{type: :string, description: "Database ID", format: :uuid}, + sapsystem_health: ResourceHealth, + database_health: ResourceHealth, + hosts_health: ResourceHealth, + clusters_health: %Schema{ + allOf: [ + ResourceHealth, + %Schema{deprecated: true} + ] + }, + application_cluster_health: ResourceHealth, + database_cluster_health: ResourceHealth, + tenant: %Schema{type: :string, description: "Tenant database SID", deprecated: true}, + database_sid: %Schema{type: :string, description: "Database SID"} + } + }, + struct?: false + ) end defmodule HealthOverview do @moduledoc false - OpenApiSpex.schema(%{ - title: "HealthOverview", - description: "A list of health summaries for the discovered SAP Systems", - type: :array, - items: SAPSystemHealthOverview - }) + OpenApiSpex.schema( + %{ + title: "HealthOverview", + description: "A list of health summaries for the discovered SAP Systems", + type: :array, + items: SAPSystemHealthOverview + }, + struct?: false + ) end end diff --git a/lib/trento_web/openapi/v1/schema/saptune_status.ex b/lib/trento_web/openapi/v1/schema/saptune_status.ex index 98319a4d9c..1a19207da4 100644 --- a/lib/trento_web/openapi/v1/schema/saptune_status.ex +++ b/lib/trento_web/openapi/v1/schema/saptune_status.ex @@ -8,134 +8,149 @@ defmodule TrentoWeb.OpenApi.V1.Schema.SaptuneStatus do defmodule Service do @moduledoc false - OpenApiSpex.schema(%{ - title: "Saptune service", - description: "Saptune service", - type: :object, - additionalProperties: false, - properties: %{ - name: %Schema{ - type: :string, - description: "Saptune service name" - }, - enabled: %Schema{ - type: :string, - description: "Enabled state as string" - }, - active: %Schema{ - type: :string, - description: "Active state as string" + OpenApiSpex.schema( + %{ + title: "Saptune service", + description: "Saptune service", + type: :object, + additionalProperties: false, + properties: %{ + name: %Schema{ + type: :string, + description: "Saptune service name" + }, + enabled: %Schema{ + type: :string, + description: "Enabled state as string" + }, + active: %Schema{ + type: :string, + description: "Active state as string" + } } - } - }) + }, + struct?: false + ) end defmodule Note do @moduledoc false - OpenApiSpex.schema(%{ - title: "Saptune note", - description: "Saptune note", - type: :object, - additionalProperties: false, - properties: %{ - id: %Schema{ - type: :string, - description: "Saptune note ID" - }, - additionally_enabled: %Schema{ - type: :boolean, - description: "Note is additionally enabled" + OpenApiSpex.schema( + %{ + title: "Saptune note", + description: "Saptune note", + type: :object, + additionalProperties: false, + properties: %{ + id: %Schema{ + type: :string, + description: "Saptune note ID" + }, + additionally_enabled: %Schema{ + type: :boolean, + description: "Note is additionally enabled" + } } - } - }) + }, + struct?: false + ) end defmodule Solution do @moduledoc false - OpenApiSpex.schema(%{ - title: "Saptune solution", - description: "Saptune solution", - type: :object, - additionalProperties: false, - properties: %{ - id: %Schema{ - type: :boolean, - description: "Saptune solution ID" - }, - notes: %Schema{ - type: :array, - description: "Solution note IDs", - items: %Schema{type: :string} - }, - partial: %Schema{ - type: :boolean, - description: "Solution is partially applied" + OpenApiSpex.schema( + %{ + title: "Saptune solution", + description: "Saptune solution", + type: :object, + additionalProperties: false, + properties: %{ + id: %Schema{ + type: :boolean, + description: "Saptune solution ID" + }, + notes: %Schema{ + type: :array, + description: "Solution note IDs", + items: %Schema{type: :string} + }, + partial: %Schema{ + type: :boolean, + description: "Solution is partially applied" + } } - } - }) + }, + struct?: false + ) end defmodule Staging do @moduledoc false - OpenApiSpex.schema(%{ - title: "Saptune staging", - description: "Saptune staging data", + OpenApiSpex.schema( + %{ + title: "Saptune staging", + description: "Saptune staging data", + type: :object, + additionalProperties: false, + properties: %{ + enabled: %Schema{ + type: :boolean, + description: "Saptune staging is enabled" + }, + notes: %Schema{ + type: :array, + description: "Staged saptune note IDs", + items: %Schema{type: :string} + }, + solutions_ids: %Schema{ + type: :array, + description: "Staged saptune solution IDs", + items: %Schema{type: :string} + } + } + }, + struct?: false + ) + end + + OpenApiSpex.schema( + %{ + title: "Saptune status", + description: "Saptune status output on the host", type: :object, + nullable: true, additionalProperties: false, properties: %{ - enabled: %Schema{ - type: :boolean, - description: "Saptune staging is enabled" + package_version: %Schema{type: :string, description: "Saptune package version"}, + configured_version: %Schema{type: :string, description: "Saptune configure version"}, + tuning_state: %Schema{type: :string, description: "Saptune tuning state"}, + services: %Schema{ + title: "Saptune services", + description: "A list of saptune services", + type: :array, + items: Service }, - notes: %Schema{ + enabled_nodes: %Schema{ + title: "Enabled notes", + description: "A list of enabled notes", type: :array, - description: "Staged saptune note IDs", - items: %Schema{type: :string} + items: Note }, - solutions_ids: %Schema{ + applied_notes: %Schema{ + title: "Applied notes", + description: "A list of applied notes", type: :array, - description: "Staged saptune solution IDs", - items: %Schema{type: :string} - } - } - }) - end - - OpenApiSpex.schema(%{ - title: "Saptune status", - description: "Saptune status output on the host", - type: :object, - nullable: true, - additionalProperties: false, - properties: %{ - package_version: %Schema{type: :string, description: "Saptune package version"}, - configured_version: %Schema{type: :string, description: "Saptune configure version"}, - tuning_state: %Schema{type: :string, description: "Saptune tuning state"}, - services: %Schema{ - title: "Saptune services", - description: "A list of saptune services", - type: :array, - items: Service - }, - enabled_nodes: %Schema{ - title: "Enabled notes", - description: "A list of enabled notes", - type: :array, - items: Note - }, - applied_notes: %Schema{ - title: "Applied notes", - description: "A list of applied notes", - type: :array, - items: Note + items: Note + }, + enabled_solution: Solution, + applied_solution: Solution, + staging: Staging }, - enabled_solution: Solution, - applied_solution: Solution, - staging: Staging + required: [:package_version] }, - required: [:package_version] - }) + struct?: false + ) end diff --git a/lib/trento_web/openapi/v1/schema/sles_subscription.ex b/lib/trento_web/openapi/v1/schema/sles_subscription.ex index a9dcfdccef..19931a7b9d 100644 --- a/lib/trento_web/openapi/v1/schema/sles_subscription.ex +++ b/lib/trento_web/openapi/v1/schema/sles_subscription.ex @@ -4,21 +4,24 @@ defmodule TrentoWeb.OpenApi.V1.Schema.SlesSubscription do require OpenApiSpex alias OpenApiSpex.Schema - OpenApiSpex.schema(%{ - title: "SlesSubscription", - description: "A discovered SLES Subscription on a host", - type: :object, - additionalProperties: false, - properties: %{ - host_id: %Schema{type: :string, format: :uuid}, - identifier: %Schema{type: :string}, - version: %Schema{type: :string}, - arch: %Schema{type: :string}, - status: %Schema{type: :string}, - subscription_status: %Schema{type: :string}, - type: %Schema{type: :string}, - starts_at: %Schema{type: :string}, - expires_at: %Schema{type: :string} - } - }) + OpenApiSpex.schema( + %{ + title: "SlesSubscription", + description: "A discovered SLES Subscription on a host", + type: :object, + additionalProperties: false, + properties: %{ + host_id: %Schema{type: :string, format: :uuid}, + identifier: %Schema{type: :string}, + version: %Schema{type: :string}, + arch: %Schema{type: :string}, + status: %Schema{type: :string}, + subscription_status: %Schema{type: :string}, + type: %Schema{type: :string}, + starts_at: %Schema{type: :string}, + expires_at: %Schema{type: :string} + } + }, + struct?: false + ) end diff --git a/lib/trento_web/openapi/v1/schema/suma_credentials.ex b/lib/trento_web/openapi/v1/schema/suma_credentials.ex index 5125518625..aa4c82eb12 100644 --- a/lib/trento_web/openapi/v1/schema/suma_credentials.ex +++ b/lib/trento_web/openapi/v1/schema/suma_credentials.ex @@ -7,27 +7,30 @@ defmodule TrentoWeb.OpenApi.V1.Schema.SUMACredentials do defmodule SaveSUMACredentialsRequest do @moduledoc false - OpenApiSpex.schema(%{ - title: "SaveSUMACredentialsRequest", - description: "Request body for saving SUMA credentials", - type: :object, - additionalProperties: false, - properties: %{ - url: %Schema{ - type: :string - }, - username: %Schema{ - type: :string - }, - password: %Schema{ - type: :string + OpenApiSpex.schema( + %{ + title: "SaveSUMACredentialsRequest", + description: "Request body for saving SUMA credentials", + type: :object, + additionalProperties: false, + properties: %{ + url: %Schema{ + type: :string + }, + username: %Schema{ + type: :string + }, + password: %Schema{ + type: :string + }, + ca_cert: %Schema{ + type: :string + } }, - ca_cert: %Schema{ - type: :string - } + required: [:url, :username, :password] }, - required: [:url, :username, :password] - }) + struct?: false + ) end defmodule UpdateSUMACredentialsRequest do @@ -64,27 +67,30 @@ defmodule TrentoWeb.OpenApi.V1.Schema.SUMACredentials do defmodule Settings do @moduledoc false - OpenApiSpex.schema(%{ - title: "SUMACredentials", - description: "User settings for SUSE Manager", - type: :object, - additionalProperties: false, - properties: %{ - url: %Schema{ - type: :string, - description: "URL of SUSE Manager" - }, - username: %Schema{ - type: :string, - description: "Username" - }, - ca_uploaded_at: %Schema{ - type: :string, - format: :datetime, - nullable: true, - description: "Time that SSL certificate was uploaded." + OpenApiSpex.schema( + %{ + title: "SUMACredentials", + description: "User settings for SUSE Manager", + type: :object, + additionalProperties: false, + properties: %{ + url: %Schema{ + type: :string, + description: "URL of SUSE Manager" + }, + username: %Schema{ + type: :string, + description: "Username" + }, + ca_uploaded_at: %Schema{ + type: :string, + format: :datetime, + nullable: true, + description: "Time that SSL certificate was uploaded." + } } - } - }) + }, + struct?: false + ) end end diff --git a/lib/trento_web/openapi/v1/schema/tag.ex b/lib/trento_web/openapi/v1/schema/tag.ex index 200a95b976..a50f378876 100644 --- a/lib/trento_web/openapi/v1/schema/tag.ex +++ b/lib/trento_web/openapi/v1/schema/tag.ex @@ -9,26 +9,32 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Tags do require OpenApiSpex alias OpenApiSpex.Schema - OpenApiSpex.schema(%{ - title: "Tag", - description: "A tag attached to a resource", - type: :object, - additionalProperties: false, - properties: %{ - id: %Schema{type: :integer}, - resource_id: %Schema{type: :string, format: :uuid}, - resource_type: %Schema{type: :string, enum: [:host, :cluster, :sap_system, :database]}, - value: %Schema{type: :string}, - inserted_at: %Schema{type: :string, format: :datetime}, - updated_at: %Schema{type: :string, format: :datetime, nullable: true} - } - }) + OpenApiSpex.schema( + %{ + title: "Tag", + description: "A tag attached to a resource", + type: :object, + additionalProperties: false, + properties: %{ + id: %Schema{type: :integer}, + resource_id: %Schema{type: :string, format: :uuid}, + resource_type: %Schema{type: :string, enum: [:host, :cluster, :sap_system, :database]}, + value: %Schema{type: :string}, + inserted_at: %Schema{type: :string, format: :datetime}, + updated_at: %Schema{type: :string, format: :datetime, nullable: true} + } + }, + struct?: false + ) end - OpenApiSpex.schema(%{ - title: "Tags", - description: "A list of tags attached to a resource", - type: :array, - items: Tag - }) + OpenApiSpex.schema( + %{ + title: "Tags", + description: "A list of tags attached to a resource", + type: :array, + items: Tag + }, + struct?: false + ) end diff --git a/lib/trento_web/openapi/v1/schema/unauthorized.ex b/lib/trento_web/openapi/v1/schema/unauthorized.ex index a6ea150233..394cd47943 100644 --- a/lib/trento_web/openapi/v1/schema/unauthorized.ex +++ b/lib/trento_web/openapi/v1/schema/unauthorized.ex @@ -7,26 +7,29 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Unauthorized do alias OpenApiSpex.Operation alias OpenApiSpex.Schema - OpenApiSpex.schema(%{ - title: "Unauthorized", - type: :object, - additionalProperties: false, - properties: %{ - errors: %Schema{ - type: :array, - items: %Schema{ - type: :object, - properties: %{ - detail: %Schema{ - type: :string, - example: "The requested operation could not be authorized." - }, - title: %Schema{type: :string, example: "Unauthorized"} + OpenApiSpex.schema( + %{ + title: "Unauthorized", + type: :object, + additionalProperties: false, + properties: %{ + errors: %Schema{ + type: :array, + items: %Schema{ + type: :object, + properties: %{ + detail: %Schema{ + type: :string, + example: "The requested operation could not be authorized." + }, + title: %Schema{type: :string, example: "Unauthorized"} + } } } } - } - }) + }, + struct?: false + ) def response do Operation.response( diff --git a/lib/trento_web/openapi/v1/schema/unprocessable_entity.ex b/lib/trento_web/openapi/v1/schema/unprocessable_entity.ex index f1b36365d0..ce109e814f 100644 --- a/lib/trento_web/openapi/v1/schema/unprocessable_entity.ex +++ b/lib/trento_web/openapi/v1/schema/unprocessable_entity.ex @@ -7,24 +7,27 @@ defmodule TrentoWeb.OpenApi.V1.Schema.UnprocessableEntity do alias OpenApiSpex.Operation alias OpenApiSpex.Schema - OpenApiSpex.schema(%{ - type: :object, - additionalProperties: false, - properties: %{ - errors: %Schema{ - type: :array, - items: %Schema{ - type: :object, - properties: %{ - title: %Schema{type: :string, example: "Invalid value"}, - detail: %Schema{type: :string, example: "null value where string expected"} - }, - required: [:title, :detail] + OpenApiSpex.schema( + %{ + type: :object, + additionalProperties: false, + properties: %{ + errors: %Schema{ + type: :array, + items: %Schema{ + type: :object, + properties: %{ + title: %Schema{type: :string, example: "Invalid value"}, + detail: %Schema{type: :string, example: "null value where string expected"} + }, + required: [:title, :detail] + } } - } + }, + required: [:errors] }, - required: [:errors] - }) + struct?: false + ) def response do Operation.response( diff --git a/lib/trento_web/openapi/v1/schema/user.ex b/lib/trento_web/openapi/v1/schema/user.ex index b80391b0a4..a74f20e148 100644 --- a/lib/trento_web/openapi/v1/schema/user.ex +++ b/lib/trento_web/openapi/v1/schema/user.ex @@ -9,201 +9,230 @@ defmodule TrentoWeb.OpenApi.V1.Schema.User do defmodule UserTOTPEnrollmentPayload do @moduledoc false - @schema %Schema{ - title: "UserTOTPEnrollmentPayload", - description: "Trento User TOTP enrollment payload", - type: :object, - additionalProperties: false, - properties: %{ - secret: %Schema{type: :string, description: "TOTP secret", nullable: false}, - secret_qr_encoded: %Schema{ - type: :string, - description: "TOTP secret qr encoded", - nullable: false - } + OpenApiSpex.schema( + %{ + title: "UserTOTPEnrollmentPayload", + description: "Trento User TOTP enrollment payload", + type: :object, + additionalProperties: false, + properties: %{ + secret: %Schema{type: :string, description: "TOTP secret", nullable: false}, + secret_qr_encoded: %Schema{ + type: :string, + description: "TOTP secret qr encoded", + nullable: false + } + }, + required: [:secret, :secret_qr_encoded] }, - required: [:secret, :secret_qr_encoded] - } - - def schema, do: @schema + struct?: false + ) end defmodule UserTOTPEnrollmentConfirmPayload do @moduledoc false - @schema %Schema{ - title: "UserTOTPEnrollmentConfirmPayload", - description: "Trento User TOTP enrollment completed payload", - type: :object, - additionalProperties: false, - properties: %{ - totp_enabled_at: %OpenApiSpex.Schema{ - type: :string, - format: :"date-time", - description: "Date of TOTP enrollment", - nullable: false - } + OpenApiSpex.schema( + %{ + title: "UserTOTPEnrollmentConfirmPayload", + description: "Trento User TOTP enrollment completed payload", + type: :object, + additionalProperties: false, + properties: %{ + totp_enabled_at: %OpenApiSpex.Schema{ + type: :string, + format: :"date-time", + description: "Date of TOTP enrollment", + nullable: false + } + }, + required: [:totp_enabled_at] }, - required: [:totp_enabled_at] - } - - def schema, do: @schema + struct?: false + ) end defmodule UserTOTPEnrollmentConfirmRequest do @moduledoc false - @schema %Schema{ - title: "UserTOTPEnrollmentConfirmRequest", - description: "Trento User totp enrollment confirmation payload", - type: :object, - additionalProperties: false, - properties: %{ - totp_code: %Schema{ - type: :string, - description: "TOTP generated from enrollment secret", - nullable: false - } + OpenApiSpex.schema( + %{ + title: "UserTOTPEnrollmentConfirmRequest", + description: "Trento User totp enrollment confirmation payload", + type: :object, + additionalProperties: false, + properties: %{ + totp_code: %Schema{ + type: :string, + description: "TOTP generated from enrollment secret", + nullable: false + } + }, + required: [:totp_code] }, - required: [:totp_code] - } - - def schema, do: @schema + struct?: false + ) end defmodule UserProfile do @moduledoc false - @schema %Schema{ - title: "UserProfile", - description: "Trento User profile", - type: :object, - additionalProperties: false, - properties: %{ - id: %Schema{type: :integer, description: "User ID", nullable: false}, - fullname: %Schema{type: :string, description: "User full name", nullable: false}, - username: %Schema{type: :string, description: "User username", nullable: false}, - email: %Schema{type: :string, description: "User email", nullable: false, format: :email}, - abilities: AbilityCollection, - password_change_requested: %Schema{ - type: :boolean, - description: "Password change is requested", - nullable: false - }, - totp_enabled: %Schema{ - type: :boolean, - description: "TOTP is enabled", - nullable: false + OpenApiSpex.schema( + %{ + title: "UserProfile", + description: "Trento User profile", + type: :object, + additionalProperties: false, + properties: %{ + id: %Schema{type: :integer, description: "User ID", nullable: false}, + fullname: %Schema{type: :string, description: "User full name", nullable: false}, + username: %Schema{type: :string, description: "User username", nullable: false}, + email: %Schema{ + type: :string, + description: "User email", + nullable: false, + format: :email + }, + abilities: AbilityCollection, + password_change_requested: %Schema{ + type: :boolean, + description: "Password change is requested", + nullable: false + }, + totp_enabled: %Schema{ + type: :boolean, + description: "TOTP is enabled", + nullable: false + }, + created_at: %OpenApiSpex.Schema{ + type: :string, + format: :"date-time", + description: "Date of user creation", + nullable: false + }, + updated_at: %OpenApiSpex.Schema{ + type: :string, + format: :"date-time", + description: "Date of user last update", + nullable: true + } }, - created_at: %OpenApiSpex.Schema{ - type: :string, - format: :"date-time", - description: "Date of user creation", - nullable: false - }, - updated_at: %OpenApiSpex.Schema{ - type: :string, - format: :"date-time", - description: "Date of user last update", - nullable: true - } + required: [:username, :id, :fullname, :email, :created_at, :totp_enabled] }, - required: [:username, :id, :fullname, :email, :created_at, :totp_enabled] - } - - def schema, do: @schema + struct?: false + ) end defmodule UserProfileUpdateRequest do @moduledoc false - @schema %Schema{ - title: "UserProfileUpdateRequest", - description: "Request body to update a user profile", - additionalProperties: false, - type: :object, - properties: %{ - fullname: %Schema{type: :string, description: "User full name", nullable: false}, - email: %Schema{type: :string, description: "User email", nullable: false, format: :email}, - password: %Schema{type: :string, description: "User new password", nullable: false}, - current_password: %Schema{ - type: :string, - description: "User current password, used to set a new password", - nullable: false - }, - password_confirmation: %Schema{ - type: :string, - description: "User new password, should be the same as password field", - nullable: false + OpenApiSpex.schema( + %{ + title: "UserProfileUpdateRequest", + description: "Request body to update a user profile", + additionalProperties: false, + type: :object, + properties: %{ + fullname: %Schema{type: :string, description: "User full name", nullable: false}, + email: %Schema{ + type: :string, + description: "User email", + nullable: false, + format: :email + }, + password: %Schema{type: :string, description: "User new password", nullable: false}, + current_password: %Schema{ + type: :string, + description: "User current password, used to set a new password", + nullable: false + }, + password_confirmation: %Schema{ + type: :string, + description: "User new password, should be the same as password field", + nullable: false + } } - } - } - - def schema, do: @schema + }, + struct?: false + ) end defmodule UserCreationRequest do @moduledoc false - @schema %Schema{ - title: "UserCreationRequest", - description: "Request body to create a user", - type: :object, - additionalProperties: false, - properties: %{ - fullname: %Schema{type: :string, description: "User full name", nullable: false}, - email: %Schema{type: :string, description: "User email", nullable: false, format: :email}, - username: %Schema{type: :string, description: "User username", nullable: false}, - enabled: %Schema{ - type: :boolean, - description: "User enabled in the system", - nullable: false - }, - password: %Schema{type: :string, description: "User new password", nullable: false}, - password_confirmation: %Schema{ - type: :string, - description: "User new password, should be the same as password field", - nullable: false + OpenApiSpex.schema( + %{ + title: "UserCreationRequest", + description: "Request body to create a user", + type: :object, + additionalProperties: false, + properties: %{ + fullname: %Schema{type: :string, description: "User full name", nullable: false}, + email: %Schema{ + type: :string, + description: "User email", + nullable: false, + format: :email + }, + username: %Schema{type: :string, description: "User username", nullable: false}, + enabled: %Schema{ + type: :boolean, + description: "User enabled in the system", + nullable: false + }, + password: %Schema{type: :string, description: "User new password", nullable: false}, + password_confirmation: %Schema{ + type: :string, + description: "User new password, should be the same as password field", + nullable: false + }, + abilities: AbilityCollection }, - abilities: AbilityCollection + required: [:fullname, :email, :enabled, :password, :password_confirmation, :username] }, - required: [:fullname, :email, :enabled, :password, :password_confirmation, :username] - } - - def schema, do: @schema + struct?: false + ) end defmodule UserUpdateRequest do @moduledoc false - @schema %Schema{ - title: "UserUpdateRequest", - description: "Request body to update a user", - type: :object, - additionalProperties: false, - properties: %{ - fullname: %Schema{type: :string, description: "User full name", nullable: false}, - email: %Schema{type: :string, description: "User email", nullable: false, format: :email}, - enabled: %Schema{ - type: :boolean, - description: "User enabled in the system", - nullable: false - }, - password: %Schema{type: :string, description: "User new password", nullable: false}, - password_confirmation: %Schema{ - type: :string, - description: "User new password, should be the same as password field", - nullable: false - }, - abilities: AbilityCollection, - totp_disabled: %Schema{ - type: :boolean, - description: - "TOTP feature disabled for the user. The only accepted value here is 'true'", - nullable: false + OpenApiSpex.schema( + %{ + title: "UserUpdateRequest", + description: "Request body to update a user", + type: :object, + additionalProperties: false, + properties: %{ + fullname: %Schema{type: :string, description: "User full name", nullable: false}, + email: %Schema{ + type: :string, + description: "User email", + nullable: false, + format: :email + }, + enabled: %Schema{ + type: :boolean, + description: "User enabled in the system", + nullable: false + }, + password: %Schema{type: :string, description: "User new password", nullable: false}, + password_confirmation: %Schema{ + type: :string, + description: "User new password, should be the same as password field", + nullable: false + }, + abilities: AbilityCollection, + totp_disabled: %Schema{ + type: :boolean, + description: + "TOTP feature disabled for the user. The only accepted value here is 'true'", + nullable: false + } } - } - } + }, + struct?: false + ) # see: https://github.com/open-api-spex/open_api_spex/issues/87 # This is an alternative way of defining schemas without having to deal to default values @@ -215,65 +244,75 @@ defmodule TrentoWeb.OpenApi.V1.Schema.User do # this means that in the controller the body params are passed as map, without converting from the struct # and we have everything cast and validated BUT without the hassle of cannot distinguish between passed # object keys or not and further conversions in the controller. - def schema, do: @schema end defmodule UserItem do @moduledoc false - OpenApiSpex.schema(%{ - title: "UserItem", - description: "User entity in the system", - type: :object, - additionalProperties: false, - properties: %{ - id: %Schema{type: :integer, description: "User ID", nullable: false}, - fullname: %Schema{type: :string, description: "User full name", nullable: false}, - username: %Schema{type: :string, description: "User username", nullable: false}, - email: %Schema{type: :string, description: "User email", nullable: false, format: :email}, - enabled: %Schema{ - type: :boolean, - description: "User enabled in the system", - nullable: false - }, - abilities: AbilityCollection, - password_change_requested_at: %OpenApiSpex.Schema{ - type: :string, - format: :"date-time", - description: "Date of password change request", - nullable: true - }, - created_at: %OpenApiSpex.Schema{ - type: :string, - format: :"date-time", - description: "Date of user creation", - nullable: false + OpenApiSpex.schema( + %{ + title: "UserItem", + description: "User entity in the system", + type: :object, + additionalProperties: false, + properties: %{ + id: %Schema{type: :integer, description: "User ID", nullable: false}, + fullname: %Schema{type: :string, description: "User full name", nullable: false}, + username: %Schema{type: :string, description: "User username", nullable: false}, + email: %Schema{ + type: :string, + description: "User email", + nullable: false, + format: :email + }, + enabled: %Schema{ + type: :boolean, + description: "User enabled in the system", + nullable: false + }, + abilities: AbilityCollection, + password_change_requested_at: %OpenApiSpex.Schema{ + type: :string, + format: :"date-time", + description: "Date of password change request", + nullable: true + }, + created_at: %OpenApiSpex.Schema{ + type: :string, + format: :"date-time", + description: "Date of user creation", + nullable: false + }, + updated_at: %OpenApiSpex.Schema{ + type: :string, + format: :"date-time", + description: "Date of user last update", + nullable: true + }, + totp_enabled_at: %OpenApiSpex.Schema{ + type: :string, + format: :"date-time", + description: "Date of TOTP enrollment", + nullable: true + } }, - updated_at: %OpenApiSpex.Schema{ - type: :string, - format: :"date-time", - description: "Date of user last update", - nullable: true - }, - totp_enabled_at: %OpenApiSpex.Schema{ - type: :string, - format: :"date-time", - description: "Date of TOTP enrollment", - nullable: true - } + required: [:username, :id, :fullname, :email, :created_at] }, - required: [:username, :id, :fullname, :email, :created_at] - }) + struct?: false + ) end defmodule UserCollection do @moduledoc false - OpenApiSpex.schema(%{ - title: "UserCollection", - description: "A collection of users in the system", - type: :array, - items: UserItem - }) + OpenApiSpex.schema( + %{ + title: "UserCollection", + description: "A collection of users in the system", + type: :array, + items: UserItem + }, + struct?: false + ) end end diff --git a/lib/trento_web/openapi/v2/schema/cluster.ex b/lib/trento_web/openapi/v2/schema/cluster.ex index 6ae868b652..2fde45db38 100644 --- a/lib/trento_web/openapi/v2/schema/cluster.ex +++ b/lib/trento_web/openapi/v2/schema/cluster.ex @@ -13,296 +13,334 @@ defmodule TrentoWeb.OpenApi.V2.Schema.Cluster do defmodule ClusterResource do @moduledoc false - OpenApiSpex.schema(%{ - title: "ClusterResource", - description: "A Cluster Resource", - type: :object, - additionalProperties: false, - properties: %{ - id: %Schema{type: :string}, - type: %Schema{type: :string}, - role: %Schema{type: :string}, - status: %Schema{type: :string}, - fail_count: %Schema{type: :integer}, - managed: %Schema{type: :boolean} - } - }) + OpenApiSpex.schema( + %{ + title: "ClusterResource", + description: "A Cluster Resource", + type: :object, + additionalProperties: false, + properties: %{ + id: %Schema{type: :string}, + type: %Schema{type: :string}, + role: %Schema{type: :string}, + status: %Schema{type: :string}, + fail_count: %Schema{type: :integer}, + managed: %Schema{type: :boolean} + } + }, + struct?: false + ) end defmodule HanaClusterNode do @moduledoc false - OpenApiSpex.schema(%{ - title: "HanaClusterNode", - description: "A HANA Cluster Node", - type: :object, - additionalProperties: false, - properties: %{ - name: %Schema{type: :string}, - site: %Schema{type: :string}, - indexserver_actual_role: %Schema{type: :string, nullable: true}, - nameserver_actual_role: %Schema{type: :string, nullable: true}, - hana_status: %Schema{type: :string, deprecated: true}, - status: %Schema{type: :string}, - attributes: %Schema{ - type: :object, - description: "Node attributes", - additionalProperties: %Schema{type: :string} - }, - virtual_ip: %Schema{type: :string}, - resources: %Schema{ - description: "A list of Cluster resources", - type: :array, - items: ClusterResource + OpenApiSpex.schema( + %{ + title: "HanaClusterNode", + description: "A HANA Cluster Node", + type: :object, + additionalProperties: false, + properties: %{ + name: %Schema{type: :string}, + site: %Schema{type: :string}, + indexserver_actual_role: %Schema{type: :string, nullable: true}, + nameserver_actual_role: %Schema{type: :string, nullable: true}, + hana_status: %Schema{type: :string, deprecated: true}, + status: %Schema{type: :string}, + attributes: %Schema{ + type: :object, + description: "Node attributes", + additionalProperties: %Schema{type: :string} + }, + virtual_ip: %Schema{type: :string}, + resources: %Schema{ + description: "A list of Cluster resources", + type: :array, + items: ClusterResource + } } - } - }) + }, + struct?: false + ) end defmodule HanaClusterSite do @moduledoc false - OpenApiSpex.schema(%{ - title: "HanaClusterSite", - description: "A HANA Cluster Site", - type: :object, - additionalProperties: false, - properties: %{ - name: %Schema{type: :string, description: "Site name"}, - state: %Schema{type: :string, description: "Site state"}, - sr_health_state: %Schema{type: :string, description: "Site SR Health state"} - } - }) + OpenApiSpex.schema( + %{ + title: "HanaClusterSite", + description: "A HANA Cluster Site", + type: :object, + additionalProperties: false, + properties: %{ + name: %Schema{type: :string, description: "Site name"}, + state: %Schema{type: :string, description: "Site state"}, + sr_health_state: %Schema{type: :string, description: "Site SR Health state"} + } + }, + struct?: false + ) end defmodule HanaClusterDetails do @moduledoc false - OpenApiSpex.schema(%{ - title: "HanaClusterDetails", - description: "Details of a HANA Pacemaker Cluster", - type: :object, - additionalProperties: false, - properties: %{ - architecture_type: %Schema{ - type: :string, - description: "HANA architecture type.", - enum: HanaArchitectureType.values() - }, - system_replication_mode: %Schema{type: :string, description: "System Replication Mode"}, - system_replication_operation_mode: %Schema{ - type: :string, - description: "System Replication Operation Mode" - }, - secondary_sync_state: %Schema{type: :string, description: "Secondary Sync State"}, - sr_health_state: %Schema{type: :string, description: "SR health state", deprecated: true}, - fencing_type: %Schema{type: :string, description: "Fencing Type"}, - maintenance_mode: %Schema{ - type: :boolean, - description: "Maintenance mode enabled" - }, - stopped_resources: %Schema{ - description: "A list of the stopped resources on this HANA Cluster", - type: :array, - items: ClusterResource + OpenApiSpex.schema( + %{ + title: "HanaClusterDetails", + description: "Details of a HANA Pacemaker Cluster", + type: :object, + additionalProperties: false, + properties: %{ + architecture_type: %Schema{ + type: :string, + description: "HANA architecture type.", + enum: HanaArchitectureType.values() + }, + system_replication_mode: %Schema{type: :string, description: "System Replication Mode"}, + system_replication_operation_mode: %Schema{ + type: :string, + description: "System Replication Operation Mode" + }, + secondary_sync_state: %Schema{type: :string, description: "Secondary Sync State"}, + sr_health_state: %Schema{ + type: :string, + description: "SR health state", + deprecated: true + }, + fencing_type: %Schema{type: :string, description: "Fencing Type"}, + maintenance_mode: %Schema{ + type: :boolean, + description: "Maintenance mode enabled" + }, + stopped_resources: %Schema{ + description: "A list of the stopped resources on this HANA Cluster", + type: :array, + items: ClusterResource + }, + nodes: %Schema{ + type: :array, + items: HanaClusterNode + }, + sites: %Schema{ + description: "A list of HANA sites", + type: :array, + items: HanaClusterSite + }, + sbd_devices: %Schema{ + type: :array, + items: Cluster.SbdDevice + } }, - nodes: %Schema{ - type: :array, - items: HanaClusterNode - }, - sites: %Schema{ - description: "A list of HANA sites", - type: :array, - items: HanaClusterSite - }, - sbd_devices: %Schema{ - type: :array, - items: Cluster.SbdDevice - } + required: [:nodes] }, - required: [:nodes] - }) + struct?: false + ) end defmodule AscsErsClusterNode do @moduledoc false - OpenApiSpex.schema(%{ - title: "AscsErsClusterNode", - description: "ASCS/ERS Cluster Node", - type: :object, - additionalProperties: false, - properties: %{ - attributes: %Schema{ - type: :object, - description: "Node attributes", - additionalProperties: %Schema{type: :string} - }, - filesystems: %Schema{ - type: :array, - items: %Schema{type: :string}, - description: "List of filesystems managed in this node" - }, - name: %Schema{ - type: :string, - description: "Node name" - }, - status: %Schema{ - type: :string, - description: "Node status" - }, - resources: %Schema{ - type: :array, - items: ClusterResource, - description: "A list of Cluster resources" - }, - roles: %Schema{ - type: :array, - items: %Schema{type: :string, enum: AscsErsClusterRole.values()}, - description: "List of roles managed in this node" - }, - virtual_ips: %Schema{ - type: :array, - items: %Schema{type: :string}, - description: "List of virtual IPs managed in this node" + OpenApiSpex.schema( + %{ + title: "AscsErsClusterNode", + description: "ASCS/ERS Cluster Node", + type: :object, + additionalProperties: false, + properties: %{ + attributes: %Schema{ + type: :object, + description: "Node attributes", + additionalProperties: %Schema{type: :string} + }, + filesystems: %Schema{ + type: :array, + items: %Schema{type: :string}, + description: "List of filesystems managed in this node" + }, + name: %Schema{ + type: :string, + description: "Node name" + }, + status: %Schema{ + type: :string, + description: "Node status" + }, + resources: %Schema{ + type: :array, + items: ClusterResource, + description: "A list of Cluster resources" + }, + roles: %Schema{ + type: :array, + items: %Schema{type: :string, enum: AscsErsClusterRole.values()}, + description: "List of roles managed in this node" + }, + virtual_ips: %Schema{ + type: :array, + items: %Schema{type: :string}, + description: "List of virtual IPs managed in this node" + } } - } - }) + }, + struct?: false + ) end defmodule AscsErsClusterSAPSystem do @moduledoc false - OpenApiSpex.schema(%{ - title: "AscsErsClusterSAPSystem", - description: "SAP system managed by a ASCS/ERS cluster", - type: :object, - additionalProperties: false, - required: [:sid], - properties: %{ - sid: %Schema{type: :string, description: "SID"}, - distributed: %Schema{ - type: :boolean, - description: "ASCS and ERS instances are distributed and running in different nodes" - }, - filesystem_resource_based: %Schema{ - type: :boolean, - description: - "ASCS and ERS filesystems are handled by the cluster with the Filesystem resource agent" - }, - nodes: %Schema{ - type: :array, - items: AscsErsClusterNode, - description: "List of ASCS/ERS nodes for this SAP system" + OpenApiSpex.schema( + %{ + title: "AscsErsClusterSAPSystem", + description: "SAP system managed by a ASCS/ERS cluster", + type: :object, + additionalProperties: false, + required: [:sid], + properties: %{ + sid: %Schema{type: :string, description: "SID"}, + distributed: %Schema{ + type: :boolean, + description: "ASCS and ERS instances are distributed and running in different nodes" + }, + filesystem_resource_based: %Schema{ + type: :boolean, + description: + "ASCS and ERS filesystems are handled by the cluster with the Filesystem resource agent" + }, + nodes: %Schema{ + type: :array, + items: AscsErsClusterNode, + description: "List of ASCS/ERS nodes for this SAP system" + } } - } - }) + }, + struct?: false + ) end defmodule AscsErsClusterDetails do @moduledoc false - OpenApiSpex.schema(%{ - title: "AscsErsClusterDetails", - description: "Details of a ASCS/ERS Pacemaker Cluster", - type: :object, - additionalProperties: false, - properties: %{ - fencing_type: %Schema{ - type: :string, - description: "Fencing type" + OpenApiSpex.schema( + %{ + title: "AscsErsClusterDetails", + description: "Details of a ASCS/ERS Pacemaker Cluster", + type: :object, + additionalProperties: false, + properties: %{ + fencing_type: %Schema{ + type: :string, + description: "Fencing type" + }, + maintenance_mode: %Schema{ + type: :boolean, + description: "Maintenance mode enabled" + }, + sap_systems: %Schema{ + type: :array, + items: AscsErsClusterSAPSystem, + description: "List of managed SAP systems in a single or multi SID cluster" + }, + sbd_devices: %Schema{ + type: :array, + items: Cluster.SbdDevice, + description: "List of SBD devices used in the cluster" + }, + stopped_resources: %Schema{ + type: :array, + items: ClusterResource, + description: "List of the stopped resources on this HANA Cluster" + } }, - maintenance_mode: %Schema{ - type: :boolean, - description: "Maintenance mode enabled" - }, - sap_systems: %Schema{ - type: :array, - items: AscsErsClusterSAPSystem, - description: "List of managed SAP systems in a single or multi SID cluster" - }, - sbd_devices: %Schema{ - type: :array, - items: Cluster.SbdDevice, - description: "List of SBD devices used in the cluster" - }, - stopped_resources: %Schema{ - type: :array, - items: ClusterResource, - description: "List of the stopped resources on this HANA Cluster" - } + required: [:sap_systems] }, - required: [:sap_systems] - }) + struct?: false + ) end defmodule Details do @moduledoc false - OpenApiSpex.schema(%{ - title: "PacemakerClusterDetails", - description: "Details of the detected PacemakerCluster", - nullable: true, - oneOf: [ - AscsErsClusterDetails, - HanaClusterDetails - ] - }) + OpenApiSpex.schema( + %{ + title: "PacemakerClusterDetails", + description: "Details of the detected PacemakerCluster", + nullable: true, + oneOf: [ + AscsErsClusterDetails, + HanaClusterDetails + ] + }, + struct?: false + ) end defmodule PacemakerCluster do @moduledoc false - OpenApiSpex.schema(%{ - title: "PacemakerCluster", - description: "A discovered Pacemaker Cluster on the target infrastructure", - type: :object, - additionalProperties: false, - properties: %{ - id: %Schema{type: :string, description: "Cluster ID", format: :uuid}, - name: %Schema{type: :string, description: "Cluster name"}, - sid: %Schema{type: :string, description: "SID"}, - additional_sids: %Schema{ - type: :array, - items: %Schema{type: :string}, - description: "Additionally discovered SIDs, such as ASCS/ERS cluster SIDs" - }, - provider: Provider.SupportedProviders, - type: %Schema{ - type: :string, - description: "Detected type of the cluster", - enum: ClusterType.values() - }, - selected_checks: %Schema{ - title: "SelectedChecks", - description: "A list of check ids selected for an execution on this cluster", - type: :array, - items: %Schema{type: :string} - }, - health: ResourceHealth, - resources_number: %Schema{type: :integer, description: "Resource number", nullable: true}, - hosts_number: %Schema{type: :integer, description: "Hosts number", nullable: true}, - cib_last_written: %Schema{ - type: :string, - description: "CIB last written date", - nullable: true - }, - details: Details, - tags: Tags, - inserted_at: %Schema{type: :string, format: :datetime}, - updated_at: %Schema{type: :string, format: :datetime, nullable: true} - } - }) + OpenApiSpex.schema( + %{ + title: "PacemakerCluster", + description: "A discovered Pacemaker Cluster on the target infrastructure", + type: :object, + additionalProperties: false, + properties: %{ + id: %Schema{type: :string, description: "Cluster ID", format: :uuid}, + name: %Schema{type: :string, description: "Cluster name"}, + sid: %Schema{type: :string, description: "SID"}, + additional_sids: %Schema{ + type: :array, + items: %Schema{type: :string}, + description: "Additionally discovered SIDs, such as ASCS/ERS cluster SIDs" + }, + provider: Provider.SupportedProviders, + type: %Schema{ + type: :string, + description: "Detected type of the cluster", + enum: ClusterType.values() + }, + selected_checks: %Schema{ + title: "SelectedChecks", + description: "A list of check ids selected for an execution on this cluster", + type: :array, + items: %Schema{type: :string} + }, + health: ResourceHealth, + resources_number: %Schema{ + type: :integer, + description: "Resource number", + nullable: true + }, + hosts_number: %Schema{type: :integer, description: "Hosts number", nullable: true}, + cib_last_written: %Schema{ + type: :string, + description: "CIB last written date", + nullable: true + }, + details: Details, + tags: Tags, + inserted_at: %Schema{type: :string, format: :datetime}, + updated_at: %Schema{type: :string, format: :datetime, nullable: true} + } + }, + struct?: false + ) end defmodule PacemakerClustersCollection do @moduledoc false - OpenApiSpex.schema(%{ - title: "PacemakerClustersCollection", - description: "A list of the discovered Pacemaker Clusters", - type: :array, - items: PacemakerCluster - }) + OpenApiSpex.schema( + %{ + title: "PacemakerClustersCollection", + description: "A list of the discovered Pacemaker Clusters", + type: :array, + items: PacemakerCluster + }, + struct?: false + ) end end diff --git a/mix.exs b/mix.exs index 62290e4b17..784b7cc147 100644 --- a/mix.exs +++ b/mix.exs @@ -80,7 +80,7 @@ defmodule Trento.MixProject do {:httpoison, "~> 2.0"}, {:jason, "~> 1.2"}, {:mox, "~> 1.0", only: :test}, - {:open_api_spex, "~> 3.11"}, + {:open_api_spex, "~> 3.19.1"}, {:phoenix, "~> 1.6.2"}, {:phoenix_ecto, "~> 4.4"}, {:phoenix_html, "~> 3.0"}, diff --git a/mix.lock b/mix.lock index 82f06c9610..4f6b7b6270 100644 --- a/mix.lock +++ b/mix.lock @@ -52,7 +52,7 @@ "hackney": {:hex, :hackney, "1.20.1", "8d97aec62ddddd757d128bfd1df6c5861093419f8f7a4223823537bad5d064e2", [:rebar3], [{:certifi, "~> 2.12.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~> 6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~> 1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~> 1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.4.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~> 1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "fe9094e5f1a2a2c0a7d10918fee36bfec0ec2a979994cff8cfe8058cd9af38e3"}, "httpoison": {:hex, :httpoison, "2.2.1", "87b7ed6d95db0389f7df02779644171d7319d319178f6680438167d7b69b1f3d", [:mix], [{:hackney, "~> 1.17", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "51364e6d2f429d80e14fe4b5f8e39719cacd03eb3f9a9286e61e216feac2d2df"}, "idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"}, - "jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"}, + "jason": {:hex, :jason, "1.4.3", "d3f984eeb96fe53b85d20e0b049f03e57d075b5acda3ac8d465c969a2536c17b", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "9a90e868927f7c777689baa16d86f4d0e086d968db5c05d917ccff6d443e58a3"}, "joken": {:hex, :joken, "2.5.0", "09be497d804b8115eb6f07615cef2e60c2a1008fb89dc0aef0d4c4b4609b99aa", [:mix], [{:jose, "~> 1.11.2", [hex: :jose, repo: "hexpm", optional: false]}], "hexpm", "22b25c89617c5ed8ca7b31026340a25ea0f9ca7160f9706b79be9ed81fdf74e7"}, "jose": {:hex, :jose, "1.11.6", "613fda82552128aa6fb804682e3a616f4bc15565a048dabd05b1ebd5827ed965", [:mix, :rebar3], [], "hexpm", "6275cb75504f9c1e60eeacb771adfeee4905a9e182103aa59b53fed651ff9738"}, "luhn": {:hex, :luhn, "0.3.3", "5aa0c6a32c2db4b9db9f9b883ba8301c1ae169d57199b9e6cb1ba2707bc51d96", [:mix], [], "hexpm", "3e823a913a25aab51352c727f135278d22954874d5f0835be81ed4fec3daf78d"}, @@ -60,12 +60,12 @@ "makeup_elixir": {:hex, :makeup_elixir, "0.16.1", "cc9e3ca312f1cfeccc572b37a09980287e243648108384b97ff2b76e505c3555", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "e127a341ad1b209bd80f7bd1620a15693a9908ed780c3b763bccf7d200c767c6"}, "makeup_erlang": {:hex, :makeup_erlang, "0.1.3", "d684f4bac8690e70b06eb52dad65d26de2eefa44cd19d64a8095e1417df7c8fd", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "b78dc853d2e670ff6390b605d807263bf606da3c82be37f9d7f68635bd886fc9"}, "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"}, - "mime": {:hex, :mime, "2.0.5", "dc34c8efd439abe6ae0343edbb8556f4d63f178594894720607772a041b04b02", [:mix], [], "hexpm", "da0d64a365c45bc9935cc5c8a7fc5e49a0e0f9932a761c55d6c52b142780a05c"}, + "mime": {:hex, :mime, "2.0.6", "8f18486773d9b15f95f4f4f1e39b710045fa1de891fada4516559967276e4dc2", [:mix], [], "hexpm", "c9945363a6b26d747389aac3643f8e0e09d30499a138ad64fe8fd1d13d9b153e"}, "mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"}, "mox": {:hex, :mox, "1.1.0", "0f5e399649ce9ab7602f72e718305c0f9cdc351190f72844599545e4996af73c", [:mix], [], "hexpm", "d44474c50be02d5b72131070281a5d3895c0e7a95c780e90bc0cfe712f633a13"}, "nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"}, "nimble_totp": {:hex, :nimble_totp, "1.0.0", "79753bae6ce59fd7cacdb21501a1dbac249e53a51c4cd22b34fa8438ee067283", [:mix], [], "hexpm", "6ce5e4c068feecdb782e85b18237f86f66541523e6bad123e02ee1adbe48eda9"}, - "open_api_spex": {:hex, :open_api_spex, "3.18.1", "0a73cd5dbcba7d32952dd9738c6819892933d9bae1642f04c9f200281524dd31", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}, {:poison, "~> 3.0 or ~> 4.0 or ~> 5.0", [hex: :poison, repo: "hexpm", optional: true]}, {:ymlr, "~> 2.0 or ~> 3.0 or ~> 4.0", [hex: :ymlr, repo: "hexpm", optional: true]}], "hexpm", "f52933cddecca675e42ead660379ae2d3853f57f5a35d201eaed85e2e81517d1"}, + "open_api_spex": {:hex, :open_api_spex, "3.19.1", "65ccb5d06e3d664d1eec7c5ea2af2289bd2f37897094a74d7219fb03fc2b5994", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}, {:poison, "~> 3.0 or ~> 4.0 or ~> 5.0", [hex: :poison, repo: "hexpm", optional: true]}, {:ymlr, "~> 2.0 or ~> 3.0 or ~> 4.0 or ~> 5.0", [hex: :ymlr, repo: "hexpm", optional: true]}], "hexpm", "392895827ce2984a3459c91a484e70708132d8c2c6c5363972b4b91d6bbac3dd"}, "parallel_stream": {:hex, :parallel_stream, "1.1.0", "f52f73eb344bc22de335992377413138405796e0d0ad99d995d9977ac29f1ca9", [:mix], [], "hexpm", "684fd19191aedfaf387bbabbeb8ff3c752f0220c8112eb907d797f4592d6e871"}, "parse_trans": {:hex, :parse_trans, "3.4.1", "6e6aa8167cb44cc8f39441d05193be6e6f4e7c2946cb2759f015f8c56b76e5ff", [:rebar3], [], "hexpm", "620a406ce75dada827b82e453c19cf06776be266f5a67cff34e1ef2cbb60e49a"}, "phoenix": {:hex, :phoenix, "1.6.16", "e5bdd18c7a06da5852a25c7befb72246de4ddc289182285f8685a40b7b5f5451", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 1.0 or ~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.2", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "e15989ff34f670a96b95ef6d1d25bad0d9c50df5df40b671d8f4a669e050ac39"}, @@ -78,7 +78,7 @@ "phoenix_swoosh": {:hex, :phoenix_swoosh, "1.2.1", "b74ccaa8046fbc388a62134360ee7d9742d5a8ae74063f34eb050279de7a99e1", [:mix], [{:finch, "~> 0.8", [hex: :finch, repo: "hexpm", optional: true]}, {:hackney, "~> 1.10", [hex: :hackney, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.6", [hex: :phoenix, repo: "hexpm", optional: true]}, {:phoenix_html, "~> 3.0 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:phoenix_view, "~> 1.0 or ~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: false]}, {:swoosh, "~> 1.5", [hex: :swoosh, repo: "hexpm", optional: false]}], "hexpm", "4000eeba3f9d7d1a6bf56d2bd56733d5cadf41a7f0d8ffe5bb67e7d667e204a2"}, "phoenix_template": {:hex, :phoenix_template, "1.0.4", "e2092c132f3b5e5b2d49c96695342eb36d0ed514c5b252a77048d5969330d639", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "2c0c81f0e5c6753faf5cca2f229c9709919aba34fab866d3bc05060c9c444206"}, "phoenix_view": {:hex, :phoenix_view, "2.0.3", "4d32c4817fce933693741deeb99ef1392619f942633dde834a5163124813aad3", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}], "hexpm", "cd34049af41be2c627df99cd4eaa71fc52a328c0c3d8e7d4aa28f880c30e7f64"}, - "plug": {:hex, :plug, "1.15.3", "712976f504418f6dff0a3e554c40d705a9bcf89a7ccef92fc6a5ef8f16a30a97", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "cc4365a3c010a56af402e0809208873d113e9c38c401cabd88027ef4f5c01fd2"}, + "plug": {:hex, :plug, "1.16.1", "40c74619c12f82736d2214557dedec2e9762029b2438d6d175c5074c933edc9d", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "a13ff6b9006b03d7e33874945b2755253841b238c34071ed85b0e86057f8cddc"}, "plug_cowboy": {:hex, :plug_cowboy, "2.6.1", "9a3bbfceeb65eff5f39dab529e5cd79137ac36e913c02067dba3963a26efe9b2", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "de36e1a21f451a18b790f37765db198075c25875c64834bcc82d90b309eb6613"}, "plug_crypto": {:hex, :plug_crypto, "1.2.5", "918772575e48e81e455818229bf719d4ab4181fcbf7f85b68a35620f78d89ced", [:mix], [], "hexpm", "26549a1d6345e2172eb1c233866756ae44a9609bd33ee6f99147ab3fd87fd842"}, "polymorphic_embed": {:hex, :polymorphic_embed, "2.0.1", "dadda9c6362054b9d82c58f70d5b3ade23775209990e79ee41fc662d1c255edf", [:mix], [{:ecto, "~> 3.8", [hex: :ecto, repo: "hexpm", optional: false]}, {:jason, "~> 1.3", [hex: :jason, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14 or ~> 3.2", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "337716c36aa6539729f738eb6e0555659b1d38b70225641274a67eb17570b820"}, diff --git a/test/e2e/cypress/e2e/users.cy.js b/test/e2e/cypress/e2e/users.cy.js index 374a67b9a7..18170c0693 100644 --- a/test/e2e/cypress/e2e/users.cy.js +++ b/test/e2e/cypress/e2e/users.cy.js @@ -259,7 +259,7 @@ describe('Users', () => { it('should see Users entry in sidebar when the all:users ability is given', () => { getProfile(USER.username, PASSWORD).then(({ id }) => { patchUser(id, { - abilities: [{ id: 2, name: 'all', resource: 'users' }], + abilities: [{ id: 2, name: 'all', resource: 'users', label: 'test' }], }); }); cy.contains('Users'); diff --git a/test/trento/activity_log_test.exs b/test/trento/activity_log_test.exs index b3c8fdf2d7..083f9ae4eb 100644 --- a/test/trento/activity_log_test.exs +++ b/test/trento/activity_log_test.exs @@ -18,7 +18,7 @@ defmodule Trento.ActivityLogTest do describe "retrieving activity log settings" do test "should return an error when settings are not available" do - assert {:error, :activity_log_settings_not_configured} == ActivityLog.get_settings() + assert {:error, :not_found} == ActivityLog.get_settings() end test "should return settings" do diff --git a/test/trento_web/controllers/v1/suse_manager_controller_test.exs b/test/trento_web/controllers/v1/suse_manager_controller_test.exs index e26eae7ae9..234948e3c8 100644 --- a/test/trento_web/controllers/v1/suse_manager_controller_test.exs +++ b/test/trento_web/controllers/v1/suse_manager_controller_test.exs @@ -8,15 +8,6 @@ defmodule TrentoWeb.V1.SUSEManagerControllerTest do alias TrentoWeb.OpenApi.V1.ApiSpec - alias TrentoWeb.OpenApi.V1.Schema.AvailableSoftwareUpdates.{ - AvailableSoftwareUpdatesResponse, - ErrataDetailsResponse, - PatchesForPackage, - PatchesForPackagesResponse, - RelevantPatch, - UpgradablePackage - } - setup do %{api_spec: ApiSpec.spec()} end @@ -44,20 +35,20 @@ defmodule TrentoWeb.V1.SUSEManagerControllerTest do upgradable_packages: upgradable_packages ) - %AvailableSoftwareUpdatesResponse{ + %{ relevant_patches: [ - %RelevantPatch{ + %{ id: 4182 }, - %RelevantPatch{ + %{ id: 4174 } ], upgradable_packages: [ - %UpgradablePackage{ + %{ name: "elixir" }, - %UpgradablePackage{ + %{ name: "systemd" } ] @@ -105,10 +96,10 @@ defmodule TrentoWeb.V1.SUSEManagerControllerTest do {:ok, build_list(10, :patch_for_package)} end) - %PatchesForPackagesResponse{ + %{ patches: [ - %PatchesForPackage{package_id: _, patches: _}, - %PatchesForPackage{package_id: _, patches: _} + %{package_id: _, patches: _}, + %{package_id: _, patches: _} ] } = conn @@ -126,10 +117,10 @@ defmodule TrentoWeb.V1.SUSEManagerControllerTest do {:error, :error_getting_patches} end) - %PatchesForPackagesResponse{ + %{ patches: [ - %PatchesForPackage{package_id: _, patches: []}, - %PatchesForPackage{package_id: _, patches: []} + %{package_id: _, patches: []}, + %{package_id: _, patches: []} ] } = conn @@ -209,7 +200,7 @@ defmodule TrentoWeb.V1.SUSEManagerControllerTest do result = assert_schema(json, "ErrataDetailsResponse", api_spec) - %ErrataDetailsResponse{ + %{ errata_details: %{ id: ^id, issue_date: ^issue_date,