-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #160 from brendanjryan/bjr-output-formatters
breaks out output logger into standard interface
- Loading branch information
Showing
2 changed files
with
69 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package kubeval | ||
|
||
import ( | ||
"github.com/instrumenta/kubeval/log" | ||
) | ||
|
||
// TODO (brendanryan) move these structs to `/log` once we have removed the potential | ||
// circular dependancy between this package and `/log` | ||
|
||
// OutputManager controls how results of the `kubeval` evaluation will be recorded | ||
// and reported to the end user. | ||
type OutputManager interface { | ||
Put(r ValidationResult) error | ||
Flush() error | ||
} | ||
|
||
// STDOutputManager reports `kubeval` results to stdout. | ||
type STDOutputManager struct { | ||
} | ||
|
||
// NewSTDOutputManager instantiates a new instance of STDOutputManager. | ||
func NewSTDOutputManager() *STDOutputManager { | ||
return &STDOutputManager{} | ||
} | ||
|
||
func (s *STDOutputManager) Put(result ValidationResult) error { | ||
if len(result.Errors) > 0 { | ||
log.Warn("The file", result.FileName, "contains an invalid", result.Kind) | ||
for _, desc := range result.Errors { | ||
log.Info("--->", desc) | ||
} | ||
} else if result.Kind == "" { | ||
log.Success("The file", result.FileName, "contains an empty YAML document") | ||
} else if !result.ValidatedAgainstSchema { | ||
log.Warn("The file", result.FileName, "containing a", result.Kind, "was not validated against a schema") | ||
} else { | ||
log.Success("The file", result.FileName, "contains a valid", result.Kind) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (s *STDOutputManager) Flush() error { | ||
// no op | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters