From ff64338d1bc7bbf7b8dd30181fe6a2900a638675 Mon Sep 17 00:00:00 2001 From: Carmine Di Monaco Date: Thu, 22 Feb 2024 11:36:35 +0100 Subject: [PATCH] Openapi schemas no additional properties (#2355) * Add additionalProperties false to openapi schema objects * Cluster v1/v2 controller tests and view refactored for openapi compatibility * HealthOverview controller refactored for openapi compatibility * Host views aligned with openapi spex * Sap system view adapted to sap system controller openapi * Fixed Host schema v1 * mix credo fix * Revert "HealthOverview controller refactored for openapi compatibility" This reverts commit 8869575a61fbc24515b15cb50c557a426e9662d2. * Addressing review feedbacks * Temporary fix incompatible api check * Revert "Temporary fix incompatible api check" This reverts commit 2df1abd3f43a31b77767e6195adaca3d497e9368. --- .../openapi/v1/schema/bad_request.ex | 1 + lib/trento_web/openapi/v1/schema/chart.ex | 3 ++ lib/trento_web/openapi/v1/schema/checks.ex | 1 + .../openapi/v1/schema/checks_catalog.ex | 5 +++ lib/trento_web/openapi/v1/schema/cluster.ex | 5 +++ lib/trento_web/openapi/v1/schema/database.ex | 8 +++++ .../openapi/v1/schema/discovery_event.ex | 1 + lib/trento_web/openapi/v1/schema/health.ex | 1 + lib/trento_web/openapi/v1/schema/host.ex | 16 +++++++++- lib/trento_web/openapi/v1/schema/http_std.ex | 1 + lib/trento_web/openapi/v1/schema/not_found.ex | 1 + lib/trento_web/openapi/v1/schema/platform.ex | 2 ++ lib/trento_web/openapi/v1/schema/provider.ex | 3 ++ lib/trento_web/openapi/v1/schema/ready.ex | 1 + .../openapi/v1/schema/sap_system.ex | 11 ++++++- .../openapi/v1/schema/saptune_status.ex | 5 +++ .../openapi/v1/schema/sles_subscription.ex | 1 + .../openapi/v1/schema/suma_credentials.ex | 3 ++ lib/trento_web/openapi/v1/schema/tag.ex | 1 + .../openapi/v1/schema/unprocessable_entity.ex | 1 + lib/trento_web/openapi/v2/schema/cluster.ex | 9 ++++++ lib/trento_web/views/v1/cluster_view.ex | 1 + lib/trento_web/views/v1/host_view.ex | 32 ++++++++++++++++--- lib/trento_web/views/v1/sap_system_view.ex | 2 ++ lib/trento_web/views/v2/cluster_view.ex | 1 + test/trento_web/views/v1/host_view_test.exs | 9 ++++++ 26 files changed, 119 insertions(+), 6 deletions(-) diff --git a/lib/trento_web/openapi/v1/schema/bad_request.ex b/lib/trento_web/openapi/v1/schema/bad_request.ex index 76bac363b8..cc42b36eda 100644 --- a/lib/trento_web/openapi/v1/schema/bad_request.ex +++ b/lib/trento_web/openapi/v1/schema/bad_request.ex @@ -11,6 +11,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.BadRequest do OpenApiSpex.schema(%{ title: "BadRequest", type: :object, + additionalProperties: false, properties: %{ errors: %Schema{ type: :array, diff --git a/lib/trento_web/openapi/v1/schema/chart.ex b/lib/trento_web/openapi/v1/schema/chart.ex index cf887178c1..7313dbb47d 100644 --- a/lib/trento_web/openapi/v1/schema/chart.ex +++ b/lib/trento_web/openapi/v1/schema/chart.ex @@ -11,6 +11,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Chart do 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{ @@ -43,6 +44,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Chart do OpenApiSpex.schema(%{ title: "HostCpuChart", + additionalProperties: false, description: "A Time Series chart with information about the cpu usage of a host", type: :object, properties: %{ @@ -63,6 +65,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Chart do 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, diff --git a/lib/trento_web/openapi/v1/schema/checks.ex b/lib/trento_web/openapi/v1/schema/checks.ex index d83b7d741b..b2a23ea88a 100644 --- a/lib/trento_web/openapi/v1/schema/checks.ex +++ b/lib/trento_web/openapi/v1/schema/checks.ex @@ -6,6 +6,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Checks.ChecksSelectionRequest do 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{ diff --git a/lib/trento_web/openapi/v1/schema/checks_catalog.ex b/lib/trento_web/openapi/v1/schema/checks_catalog.ex index 77934366f9..a10bfc2c27 100644 --- a/lib/trento_web/openapi/v1/schema/checks_catalog.ex +++ b/lib/trento_web/openapi/v1/schema/checks_catalog.ex @@ -13,6 +13,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.ChecksCatalog do 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"}, @@ -50,6 +51,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.ChecksCatalog do OpenApiSpex.schema(%{ title: "ChecksGroup", description: "A Group of related Checks (Corosync, Pacemaker ...)", + additionalProperties: false, type: :object, properties: %{ group: %Schema{type: :string, description: "Group Name"}, @@ -64,6 +66,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.ChecksCatalog do OpenApiSpex.schema(%{ title: "ProviderCatalog", description: "A Provider specific Catalog, and respective values", + additionalProperties: false, type: :object, properties: %{ provider: %Schema{ @@ -164,6 +167,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.ChecksCatalog do OpenApiSpex.schema(%{ title: "CatalogNotfound", description: "No Catalog was found for the provided query", + additionalProperties: false, type: :object, properties: %{ error: %Schema{ @@ -181,6 +185,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.ChecksCatalog do 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"} diff --git a/lib/trento_web/openapi/v1/schema/cluster.ex b/lib/trento_web/openapi/v1/schema/cluster.ex index 45d9a17993..71cff22b76 100644 --- a/lib/trento_web/openapi/v1/schema/cluster.ex +++ b/lib/trento_web/openapi/v1/schema/cluster.ex @@ -14,6 +14,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Cluster do title: "ClusterResource", description: "A Cluster Resource", type: :object, + additionalProperties: false, properties: %{ id: %Schema{type: :string}, type: %Schema{type: :string}, @@ -30,6 +31,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Cluster do OpenApiSpex.schema(%{ title: "HanaClusterNode", description: "A HANA Cluster Node", + additionalProperties: false, type: :object, properties: %{ name: %Schema{type: :string}, @@ -56,6 +58,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Cluster do OpenApiSpex.schema(%{ title: "SbdDevice", description: "SBD Device", + additionalProperties: false, type: :object, properties: %{ device: %Schema{type: :string}, @@ -71,6 +74,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Cluster do 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{ @@ -118,6 +122,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Cluster do 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"}, diff --git a/lib/trento_web/openapi/v1/schema/database.ex b/lib/trento_web/openapi/v1/schema/database.ex index 62dde505a0..38543e76ed 100644 --- a/lib/trento_web/openapi/v1/schema/database.ex +++ b/lib/trento_web/openapi/v1/schema/database.ex @@ -13,6 +13,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Database do 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}, sid: %Schema{type: :string, description: "SID"}, @@ -23,6 +24,12 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Database do 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}, @@ -65,6 +72,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Database do 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"}, diff --git a/lib/trento_web/openapi/v1/schema/discovery_event.ex b/lib/trento_web/openapi/v1/schema/discovery_event.ex index 2ff910ac2a..0ef0b78f49 100644 --- a/lib/trento_web/openapi/v1/schema/discovery_event.ex +++ b/lib/trento_web/openapi/v1/schema/discovery_event.ex @@ -9,6 +9,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.DiscoveryEvent do title: "DiscoveryEvent", description: "A discovery event", type: :object, + additionalProperties: false, properties: %{ agent_id: %Schema{type: :string, format: :uuid}, discovery_type: %Schema{type: :string}, diff --git a/lib/trento_web/openapi/v1/schema/health.ex b/lib/trento_web/openapi/v1/schema/health.ex index a2ebc3012d..d1617f1eae 100644 --- a/lib/trento_web/openapi/v1/schema/health.ex +++ b/lib/trento_web/openapi/v1/schema/health.ex @@ -13,6 +13,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Health do example: %{ database: "pass" }, + additionalProperties: false, properties: %{ database: %Schema{ description: "The status of the database connection", diff --git a/lib/trento_web/openapi/v1/schema/host.ex b/lib/trento_web/openapi/v1/schema/host.ex index 095202928a..a010cd3f4d 100644 --- a/lib/trento_web/openapi/v1/schema/host.ex +++ b/lib/trento_web/openapi/v1/schema/host.ex @@ -4,7 +4,13 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Host do require OpenApiSpex alias OpenApiSpex.Schema - alias TrentoWeb.OpenApi.V1.Schema.{Provider, SaptuneStatus, SlesSubscription, Tags} + alias TrentoWeb.OpenApi.V1.Schema.{ + Provider, + ResourceHealth, + SaptuneStatus, + SlesSubscription, + Tags + } defmodule IPv4 do @moduledoc false @@ -33,6 +39,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Host do 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"}, @@ -51,6 +58,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Host do 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", @@ -70,6 +78,12 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Host do 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", diff --git a/lib/trento_web/openapi/v1/schema/http_std.ex b/lib/trento_web/openapi/v1/schema/http_std.ex index 241c69cb10..fb47b534ee 100644 --- a/lib/trento_web/openapi/v1/schema/http_std.ex +++ b/lib/trento_web/openapi/v1/schema/http_std.ex @@ -16,6 +16,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.HttpStd do "labelname" => "mylabel" } }, + additionalProperties: false, properties: %{ labels: %Schema{ type: :object, diff --git a/lib/trento_web/openapi/v1/schema/not_found.ex b/lib/trento_web/openapi/v1/schema/not_found.ex index 536b2d4e3d..4e6c07f04a 100644 --- a/lib/trento_web/openapi/v1/schema/not_found.ex +++ b/lib/trento_web/openapi/v1/schema/not_found.ex @@ -10,6 +10,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.NotFound do OpenApiSpex.schema(%{ title: "NotFound", type: :object, + additionalProperties: false, properties: %{ errors: %Schema{ type: :array, diff --git a/lib/trento_web/openapi/v1/schema/platform.ex b/lib/trento_web/openapi/v1/schema/platform.ex index d4afe8c1e2..157760e5e4 100644 --- a/lib/trento_web/openapi/v1/schema/platform.ex +++ b/lib/trento_web/openapi/v1/schema/platform.ex @@ -11,6 +11,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Platform do title: "PlatformSettings", description: "Settings values for the current installation", type: :object, + additionalProperties: false, properties: %{ eula_accepted: %Schema{ type: :boolean, @@ -31,6 +32,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Platform do title: "GeneralInformation", description: "General information about the current installation", type: :object, + additionalProperties: false, properties: %{ flavor: %Schema{ type: :string, diff --git a/lib/trento_web/openapi/v1/schema/provider.ex b/lib/trento_web/openapi/v1/schema/provider.ex index 0cbcbc343a..d282b96414 100644 --- a/lib/trento_web/openapi/v1/schema/provider.ex +++ b/lib/trento_web/openapi/v1/schema/provider.ex @@ -35,6 +35,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Provider do title: "AzureProviderData", description: "Azure detected metadata", type: :object, + additionalProperties: false, properties: %{ resource_group: %Schema{type: :string}, location: %Schema{type: :string}, @@ -54,6 +55,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Provider do title: "AwsProviderData", description: "AWS detected metadata", type: :object, + additionalProperties: false, properties: %{ account_id: %Schema{type: :string}, ami_id: %Schema{type: :string}, @@ -74,6 +76,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Provider do title: "GcpProviderData", description: "GCP detected metadata", type: :object, + additionalProperties: false, properties: %{ disk_number: %Schema{type: :integer}, image: %Schema{type: :string}, diff --git a/lib/trento_web/openapi/v1/schema/ready.ex b/lib/trento_web/openapi/v1/schema/ready.ex index b8e64f08de..68fe848e02 100644 --- a/lib/trento_web/openapi/v1/schema/ready.ex +++ b/lib/trento_web/openapi/v1/schema/ready.ex @@ -13,6 +13,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Ready do example: %{ ready: true }, + additionalProperties: false, properties: %{ ready: %Schema{ description: "Trento Web platform ready", diff --git a/lib/trento_web/openapi/v1/schema/sap_system.ex b/lib/trento_web/openapi/v1/schema/sap_system.ex index f829c80748..23c734727e 100644 --- a/lib/trento_web/openapi/v1/schema/sap_system.ex +++ b/lib/trento_web/openapi/v1/schema/sap_system.ex @@ -15,6 +15,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.SAPSystem do 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"}, @@ -24,6 +25,12 @@ defmodule TrentoWeb.OpenApi.V1.Schema.SAPSystem do 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}, @@ -49,6 +56,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.SAPSystem do 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"}, @@ -90,6 +98,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.SAPSystem do 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"}, @@ -113,7 +122,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.SAPSystem do sapsystem_health: ResourceHealth, database_health: ResourceHealth, hosts_health: ResourceHealth, - clusters_heatlh: %Schema{ + clusters_health: %Schema{ allOf: [ ResourceHealth, %Schema{deprecated: true} diff --git a/lib/trento_web/openapi/v1/schema/saptune_status.ex b/lib/trento_web/openapi/v1/schema/saptune_status.ex index 43547ce93f..98319a4d9c 100644 --- a/lib/trento_web/openapi/v1/schema/saptune_status.ex +++ b/lib/trento_web/openapi/v1/schema/saptune_status.ex @@ -12,6 +12,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.SaptuneStatus do title: "Saptune service", description: "Saptune service", type: :object, + additionalProperties: false, properties: %{ name: %Schema{ type: :string, @@ -36,6 +37,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.SaptuneStatus do title: "Saptune note", description: "Saptune note", type: :object, + additionalProperties: false, properties: %{ id: %Schema{ type: :string, @@ -56,6 +58,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.SaptuneStatus do title: "Saptune solution", description: "Saptune solution", type: :object, + additionalProperties: false, properties: %{ id: %Schema{ type: :boolean, @@ -81,6 +84,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.SaptuneStatus do title: "Saptune staging", description: "Saptune staging data", type: :object, + additionalProperties: false, properties: %{ enabled: %Schema{ type: :boolean, @@ -105,6 +109,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.SaptuneStatus do 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"}, diff --git a/lib/trento_web/openapi/v1/schema/sles_subscription.ex b/lib/trento_web/openapi/v1/schema/sles_subscription.ex index a096ce013c..a9dcfdccef 100644 --- a/lib/trento_web/openapi/v1/schema/sles_subscription.ex +++ b/lib/trento_web/openapi/v1/schema/sles_subscription.ex @@ -8,6 +8,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.SlesSubscription do 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}, diff --git a/lib/trento_web/openapi/v1/schema/suma_credentials.ex b/lib/trento_web/openapi/v1/schema/suma_credentials.ex index 42b2d71e72..5125518625 100644 --- a/lib/trento_web/openapi/v1/schema/suma_credentials.ex +++ b/lib/trento_web/openapi/v1/schema/suma_credentials.ex @@ -11,6 +11,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.SUMACredentials do title: "SaveSUMACredentialsRequest", description: "Request body for saving SUMA credentials", type: :object, + additionalProperties: false, properties: %{ url: %Schema{ type: :string @@ -39,6 +40,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.SUMACredentials do "Request body for updating SUMA credentials.\nOnly provide fields to be updated", type: :object, minProperties: 1, + additionalProperties: false, properties: %{ url: %Schema{ type: :string @@ -66,6 +68,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.SUMACredentials do title: "SUMACredentials", description: "User settings for SUSE Manager", type: :object, + additionalProperties: false, properties: %{ url: %Schema{ type: :string, diff --git a/lib/trento_web/openapi/v1/schema/tag.ex b/lib/trento_web/openapi/v1/schema/tag.ex index 6f9a63375c..7a628423aa 100644 --- a/lib/trento_web/openapi/v1/schema/tag.ex +++ b/lib/trento_web/openapi/v1/schema/tag.ex @@ -13,6 +13,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Tags do 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}, diff --git a/lib/trento_web/openapi/v1/schema/unprocessable_entity.ex b/lib/trento_web/openapi/v1/schema/unprocessable_entity.ex index e9cd04121d..f1b36365d0 100644 --- a/lib/trento_web/openapi/v1/schema/unprocessable_entity.ex +++ b/lib/trento_web/openapi/v1/schema/unprocessable_entity.ex @@ -9,6 +9,7 @@ defmodule TrentoWeb.OpenApi.V1.Schema.UnprocessableEntity do OpenApiSpex.schema(%{ type: :object, + additionalProperties: false, properties: %{ errors: %Schema{ type: :array, diff --git a/lib/trento_web/openapi/v2/schema/cluster.ex b/lib/trento_web/openapi/v2/schema/cluster.ex index c0ae90d137..2e6162602f 100644 --- a/lib/trento_web/openapi/v2/schema/cluster.ex +++ b/lib/trento_web/openapi/v2/schema/cluster.ex @@ -16,6 +16,7 @@ defmodule TrentoWeb.OpenApi.V2.Schema.Cluster do title: "HanaClusterNode", description: "A HANA Cluster Node", type: :object, + additionalProperties: false, properties: %{ name: %Schema{type: :string}, site: %Schema{type: :string}, @@ -44,6 +45,7 @@ defmodule TrentoWeb.OpenApi.V2.Schema.Cluster do 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"}, @@ -59,6 +61,7 @@ defmodule TrentoWeb.OpenApi.V2.Schema.Cluster do 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{ @@ -102,6 +105,7 @@ defmodule TrentoWeb.OpenApi.V2.Schema.Cluster do title: "AscsErsClusterNode", description: "ASCS/ERS Cluster Node", type: :object, + additionalProperties: false, properties: %{ attributes: %Schema{ type: :object, @@ -143,7 +147,10 @@ defmodule TrentoWeb.OpenApi.V2.Schema.Cluster do 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" @@ -169,6 +176,7 @@ defmodule TrentoWeb.OpenApi.V2.Schema.Cluster do title: "AscsErsClusterDetails", description: "Details of a ASCS/ERS Pacemaker Cluster", type: :object, + additionalProperties: false, properties: %{ fencing_type: %Schema{ type: :string, @@ -219,6 +227,7 @@ defmodule TrentoWeb.OpenApi.V2.Schema.Cluster do 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"}, diff --git a/lib/trento_web/views/v1/cluster_view.ex b/lib/trento_web/views/v1/cluster_view.ex index 5aeb0b3f40..eff378822d 100644 --- a/lib/trento_web/views/v1/cluster_view.ex +++ b/lib/trento_web/views/v1/cluster_view.ex @@ -8,6 +8,7 @@ defmodule TrentoWeb.V1.ClusterView do def render("cluster.json", %{cluster: cluster}) do cluster |> Map.from_struct() + |> Map.delete(:deregistered_at) |> Map.delete(:__meta__) |> adapt_v1() end diff --git a/lib/trento_web/views/v1/host_view.ex b/lib/trento_web/views/v1/host_view.ex index c46acf0475..143e52f1d9 100644 --- a/lib/trento_web/views/v1/host_view.ex +++ b/lib/trento_web/views/v1/host_view.ex @@ -5,14 +5,38 @@ defmodule TrentoWeb.V1.HostView do render_many(hosts, __MODULE__, "host.json") end - def render("host.json", %{host: host}) do + def render("host.json", %{host: %{sles_subscriptions: sles_subscriptions} = host}) do + sles_subscriptions = + render_many(sles_subscriptions, __MODULE__, "sles_subscription.json", + as: :sles_subscription + ) + + host + |> Map.from_struct() + |> Map.put(:sles_subscriptions, sles_subscriptions) + |> Map.delete(:fully_qualified_domain_name) + |> Map.delete(:inserted_at) + |> Map.delete(:__meta__) + end + + def render("sles_subscription.json", %{sles_subscription: sles_subscription}) do + sles_subscription + |> Map.from_struct() + |> Map.delete(:__meta__) + |> Map.delete(:inserted_at) + |> Map.delete(:updated_at) + end + + def render("sles_subscription.json", _), do: nil + + def render("broadcast_host.json", %{host: host}) do host |> Map.from_struct() |> Map.delete(:__meta__) end def render("host_details_updated.json", %{host: host}) do - render("host.json", %{host: host}) + render("broadcast_host.json", %{host: host}) |> Map.delete(:sles_subscriptions) |> Map.delete(:tags) |> Map.delete(:cluster_id) @@ -22,13 +46,13 @@ defmodule TrentoWeb.V1.HostView do end def render("host_registered.json", %{host: host}) do - render("host.json", %{host: host}) + render("broadcast_host.json", %{host: host}) |> Map.delete(:sles_subscriptions) |> Map.delete(:tags) end def render("host_restored.json", %{host: host}) do - render("host.json", %{host: host}) + render("broadcast_host.json", %{host: host}) end def render("heartbeat_result.json", %{host: %{id: id, hostname: hostname}}) do diff --git a/lib/trento_web/views/v1/sap_system_view.ex b/lib/trento_web/views/v1/sap_system_view.ex index eb9c4796a6..529b2afd24 100644 --- a/lib/trento_web/views/v1/sap_system_view.ex +++ b/lib/trento_web/views/v1/sap_system_view.ex @@ -17,6 +17,7 @@ defmodule TrentoWeb.V1.SapSystemView do database |> Map.from_struct() |> Map.delete(:__meta__) + |> Map.delete(:deregistered_at) |> Map.put(:database_instances, rendered_database_instances) |> add_system_replication_status_to_secondary_instance end @@ -117,6 +118,7 @@ defmodule TrentoWeb.V1.SapSystemView do sap_system |> Map.from_struct() |> Map.delete(:__meta__) + |> Map.delete(:deregistered_at) |> Map.put( :database_instances, rendered_database_instances diff --git a/lib/trento_web/views/v2/cluster_view.ex b/lib/trento_web/views/v2/cluster_view.ex index 1a9904bbf7..d4eb39fc09 100644 --- a/lib/trento_web/views/v2/cluster_view.ex +++ b/lib/trento_web/views/v2/cluster_view.ex @@ -8,6 +8,7 @@ defmodule TrentoWeb.V2.ClusterView do def render("cluster.json", %{cluster: cluster}) do cluster |> Map.from_struct() + |> Map.delete(:deregistered_at) |> Map.delete(:__meta__) end diff --git a/test/trento_web/views/v1/host_view_test.exs b/test/trento_web/views/v1/host_view_test.exs index 04e9d7e61f..84f34357e4 100644 --- a/test/trento_web/views/v1/host_view_test.exs +++ b/test/trento_web/views/v1/host_view_test.exs @@ -17,6 +17,15 @@ defmodule TrentoWeb.V1.HostViewTest do render(HostView, "host_health_changed.json", %{host: host}) end + test "should render single host information" do + host = build(:host, sles_subscriptions: build_list(1, :sles_subscription)) + + rendered_host = render(HostView, "host.json", %{host: host}) + + refute Access.get(rendered_host, :fully_qualified_domain_name) + refute Access.get(rendered_host, :inserted_at) + end + test "should render host details relevant information" do host = build(:host)