Skip to content

Commit

Permalink
feat: Add external_data function to Gator Test command
Browse files Browse the repository at this point in the history
Signed-off-by: Fardin Khanjani <fardin.khanjani@tradeshift.com>
  • Loading branch information
fardin01 committed Jun 21, 2023
1 parent 6aad7b6 commit 83e9946
Show file tree
Hide file tree
Showing 6 changed files with 1,194 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cmd/gator/expand/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func init() {
}

func run(cmd *cobra.Command, args []string) {
unstrucs, err := reader.ReadSources(flagFilenames, flagImages, flagTempDir)
unstrucs, err := reader.ReadSources(flagFilenames, flagImages, flagTempDir, []string{})
if err != nil {
util.ErrFatalf("reading: %v", err)
}
Expand Down
18 changes: 10 additions & 8 deletions cmd/gator/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@ var Cmd = &cobra.Command{
}

var (
flagFilenames []string
flagOutput string
flagIncludeTrace bool
flagGatherStats bool
flagImages []string
flagTempDir string
flagEnableK8sCel bool
flagFilenames []string
flagOutput string
flagIncludeTrace bool
flagGatherStats bool
flagExternalDataProviders []string
flagImages []string
flagTempDir string
flagEnableK8sCel bool
)

const (
Expand All @@ -74,12 +75,13 @@ func init() {
Cmd.Flags().BoolVarP(&flagIncludeTrace, "trace", "t", false, "include a trace for the underlying Constraint Framework evaluation.")
Cmd.Flags().BoolVarP(&flagGatherStats, "stats", "", false, "include performance stats returned from the Constraint Framework.")
Cmd.Flags().BoolVarP(&flagEnableK8sCel, "experimental-enable-k8s-native-validation", "", false, "PROTOTYPE (not stable): enable the validating admission policy driver")
Cmd.Flags().StringArrayVarP(&flagExternalDataProviders, "external-data-providers", "", []string{}, "a file containing External Data Provider manifest. Can be specified multiple times.")
Cmd.Flags().StringArrayVarP(&flagImages, flagNameImage, "i", []string{}, "a URL to an OCI image containing policies. Can be specified multiple times.")
Cmd.Flags().StringVarP(&flagTempDir, flagNameTempDir, "d", "", fmt.Sprintf("Specifies the temporary directory to download and unpack images to, if using the --%s flag. Optional.", flagNameImage))
}

func run(cmd *cobra.Command, args []string) {
unstrucs, err := reader.ReadSources(flagFilenames, flagImages, flagTempDir)
unstrucs, err := reader.ReadSources(flagFilenames, flagImages, flagTempDir, flagExternalDataProviders)
if err != nil {
cmdutils.ErrFatalf("reading: %v", err)
}
Expand Down
9 changes: 8 additions & 1 deletion pkg/gator/reader/filereader.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

var allowedExtensions = []string{".yaml", ".yml", ".json"}

func ReadSources(filenames []string, images []string, tempDir string) ([]*unstructured.Unstructured, error) {
func ReadSources(filenames []string, images []string, tempDir string, externalDataProviderFiles []string) ([]*unstructured.Unstructured, error) {
var sources []*source

// Read from --filename flag
Expand All @@ -29,6 +29,13 @@ func ReadSources(filenames []string, images []string, tempDir string) ([]*unstru
}
sources = append(sources, s...)

// Read from --external-data-providers flag
s, err = readFiles(externalDataProviderFiles)
if err != nil {
return nil, fmt.Errorf("reading from filenames: %w", err)
}
sources = append(sources, s...)

// Read stdin
stdinUnstructs, err := readStdin()
if err != nil {
Expand Down
Loading

0 comments on commit 83e9946

Please sign in to comment.