Skip to content

Commit

Permalink
Rule Types: Skip .test.yml files when linting/applying
Browse files Browse the repository at this point in the history
These files are not actually rule types and will make linting and
applying rule types fail.

Signed-off-by: Juan Antonio Osorio <[email protected]>
  • Loading branch information
JAORMX committed Oct 17, 2024
1 parent 1f78eb1 commit d19cc0e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cmd/cli/app/ruletype/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ func shouldSkipFile(f string) bool {
ext := filepath.Ext(f)
switch ext {
case ".yaml", ".yml", ".json":
if cli.IsTestFile(f) {
// Skip test files.
return true
}
return false
default:
fmt.Fprintf(os.Stderr, "Skipping file %s: not a yaml or json file\n", f)
Expand Down
3 changes: 2 additions & 1 deletion cmd/dev/app/rule_type/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"gopkg.in/yaml.v3"

"github.com/mindersec/minder/internal/engine/eval/rego"
"github.com/mindersec/minder/internal/util/cli"
minderv1 "github.com/mindersec/minder/pkg/api/protobuf/go/minder/v1"
)

Expand Down Expand Up @@ -58,7 +59,7 @@ func lintCmdRun(cmd *cobra.Command, _ []string) error {
return nil
}

if filepath.Ext(path) != ".yaml" && filepath.Ext(path) != ".yml" {
if !cli.IsYAMLFileAndNotATest(path) {
return nil
}

Expand Down
11 changes: 11 additions & 0 deletions internal/util/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,14 @@ func GetRelevantCLIConfigPath(v *viper.Viper) string {
GetDefaultCLIConfigPath(),
))
}

// IsYAMLFileAndNotATest checks if a file is a YAML file and not a test file
func IsYAMLFileAndNotATest(path string) bool {
return (filepath.Ext(path) == ".yaml" || filepath.Ext(path) == ".yml") &&
!IsTestFile(path)
}

// IsTestFile checks if a file is a test file. Test files are YAML files ending with .test.yaml or .test.yml
func IsTestFile(path string) bool {
return strings.HasSuffix(path, ".test.yaml") || strings.HasSuffix(path, ".test.yml")
}

0 comments on commit d19cc0e

Please sign in to comment.