Azure / ShieldGuard

Enables best security practices for your project from day zero.
MIT License
8 stars 6 forks source link

Implement TextEncoder for better readability #34

Closed bcho closed 1 year ago

bcho commented 1 year ago

When using sg from local, we should provide a TextEncoder for better readability. Similar to the JSON encoder, we can implement like this:

// sg/internal/result/presenter/text.go

func Text(queryResultsList []result.QueryResults) WriteQueryResultTo {
        return writeQueryResultToFunc(func(w io.Writer) error {
        for _, queryResult := range queryResultsList { // TODO: maybe we should sort & group results before iterating them
                  fmt.Fprintf(w, "%s - %s - %s", <kind>, <file-path>, <message>)
                }
    })
}

conftest is providing similar output like this:

$ conftest test -p ./sg/internal/cli/test/testdata/bug25/policy ./sg/internal/cli/test/testdata/bug25/configurations/data.json
WARN - ./sg/internal/cli/test/testdata/bug25/configurations/data.json - main - foo is not allowed
FAIL - ./sg/internal/cli/test/testdata/bug25/configurations/data.json - main - foo is not allowed
FAIL - ./sg/internal/cli/test/testdata/bug25/configurations/data.json - main - foo is not allowed
bcho commented 1 year ago

conftest's implementation for reference: https://github.com/open-policy-agent/conftest/blob/55834493ce76e76241479ede4e3c711010a7bf5c/output/standard.go#L63-L96