diff --git a/guides/check_definition.schema.json b/guides/check_definition.schema.json index a6bece79..2313706b 100644 --- a/guides/check_definition.schema.json +++ b/guides/check_definition.schema.json @@ -27,9 +27,6 @@ "remediation": { "type": "string" }, - "premium": { - "type": "boolean" - }, "facts": { "type": "array", "items": { diff --git a/guides/specification.md b/guides/specification.md index 277923ea..cfe09d03 100644 --- a/guides/specification.md +++ b/guides/specification.md @@ -230,20 +230,6 @@ Reports a `critical` When the Check expectations do not pass severity: critical ``` -#### premium - -A boolean determining whether the check is premium or not. It doesn't have any real impact in the check execution itself, it is only an informative field, mostly used by the web frontend. - -**Default:** if no premium flag is provided, the system would default to `false` - -Example: - -Sets the check as premium - -```yaml -premium: true -``` - #### metadata A key-value map that enriches the Check being declared by providing extra information about when to consider it as applicable given a specific [env](#env) diff --git a/lib/wanda/catalog.ex b/lib/wanda/catalog.ex index 5483f3d9..a46c5e39 100644 --- a/lib/wanda/catalog.ex +++ b/lib/wanda/catalog.ex @@ -137,7 +137,6 @@ defmodule Wanda.Catalog do remediation: remediation, metadata: Map.get(check, "metadata"), when: Map.get(check, "when"), - premium: Map.get(check, "premium", false), severity: map_severity(check), facts: Enum.map(facts, &map_fact/1), values: map_values(check), diff --git a/lib/wanda/catalog/check.ex b/lib/wanda/catalog/check.ex index e75f670b..3de8c810 100644 --- a/lib/wanda/catalog/check.ex +++ b/lib/wanda/catalog/check.ex @@ -17,8 +17,7 @@ defmodule Wanda.Catalog.Check do :facts, :values, :expectations, - :when, - :premium + :when ] @type t :: %__MODULE__{ @@ -32,7 +31,6 @@ defmodule Wanda.Catalog.Check do facts: [Fact.t()], values: [Value.t()], expectations: [Expectation.t()], - when: String.t(), - premium: boolean() + when: String.t() } end diff --git a/lib/wanda_web/schemas/v1/catalog/check.ex b/lib/wanda_web/schemas/v1/catalog/check.ex index 41252ee2..364238c6 100644 --- a/lib/wanda_web/schemas/v1/catalog/check.ex +++ b/lib/wanda_web/schemas/v1/catalog/check.ex @@ -111,7 +111,8 @@ defmodule WandaWeb.Schemas.V1.Catalog.Check do }, premium: %Schema{ type: :boolean, - description: "Check is Premium or not" + description: "Check is Premium or not", + deprecated: true } }, required: [ diff --git a/lib/wanda_web/schemas/v3/catalog/check.ex b/lib/wanda_web/schemas/v3/catalog/check.ex index e8281b4b..f3b018f6 100644 --- a/lib/wanda_web/schemas/v3/catalog/check.ex +++ b/lib/wanda_web/schemas/v3/catalog/check.ex @@ -117,7 +117,8 @@ defmodule WandaWeb.Schemas.V3.Catalog.Check do }, premium: %Schema{ type: :boolean, - description: "Check is Premium or not" + description: "Check is Premium or not", + deprecated: true } }, required: [ diff --git a/lib/wanda_web/views/v1/catalog_json.ex b/lib/wanda_web/views/v1/catalog_json.ex index 2fcfc3d1..02c89324 100644 --- a/lib/wanda_web/views/v1/catalog_json.ex +++ b/lib/wanda_web/views/v1/catalog_json.ex @@ -5,17 +5,44 @@ defmodule WandaWeb.V1.CatalogJSON do %{items: Enum.map(catalog, &check/1)} end - def check(%Check{} = check), do: adapt_v1(check) + def check( + %Check{ + id: id, + name: name, + group: group, + description: description, + remediation: remediation, + metadata: metadata, + severity: severity, + facts: facts, + values: values, + when: when_expression + } = check + ) do + adapted_expectations = adapt_expectations(check) - def adapt_v1(%{expectations: expectations} = check) do - adapted_expectations = - expectations - |> Enum.map(fn - %{type: :expect_enum} = expectation -> Map.put(expectation, :type, :unknown) - expectation -> expectation - end) - |> Enum.map(&Map.drop(Map.from_struct(&1), [:warning_message])) + %{ + id: id, + name: name, + group: group, + description: description, + remediation: remediation, + metadata: metadata, + severity: severity, + facts: facts, + values: values, + expectations: adapted_expectations, + when: when_expression, + premium: false + } + end - %{check | expectations: adapted_expectations} + def adapt_expectations(%{expectations: expectations}) do + expectations + |> Enum.map(fn + %{type: :expect_enum} = expectation -> Map.put(expectation, :type, :unknown) + expectation -> expectation + end) + |> Enum.map(&Map.drop(Map.from_struct(&1), [:warning_message])) end end diff --git a/lib/wanda_web/views/v3/catalog_json.ex b/lib/wanda_web/views/v3/catalog_json.ex index 16a6e082..f1eba63f 100644 --- a/lib/wanda_web/views/v3/catalog_json.ex +++ b/lib/wanda_web/views/v3/catalog_json.ex @@ -5,7 +5,32 @@ defmodule WandaWeb.V3.CatalogJSON do %{items: Enum.map(catalog, &check/1)} end - def check(%Check{} = check) do - check + def check(%Check{ + id: id, + name: name, + group: group, + description: description, + remediation: remediation, + metadata: metadata, + severity: severity, + facts: facts, + values: values, + expectations: expectations, + when: when_expression + }) do + %{ + id: id, + name: name, + group: group, + description: description, + remediation: remediation, + metadata: metadata, + severity: severity, + facts: facts, + values: values, + expectations: expectations, + when: when_expression, + premium: false + } end end diff --git a/test/fixtures/catalog/expect_check.yaml b/test/fixtures/catalog/expect_check.yaml index 9ce2e639..78eb267c 100644 --- a/test/fixtures/catalog/expect_check.yaml +++ b/test/fixtures/catalog/expect_check.yaml @@ -6,7 +6,6 @@ description: | remediation: | ## Remediation Remediation text -premium: true facts: - name: jedi gatherer: wandalorian diff --git a/test/fixtures/catalog/expect_enum_check.yaml b/test/fixtures/catalog/expect_enum_check.yaml index f27b7f46..785e98bf 100644 --- a/test/fixtures/catalog/expect_enum_check.yaml +++ b/test/fixtures/catalog/expect_enum_check.yaml @@ -6,7 +6,6 @@ description: | remediation: | ## Remediation Remediation text -premium: true facts: - name: jedi gatherer: wandalorian diff --git a/test/support/factory.ex b/test/support/factory.ex index b407f936..3e280d59 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -36,8 +36,7 @@ defmodule Wanda.Factory do facts: build_list(10, :catalog_fact), values: build_list(10, :catalog_value), expectations: build_list(10, :catalog_expectation), - when: Faker.Lorem.sentence(), - premium: Enum.random([false, true]) + when: Faker.Lorem.sentence() } end diff --git a/test/wanda/catalog_test.exs b/test/wanda/catalog_test.exs index d55b3efc..4c470225 100644 --- a/test/wanda/catalog_test.exs +++ b/test/wanda/catalog_test.exs @@ -95,7 +95,6 @@ defmodule Wanda.CatalogTest do description: "Just a check\n", remediation: "## Remediation\nRemediation text\n", severity: :critical, - premium: true, facts: [ %Fact{ name: "jedi", @@ -194,11 +193,6 @@ defmodule Wanda.CatalogTest do Catalog.get_check(catalog_path(), "warning_severity_check") end - test "should load premium as false by default" do - assert {:ok, %Check{premium: false}} = - Catalog.get_check(catalog_path(), "warning_severity_check") - end - test "should return an error for non-existent check" do assert {:error, _} = Catalog.get_check(catalog_path(), "non_existent_check") end diff --git a/test/wanda_web/views/v1/catalog_view_json_test.exs b/test/wanda_web/views/v1/catalog_view_json_test.exs index a88f2e1b..441fac08 100644 --- a/test/wanda_web/views/v1/catalog_view_json_test.exs +++ b/test/wanda_web/views/v1/catalog_view_json_test.exs @@ -3,7 +3,6 @@ defmodule WandaWeb.V1.CatalogJSONTest do import Wanda.Factory - alias Wanda.Catalog.Check alias WandaWeb.V1.CatalogJSON describe "CatalogJSON" do @@ -14,7 +13,7 @@ defmodule WandaWeb.V1.CatalogJSONTest do ] adapted_checks = - Enum.map(checks, fn %Check{expectations: expectations} = check -> + Enum.map(checks, fn %{expectations: expectations} = check -> %{ check | expectations: @@ -24,6 +23,8 @@ defmodule WandaWeb.V1.CatalogJSONTest do |> Map.drop([:warning_message]) end) } + |> Map.from_struct() + |> Map.put(:premium, false) end) rendered_catalog = CatalogJSON.catalog(%{catalog: checks}) @@ -56,7 +57,7 @@ defmodule WandaWeb.V1.CatalogJSONTest do checks = build_list(1, :check) %{ - items: [%Check{expectations: [expectation | _rest_expectations]}] + items: [%{expectations: [expectation | _rest_expectations]}] } = CatalogJSON.catalog(%{catalog: checks}) diff --git a/test/wanda_web/views/v2/catalog_view_json_test.exs b/test/wanda_web/views/v2/catalog_view_json_test.exs index 7709c6db..05c18cb2 100644 --- a/test/wanda_web/views/v2/catalog_view_json_test.exs +++ b/test/wanda_web/views/v2/catalog_view_json_test.exs @@ -3,7 +3,6 @@ defmodule WandaWeb.V2.CatalogJSONTest do import Wanda.Factory - alias Wanda.Catalog.Check alias WandaWeb.V2.CatalogJSON describe "CatalogJSON" do @@ -14,7 +13,7 @@ defmodule WandaWeb.V2.CatalogJSONTest do ] adapted_checks = - Enum.map(checks, fn %Check{expectations: expectations} = check -> + Enum.map(checks, fn %{expectations: expectations} = check -> %{ check | expectations: @@ -24,6 +23,8 @@ defmodule WandaWeb.V2.CatalogJSONTest do |> Map.drop([:warning_message]) end) } + |> Map.from_struct() + |> Map.put(:premium, false) end) rendered_catalog = CatalogJSON.catalog(%{catalog: checks}) diff --git a/test/wanda_web/views/v3/catalog_view_json_test.exs b/test/wanda_web/views/v3/catalog_view_json_test.exs index efbdc474..a00d1fbd 100644 --- a/test/wanda_web/views/v3/catalog_view_json_test.exs +++ b/test/wanda_web/views/v3/catalog_view_json_test.exs @@ -3,14 +3,45 @@ defmodule WandaWeb.V3.CatalogJSONTest do import Wanda.Factory + alias Wanda.Catalog.Check + alias WandaWeb.V3.CatalogJSON describe "CatalogJSON" do test "renders catalog.json" do - checks = build_list(1, :check) + [ + %Check{ + id: id, + name: name, + group: group, + description: description, + remediation: remediation, + metadata: metadata, + severity: severity, + facts: facts, + values: values, + expectations: expectations, + when: when_expression + } + ] = checks = build_list(1, :check) assert %{ - items: ^checks + items: [ + %{ + id: ^id, + name: ^name, + group: ^group, + description: ^description, + remediation: ^remediation, + metadata: ^metadata, + severity: ^severity, + facts: ^facts, + values: ^values, + expectations: ^expectations, + when: ^when_expression, + premium: false + } + ] } = CatalogJSON.catalog(%{catalog: checks}) end end