diff --git a/cmd/regex.go b/cmd/regex.go new file mode 100644 index 0000000..ccc289a --- /dev/null +++ b/cmd/regex.go @@ -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 +} diff --git a/cmd/regx.go b/cmd/regx.go deleted file mode 100644 index e2e7d2e..0000000 --- a/cmd/regx.go +++ /dev/null @@ -1,60 +0,0 @@ -package cmd - -import ( - log "github.com/sirupsen/logrus" - "github.com/spf13/cobra" - - "github.com/intelops/genval/pkg/regx" -) - -type regxSearchFlags struct { - reqinput string - policy string -} - -var regxSearchArgs regxSearchFlags - -func init() { - regxSearchCmd.Flags().StringVarP(®xSearchArgs.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) - } - regxSearchCmd.Flags().StringVarP(®xSearchArgs.policy, "policy", "p", "", "Path for the RegeX policy file, polciy can be passed from either Local or from remote URL") - rootCmd.AddCommand(regxSearchCmd) -} - -var regxSearchCmd = &cobra.Command{ - Use: "regx", - Short: "Validate resource files with Regex policy match", - Long: ``, - Example: ` -# Validate resource files with Regex policies - - `, - RunE: runRegxSearchCmd, -} - -func runRegxSearchCmd(cmd *cobra.Command, args []string) error { - inputFile := regxSearchArgs.reqinput - policy := regxSearchArgs.policy - - // Load the regex patterns from the policy file - var patternConfig regx.PatternConfig - if err := regx.ReadRegxPolicy(policy, &patternConfig); err != nil { - log.Fatalf("Error reading policy YAML: %v", err) - } - - // Perform the regex validation on the resource file - isPass := regx.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 - regx.PrintResultTable(patternConfig.Metadata, result) - - return nil -} diff --git a/pkg/regx/regx.go b/pkg/validate/regex.go similarity index 99% rename from pkg/regx/regx.go rename to pkg/validate/regex.go index 4ff5642..7c8d699 100644 --- a/pkg/regx/regx.go +++ b/pkg/validate/regex.go @@ -1,4 +1,4 @@ -package regx +package validate import ( "fmt"