Skip to content

Commit 06e1ec5

Browse files
authored
Merge pull request #30 from bachradsusi/filter-file-extensions
Filter out invalid module extensions
2 parents 9540104 + f30a52d commit 06e1ec5

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

pkg/utils/utils.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
)
1111

1212
var (
13-
ErrInvalidPath = errors.New("invalid path")
14-
ErrNoExtension = errors.New("file without extension")
13+
ErrInvalidPath = errors.New("invalid path")
14+
ErrInvalidExtension = errors.New("file with invalid extension, valid extensions: .cil .pp")
1515
)
1616

1717
func NewErrInvalidPath(path string) error {
@@ -24,8 +24,10 @@ func GetFileWithoutExtension(filename string) string {
2424
}
2525

2626
func PolicyNameFromPath(path string) (string, error) {
27-
if filepath.Ext(path) == "" {
28-
return "", fmt.Errorf("ignoring: %w", ErrNoExtension)
27+
switch filepath.Ext(path) {
28+
case ".cil", ".pp":
29+
default:
30+
return "", fmt.Errorf("ignoring: %w", ErrInvalidExtension)
2931
}
3032
baseFile := filepath.Base(path)
3133
policy := GetFileWithoutExtension(baseFile)

0 commit comments

Comments
 (0)