Skip to content
This repository has been archived by the owner on Feb 4, 2025. It is now read-only.

Include internal rules #97

Merged
merged 10 commits into from
Jul 9, 2020
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ FROM registry.redhat.io/ubi8-minimal
COPY --from=builder /opt/app-root/src/insights-content-service .
COPY --from=builder /opt/app-root/src/openapi.json /openapi/openapi.json
COPY --from=builder /opt/app-root/src/groups_config.yaml /groups/groups_config.yaml
# copy just the rule content instead of the whole repository
# copy just the rule content instead of the whole ocp-rules repository
COPY --from=builder /rules-content/content/ /rules-content
# copy tutorial/fake rule hit on all reports
# copy tutorial/fake rule to external rules to be hit by all reports
COPY rules/tutorial/content/ /rules-content/external/rules

USER 1001
Expand Down
16 changes: 16 additions & 0 deletions content/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,24 @@ func ParseRuleContentDir(contentDirPath string) (RuleContentDirectory, error) {
Rules: map[string]RuleContent{},
}

// parse external and internal rules separately, because there are currently more categories
// of rules, but they just don't have content yet, so in case the content for them appears.
// If we want to parse all of them, the full contentDirPath can be passed to parseRulesInDir without problems
externalContentDir := path.Join(contentDirPath, "external")
err = parseRulesInDir(externalContentDir, &contentDir.Rules)

if err != nil {
log.Error().Err(err).Msg("Cannot parse content of external rules")
return contentDir, err
}

internalContentDir := path.Join(contentDirPath, "internal")
err = parseRulesInDir(internalContentDir, &contentDir.Rules)

if err != nil {
log.Error().Err(err).Msg("Cannot parse content of internal rules")
return contentDir, err
}

return contentDir, err
}
8 changes: 7 additions & 1 deletion content/content_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,16 @@ func TestContentParseNoExternal(t *testing.T) {
assert.EqualError(t, err, fmt.Sprintf("open %s/external: no such file or directory", noExternalPath))
}

// TestContentParseNoInternal tests condition where there is no folder for internal rules
func TestContentParseNoInternal(t *testing.T) {
noInternalPath := "../tests/content/no_internal"
_, err := content.ParseRuleContentDir(noInternalPath)
assert.EqualError(t, err, fmt.Sprintf("open %s/internal: no such file or directory", noInternalPath))
}

// TestContentParseNoReason tests failing when no reason file in rule or error key dirs is present
func TestContentParseNoReason(t *testing.T) {
noReasonPath := "../tests/content/no_reason"
_, err := content.ParseRuleContentDir(noReasonPath)
assert.EqualError(t, err, "Missing required file: reason.md")

}
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require (
github.com/BurntSushi/toml v0.3.1
github.com/RedHatInsights/insights-operator-utils v1.3.2
github.com/RedHatInsights/insights-results-aggregator v0.0.0-20200604090056-3534f6dd9c1c
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
github.com/go-yaml/yaml v2.1.0+incompatible
github.com/gorilla/mux v1.7.4
github.com/prometheus/client_golang v1.7.1
Expand All @@ -15,6 +14,5 @@ require (
github.com/stretchr/testify v1.6.1
github.com/tisnik/go-capture v1.0.1
github.com/verdverm/frisby v0.0.0-20170604211311-b16556248a9a
gopkg.in/h2non/gock.v1 v1.0.15 // indirect
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2020 Red Hat, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

@
5 changes: 5 additions & 0 deletions tests/content/bad_metadata/internal/rules/rule2/more_info.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Some more information

## would be put

### into this file
13 changes: 13 additions & 0 deletions tests/content/bad_metadata/internal/rules/rule2/plugin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2020 Red Hat, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
Empty file.
1 change: 1 addition & 0 deletions tests/content/bad_metadata/internal/rules/rule2/summary.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Rule 1 Summary
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2020 Red Hat, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
status: "bad-status"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Some more information

## would be put

### into this file
13 changes: 13 additions & 0 deletions tests/content/bad_metadata_status/internal/rules/rule2/plugin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2020 Red Hat, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Rule 1 Summary
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2020 Red Hat, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
5 changes: 5 additions & 0 deletions tests/content/bad_plugin/internal/rules/rule2/more_info.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Some more information

## would be put

### into this file
15 changes: 15 additions & 0 deletions tests/content/bad_plugin/internal/rules/rule2/plugin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2020 Red Hat, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

@
Empty file.
1 change: 1 addition & 0 deletions tests/content/bad_plugin/internal/rules/rule2/summary.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Rule 1 Summary
13 changes: 13 additions & 0 deletions tests/content/missing/internal/rules/rule3/plugin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2020 Red Hat, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
1 change: 1 addition & 0 deletions tests/content/missing/internal/rules/rule3/summary.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Rule 2 Summary
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2020 Red Hat, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
status: "inactive"
publish_date: "2020-04-03T16:13:30+02:00"
5 changes: 5 additions & 0 deletions tests/content/no_external/internal/rules/rule2/more_info.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Some more information

## would be put

### into this file
13 changes: 13 additions & 0 deletions tests/content/no_external/internal/rules/rule2/plugin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2020 Red Hat, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
Empty file.
1 change: 1 addition & 0 deletions tests/content/no_external/internal/rules/rule2/summary.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Rule 1 Summary
24 changes: 24 additions & 0 deletions tests/content/no_internal/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2020 Red Hat, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

impact:
One: 1
Two: 2
Three: 3
Four: 4
Five: 5
Six: 6
Seven: 7
Eight: 8
Nine: 9
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2020 Red Hat, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
status: "inactive"
publish_date: "2020-04-03T16:13:30+02:00"
5 changes: 5 additions & 0 deletions tests/content/no_internal/external/rules/rule1/more_info.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Some more information

## would be put

### into this file
13 changes: 13 additions & 0 deletions tests/content/no_internal/external/rules/rule1/plugin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2020 Red Hat, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
Empty file.
1 change: 1 addition & 0 deletions tests/content/no_internal/external/rules/rule1/summary.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Rule 1 Summary
Empty file.
15 changes: 15 additions & 0 deletions tests/content/ok/internal/rules/rule2/err_key/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2020 Red Hat, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
status: "inactive"
publish_date: "2020-04-03T16:13:30+02:00"
5 changes: 5 additions & 0 deletions tests/content/ok/internal/rules/rule2/more_info.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Some more information

## would be put

### into this file
13 changes: 13 additions & 0 deletions tests/content/ok/internal/rules/rule2/plugin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2020 Red Hat, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
Empty file.
Empty file.
1 change: 1 addition & 0 deletions tests/content/ok/internal/rules/rule2/summary.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Rule 1 Summary
Empty file.