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

moved-some-types-to-operator-utils #160

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
2 changes: 1 addition & 1 deletion checker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func checkRuleContent(groupCfg groupConfigMap) {
checkRuleAttributeNotEmpty(ruleName, "product_code", ruleContent.Plugin.ProductCode)
checkRuleAttributeNotEmpty(ruleName, "python_module", ruleContent.Plugin.PythonModule)

checkRuleFileNotEmpty(ruleName, "more_info.md", ruleContent.MoreInfo)
checkRuleFileNotEmpty(ruleName, "more_info.md", string(ruleContent.MoreInfo))
checkRuleFileNotEmpty(ruleName, "reason.md", ruleContent.Reason)
checkRuleFileNotEmpty(ruleName, "resolution.md", ruleContent.Resolution)
checkRuleFileNotEmpty(ruleName, "summary.md", ruleContent.Summary)
Expand Down
13 changes: 13 additions & 0 deletions config-devel.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[server]
address = ":8082"
api_prefix = "/api/v1/"
api_spec_file = "openapi.json"

[groups]
path = "groups_config.yaml"

[content]
path = "rules-content"

[metrics]
namespace = "insights_content_service"
83 changes: 25 additions & 58 deletions content/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,61 +23,28 @@ import (
"path"
"path/filepath"

"github.com/RedHatInsights/insights-operator-utils/types"
"github.com/go-yaml/yaml"
"github.com/rs/zerolog/log"
)

// GlobalRuleConfig represents the file that contains
// metadata globally applicable to any/all rule content.
type GlobalRuleConfig struct {
Impact map[string]int `yaml:"impact" json:"impact"`
}

// ErrorKeyMetadata is a Go representation of the `metadata.yaml`
// file inside of an error key content directory.
type ErrorKeyMetadata struct {
Condition string `yaml:"condition" json:"condition"`
Description string `yaml:"description" json:"description"`
Impact string `yaml:"impact" json:"impact"`
Likelihood int `yaml:"likelihood" json:"likelihood"`
PublishDate string `yaml:"publish_date" json:"publish_date"`
Status string `yaml:"status" json:"status"`
Tags []string `yaml:"tags" json:"tags"`
}

// RuleErrorKeyContent wraps content of a single error key.
type RuleErrorKeyContent struct {
Generic string `json:"generic"`
Metadata ErrorKeyMetadata `json:"metadata"`
Reason string `json:"reason"`
hasReason bool
}

// RulePluginInfo is a Go representation of the `plugin.yaml`
// file inside of the rule content directory.
type RulePluginInfo struct {
Name string `yaml:"name" json:"name"`
NodeID string `yaml:"node_id" json:"node_id"`
ProductCode string `yaml:"product_code" json:"product_code"`
PythonModule string `yaml:"python_module" json:"python_module"`
}

// RuleContent wraps all the content available for a rule into a single structure.
type RuleContent struct {
Summary string `json:"summary"`
Reason string `json:"reason"`
Resolution string `json:"resolution"`
MoreInfo string `json:"more_info"`
Plugin RulePluginInfo `json:"plugin"`
ErrorKeys map[string]RuleErrorKeyContent `json:"error_keys"`
hasReason bool
}

// RuleContentDirectory contains content for all available rules in a directory.
type RuleContentDirectory struct {
Config GlobalRuleConfig
Rules map[string]RuleContent
}
type (
// RuleContent wraps all the content available for a rule into a single structure.
RuleContent = types.RuleContent
// RulePluginInfo is a Go representation of the `plugin.yaml`
// file inside of the rule content directory.
RulePluginInfo = types.RulePluginInfo
// RuleErrorKeyContent wraps content of a single error key.
RuleErrorKeyContent = types.RuleErrorKeyContent
// ErrorKeyMetadata is a Go representation of the `metadata.yaml`
// file inside of an error key content directory.
ErrorKeyMetadata = types.ErrorKeyMetadata
// RuleContentDirectory contains content for all available rules in a directory.
RuleContentDirectory = types.RuleContentDirectory
// GlobalRuleConfig represents the file that contains
// metadata globally applicable to any/all rule content.
GlobalRuleConfig = types.GlobalRuleConfig
)

// readFilesIntoByteArrayPointers reads the contents of the specified files
// in the base directory and saves them via the specified byte slice pointers.
Expand Down Expand Up @@ -111,10 +78,10 @@ func createErrorContents(contentRead map[string][]byte) (*RuleErrorKeyContent, e

if contentRead["reason.md"] == nil {
errorContent.Reason = ""
errorContent.hasReason = false
errorContent.HasReason = false
} else {
errorContent.Reason = string(contentRead["reason.md"])
errorContent.hasReason = true
errorContent.HasReason = true
}

if contentRead["metadata.yaml"] == nil {
Expand Down Expand Up @@ -178,10 +145,10 @@ func createRuleContent(contentRead map[string][]byte, errorKeys map[string]RuleE
if contentRead["reason.md"] == nil {
// check error keys for a reason
ruleContent.Reason = ""
ruleContent.hasReason = false
ruleContent.HasReason = false
} else {
ruleContent.Reason = string(contentRead["reason.md"])
ruleContent.hasReason = true
ruleContent.HasReason = true
}

if contentRead["resolution.md"] == nil {
Expand All @@ -194,7 +161,7 @@ func createRuleContent(contentRead map[string][]byte, errorKeys map[string]RuleE
return nil, &MissingMandatoryFile{FileName: "more_info.md"}
}

ruleContent.MoreInfo = string(contentRead["more_info.md"])
ruleContent.MoreInfo = contentRead["more_info.md"]

if contentRead["plugin.yaml"] == nil {
return nil, &MissingMandatoryFile{FileName: "plugin.yaml"}
Expand Down Expand Up @@ -299,12 +266,12 @@ func parseRulesInDir(dirPath string, contentMap *map[string]RuleContent) error {
// checkRequiredFields search if all the required fields in the RuleContent are ok
// at the moment only checks for Reason field
func checkRequiredFields(rule RuleContent) error {
if rule.hasReason {
if rule.HasReason {
return nil
}

for _, errorKeyContent := range rule.ErrorKeys {
if !errorKeyContent.hasReason {
if !errorKeyContent.HasReason {
return &MissingMandatoryFile{FileName: "reason.md"}
}
}
Expand Down
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ go 1.13

require (
github.com/BurntSushi/toml v0.3.1
github.com/RedHatInsights/insights-operator-utils v1.6.0
github.com/RedHatInsights/insights-operator-utils v1.6.4
github.com/RedHatInsights/insights-results-aggregator v0.0.0-20200604090056-3534f6dd9c1c
github.com/bitly/go-simplejson v0.5.0 // indirect
github.com/go-yaml/yaml v2.1.0+incompatible
github.com/gorilla/mux v1.7.4
github.com/gorilla/mux v1.8.0
github.com/prometheus/client_golang v1.7.1
github.com/rs/zerolog v1.19.0
github.com/spf13/viper v1.7.0
github.com/rs/zerolog v1.20.0
github.com/spf13/viper v1.7.1
github.com/stretchr/testify v1.6.1
github.com/tisnik/go-capture v1.0.1
github.com/verdverm/frisby v0.0.0-20170604211311-b16556248a9a
Expand Down
Loading