Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Remove all premium references #516

Merged
merged 3 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions guides/check_definition.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
"remediation": {
"type": "string"
},
"premium": {
"type": "boolean"
},
"facts": {
"type": "array",
"items": {
Expand Down
14 changes: 0 additions & 14 deletions guides/specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion lib/wanda/catalog.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
6 changes: 2 additions & 4 deletions lib/wanda/catalog/check.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ defmodule Wanda.Catalog.Check do
:facts,
:values,
:expectations,
:when,
:premium
:when
]

@type t :: %__MODULE__{
Expand All @@ -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
3 changes: 2 additions & 1 deletion lib/wanda_web/schemas/v1/catalog/check.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
3 changes: 2 additions & 1 deletion lib/wanda_web/schemas/v3/catalog/check.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
47 changes: 37 additions & 10 deletions lib/wanda_web/views/v1/catalog_json.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
29 changes: 27 additions & 2 deletions lib/wanda_web/views/v3/catalog_json.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion test/fixtures/catalog/expect_check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ description: |
remediation: |
## Remediation
Remediation text
premium: true
facts:
- name: jedi
gatherer: wandalorian
Expand Down
1 change: 0 additions & 1 deletion test/fixtures/catalog/expect_enum_check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ description: |
remediation: |
## Remediation
Remediation text
premium: true
facts:
- name: jedi
gatherer: wandalorian
Expand Down
3 changes: 1 addition & 2 deletions test/support/factory.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 0 additions & 6 deletions test/wanda/catalog_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions test/wanda_web/views/v1/catalog_view_json_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ defmodule WandaWeb.V1.CatalogJSONTest do

import Wanda.Factory

alias Wanda.Catalog.Check
alias WandaWeb.V1.CatalogJSON

describe "CatalogJSON" do
Expand All @@ -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:
Expand All @@ -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})
Expand Down Expand Up @@ -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})

Expand Down
5 changes: 3 additions & 2 deletions test/wanda_web/views/v2/catalog_view_json_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ defmodule WandaWeb.V2.CatalogJSONTest do

import Wanda.Factory

alias Wanda.Catalog.Check
alias WandaWeb.V2.CatalogJSON

describe "CatalogJSON" do
Expand All @@ -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:
Expand All @@ -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})
Expand Down
35 changes: 33 additions & 2 deletions test/wanda_web/views/v3/catalog_view_json_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down