Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase YAML buffer & more up to date deps #2

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"github.com/spf13/cobra"
"io"
"io/ioutil"
jsonutil "k8s.io/apimachinery/pkg/util/json"
yamlutil "k8s.io/apimachinery/pkg/util/yaml"
"os"
Expand All @@ -27,12 +26,16 @@ var tmpPluginDir = ".gatekeeper-conftest/"
var rootCmd = &cobra.Command{
Use: "gatekeeper [flags] k8s_file.yaml -- [flags to pass to `conftest test`]",
Short: "conftest plugin to make input compatible with gatekeeper constrint templates",
Long: `This plugin tranforms input into the format (input.review.object) expected by
Long: `This plugin tranforms input into the format (input.review.object) expected by
gatekeeper's constraint templates allowing you to reuse the policies with conftest`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) < 1 {
fmt.Println("Error: Missing input.\n\nHelp:")
cmd.Help()
err := cmd.Help()
if err != nil {
fmt.Printf("Error: %s\n", err)
}

os.Exit(5)
}
err := runTests(args, parametersFile)
Expand All @@ -56,10 +59,6 @@ func init() {
rootCmd.Flags().StringVarP(&parametersFile, "parameters", "p", "", "path to file conatining paramater values used in constraint templates")
}

func createFile(filename string, contents string) {

}

func runTests(args []string, parametersFile string) error {
inputFile := args[0]

Expand Down Expand Up @@ -91,10 +90,19 @@ func runTests(args []string, parametersFile string) error {
return fmt.Errorf("Expecting file for parameters. Got directory.")
}

parametersYaml, err := ioutil.ReadFile(parametersFile)
// Open the file for reading
file, err := os.Open(parametersFile)
if err != nil {
return fmt.Errorf("open parameters file: %w", err)
}
defer file.Close()

// Read the file contents
parametersYaml, err := io.ReadAll(file)
if err != nil {
return fmt.Errorf("read parameters file: %w", err)
}

parametersJson, err := yamlutil.ToJSON(parametersYaml)
if err != nil {
return fmt.Errorf("convert parameters yaml to json: %w", err)
Expand Down Expand Up @@ -129,7 +137,7 @@ func runTests(args []string, parametersFile string) error {
}

yamlReader := yamlutil.NewDocumentDecoder(inputFileReader)
yamlBuf := make([]byte, 10*1024)
yamlBuf := make([]byte, 2048*1024)

// build gatekeeper compatible input object for each yaml document found in input manifest
for {
Expand Down
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ module github.com/clover/gatekeeper-conftest
go 1.16

require (
github.com/spf13/cobra v1.1.3
k8s.io/apimachinery v0.21.1
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/spf13/cobra v1.5.0
k8s.io/apimachinery v0.24.5
sigs.k8s.io/yaml v1.3.0 // indirect
)
329 changes: 70 additions & 259 deletions go.sum

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading