-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move regex files to validate package
- Loading branch information
1 parent
ce38f9a
commit f819cb3
Showing
3 changed files
with
61 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package cmd | ||
|
||
import ( | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/intelops/genval/pkg/validate" | ||
) | ||
|
||
type regexSearchFlags struct { | ||
reqinput string | ||
policy string | ||
} | ||
|
||
var regexSearchArgs regexSearchFlags | ||
|
||
func init() { | ||
regexSearchCmd.Flags().StringVarP(®exSearchArgs.reqinput, "reqinput", "r", "", "Input file for validating against regex pattern") | ||
if err := terraformCmd.MarkFlagRequired("reqinput"); err != nil { | ||
log.Fatalf("Error marking flag as required: %v", err) | ||
} | ||
regexSearchCmd.Flags().StringVarP(®exSearchArgs.policy, "policy", "p", "", "Path for the RegeX policy file, polciy can be passed from either Local or from remote URL") | ||
rootCmd.AddCommand(regexSearchCmd) | ||
} | ||
|
||
var regexSearchCmd = &cobra.Command{ | ||
Use: "regx", | ||
Short: "Validate resource files with Regex policy match", | ||
Long: ``, | ||
Example: ` | ||
# Validate resource files with Regex policies | ||
`, | ||
RunE: runRegexSearchCmd, | ||
} | ||
|
||
func runRegexSearchCmd(cmd *cobra.Command, args []string) error { | ||
inputFile := regexSearchArgs.reqinput | ||
policy := regexSearchArgs.policy | ||
|
||
// Load the regex patterns from the policy file | ||
var patternConfig validate.PatternConfig | ||
if err := validate.ReadRegxPolicy(policy, &patternConfig); err != nil { | ||
log.Fatalf("Error reading policy YAML: %v", err) | ||
} | ||
|
||
// Perform the regex validation on the resource file | ||
isPass := validate.ScanResourceFile(inputFile, patternConfig.Spec.Pattern) | ||
|
||
// Determine the result and print the table | ||
result := "Pass" | ||
if !isPass { | ||
result = "Fail: Sensitive information found." | ||
} | ||
|
||
// Print the metadata and result in a table | ||
validate.PrintResultTable(patternConfig.Metadata, result) | ||
|
||
return nil | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package regx | ||
package validate | ||
|
||
import ( | ||
"fmt" | ||
|