Skip to content

Commit

Permalink
Fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
santoshkal committed Oct 1, 2024
1 parent f819cb3 commit 46feb1f
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions pkg/validate/regex.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ import (

// PatternConfig represents the input YAML structure for regex patterns
type PatternConfig struct {
APIVersion string `yaml:"apiVersion"`
Metadata Metadata `yaml:"metadata"`
APIVersion string `yaml:"apiVersion"`
Metadata PolicyMetadata `yaml:"metadata"`
Spec struct {
Pattern []string `yaml:"pattern"`
} `yaml:"spec"`
}

// Metadata contains the details from the policy metadata section
type Metadata struct {
type PolicyMetadata struct {
Name string `yaml:"name"`
Description string `yaml:"description"`
Severity string `yaml:"severity"`
Expand All @@ -33,7 +33,7 @@ type Metadata struct {
func ReadRegxPolicy(path string, target interface{}) error {
data, err := utils.ReadFile(path)
if err != nil {
return err
return fmt.Errorf("failed to read the resource file: %w", err)
}

if err := yaml.Unmarshal(data, target); err != nil {
Expand All @@ -54,18 +54,15 @@ func scanForPattern(content string, patterns []string) bool {
return false
}

// scanResourceFile reads the provided file and scans it for sensitive info
// ScanResourceFile reads the provided file and scans it for sensitive info.
func ScanResourceFile(resourcePath string, patterns []string) bool {
content, err := utils.ReadFile(resourcePath)
if err != nil {
log.Fatalf("Failed to read the resource file: %v\n", err)
}

fmt.Printf("Scanning file: %s\n", resourcePath)
if scanForPattern(string(content), patterns) {
return false // Sensitive pattern found
}
return true // No sensitive patterns found
return !scanForPattern(string(content), patterns) // Return the negation directly
}

// PrintResultTable prints the metadata and result in a formatted table
Expand Down

0 comments on commit 46feb1f

Please sign in to comment.