-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(misconf): scanning support for YAML and JSON
Signed-off-by: nikpivkin <[email protected]>
- Loading branch information
Showing
5 changed files
with
102 additions
and
8 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
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,36 @@ | ||
package json | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer" | ||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer/config" | ||
"github.com/aquasecurity/trivy/pkg/misconf" | ||
) | ||
|
||
const ( | ||
analyzerType = analyzer.TypeJSON | ||
version = 1 | ||
) | ||
|
||
func init() { | ||
analyzer.RegisterPostAnalyzer(analyzerType, newJSONConfigAnalyzer) | ||
} | ||
|
||
// jsonConfigAnalyzer analyzes JSON files | ||
type jsonConfigAnalyzer struct { | ||
*config.Analyzer | ||
} | ||
|
||
func newJSONConfigAnalyzer(opts analyzer.AnalyzerOptions) (analyzer.PostAnalyzer, error) { | ||
a, err := config.NewAnalyzer(analyzerType, version, misconf.NewJSONScanner, opts) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &jsonConfigAnalyzer{Analyzer: a}, nil | ||
} | ||
|
||
func (*jsonConfigAnalyzer) Required(filePath string, _ os.FileInfo) bool { | ||
return filepath.Ext(filePath) == ".json" | ||
} |
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,36 @@ | ||
package yaml | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer" | ||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer/config" | ||
"github.com/aquasecurity/trivy/pkg/misconf" | ||
) | ||
|
||
const ( | ||
analyzerType = analyzer.TypeYAML | ||
version = 1 | ||
) | ||
|
||
func init() { | ||
analyzer.RegisterPostAnalyzer(analyzerType, newYAMLConfigAnalyzer) | ||
} | ||
|
||
// yamlConfigAnalyzer analyzes YAML files | ||
type yamlConfigAnalyzer struct { | ||
*config.Analyzer | ||
} | ||
|
||
func newYAMLConfigAnalyzer(opts analyzer.AnalyzerOptions) (analyzer.PostAnalyzer, error) { | ||
a, err := config.NewAnalyzer(analyzerType, version, misconf.NewYAMLScanner, opts) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &yamlConfigAnalyzer{Analyzer: a}, nil | ||
} | ||
|
||
func (*yamlConfigAnalyzer) Required(filePath string, _ os.FileInfo) bool { | ||
return filepath.Ext(filePath) == ".yaml" || filepath.Ext(filePath) == ".yml" | ||
} |
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
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