From 66e2a961aec787b028b918ecb1a7613b2028b96b Mon Sep 17 00:00:00 2001 From: Ahmed AbouZaid <6760103+aabouzaid@users.noreply.github.com> Date: Wed, 12 Apr 2023 23:44:19 +0200 Subject: [PATCH] refactor: expose kubeconform config --- pkg/config/config.go | 64 +++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 25 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 4b834d9..309be12 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -16,27 +16,48 @@ type Stream struct { } type Config struct { - Cache string - Debug bool - ExitOnError bool - Files []string - SchemaLocations []string - SkipTLS bool - SkipKinds map[string]struct{} + Cache string `yaml:"cache" json:"cache"` + Debug bool `yaml:"debug" json:"debug"` + ExitOnError bool `yaml:"exitOnError" json:"exitOnError"` + Files []string `yaml:"files" json:"files"` + Help bool `yaml:"help" json:"help"` + IgnoreFilenamePatterns []string `yaml:"ignoreFilenamePatterns" json:"ignoreFilenamePatterns"` + IgnoreMissingSchemas bool `yaml:"ignoreMissingSchemas" json:"ignoreMissingSchemas"` + KubernetesVersion string `yaml:"kubernetesVersion" json:"kubernetesVersion"` + NumberOfWorkers int `yaml:"numberOfWorkers" json:"numberOfWorkers"` + OutputFormat string `yaml:"output" json:"output"` RejectKinds map[string]struct{} - OutputFormat string - KubernetesVersion string - NumberOfWorkers int - Summary bool - Strict bool - Verbose bool - IgnoreMissingSchemas bool - IgnoreFilenamePatterns []string - Help bool - Version bool + RejectKindsNG []string `yaml:"reject" json:"reject"` + SchemaLocations []string `yaml:"schemaLocations" json:"schemaLocations"` + SkipKinds map[string]struct{} + SkipKindsNG []string `yaml:"skip" json:"skip"` + SkipTLS bool `yaml:"insecureSkipTLSVerify" json:"insecureSkipTLSVerify"` + Strict bool `yaml:"strict" json:"strict"` + Summary bool `yaml:"summary" json:"summary"` + Verbose bool `yaml:"verbose" json:"verbose"` + Version bool `yaml:"version" json:"version"` Stream *Stream } +// LoadNGConfig allows to introduce new config while keeping backward compatibility. +func (c *Config) LoadNGConfig() error { + // SkipKindsNG. + loadKinds(c.SkipKinds, c.SkipKindsNG) + + // RejectKindsNG. + loadKinds(c.RejectKinds, c.RejectKindsNG) + + return nil +} + +func loadKinds(dest map[string]struct{}, src []string) { + for _, kind := range src { + if len(kind) > 0 { + dest[kind] = struct{}{} + } + } +} + type arrayParam []string func (ap *arrayParam) String() string { @@ -49,15 +70,8 @@ func (ap *arrayParam) Set(value string) error { } func splitCSV(csvStr string) map[string]struct{} { - splitValues := strings.Split(csvStr, ",") valuesMap := map[string]struct{}{} - - for _, kind := range splitValues { - if len(kind) > 0 { - valuesMap[kind] = struct{}{} - } - } - + loadKinds(valuesMap, strings.Split(csvStr, ",")) return valuesMap }