feat: initial custom analysis server mode (#1205)

* chore: initial custom analysis

Signed-off-by: Alex Jones <alexsimonjones@gmail.com>

* chore: saving the missing stuff

Signed-off-by: Alex Jones <alexsimonjones@gmail.com>

* chore: removed redundant error handling

Signed-off-by: Alex Jones <alexsimonjones@gmail.com>

* chore: missing piece of the custom analysis response

Signed-off-by: Alex Jones <alexsimonjones@gmail.com>

---------

Signed-off-by: Alex Jones <alexsimonjones@gmail.com>
Signed-off-by: AlexsJones <alexsimonjones@gmail.com>
This commit is contained in:
Alex Jones
2024-08-04 21:03:34 +01:00
committed by GitHub
parent 3547c4808a
commit 16d57e5a55
5 changed files with 62 additions and 11 deletions

View File

@@ -160,6 +160,14 @@ func NewAnalysis(
return a, nil
}
func (a *Analysis) CustomAnalyzersAreAvailable() bool {
var customAnalyzers []custom.CustomAnalyzer
if err := viper.UnmarshalKey("custom_analyzers", &customAnalyzers); err != nil {
return false
}
return len(customAnalyzers) > 0
}
func (a *Analysis) RunCustomAnalysis() {
var customAnalyzers []custom.CustomAnalyzer
if err := viper.UnmarshalKey("custom_analyzers", &customAnalyzers); err != nil {
@@ -184,6 +192,12 @@ func (a *Analysis) RunCustomAnalysis() {
}
result, err := canClient.Run()
if result.Kind == "" {
// for custom analyzer name, we must use a lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, '-' or '.',
//and must start and end with an alphanumeric character (e.g. 'example.com',
//regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*')
result.Kind = cAnalyzer.Name
}
if err != nil {
mutex.Lock()
a.Errors = append(a.Errors, fmt.Sprintf("[%s] %s", cAnalyzer.Name, err))