Azure/ShieldGuard

Implement TextEncoder for better readability

bcho opened this issue · 1 comments

bcho commented

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