Skip to content

Commit

Permalink
Move regex files to validate package
Browse files Browse the repository at this point in the history
  • Loading branch information
santoshkal committed Oct 1, 2024
1 parent ce38f9a commit f819cb3
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 61 deletions.
60 changes: 60 additions & 0 deletions cmd/regex.go
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(&regexSearchArgs.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(&regexSearchArgs.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
}
60 changes: 0 additions & 60 deletions cmd/regx.go

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/regx/regx.go → pkg/validate/regex.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package regx
package validate

import (
"fmt"
Expand Down

0 comments on commit f819cb3

Please sign in to comment.