example of an integration

Signed-off-by: Alex Jones <alexsimonjones@gmail.com>
This commit is contained in:
Alex Jones 2023-06-15 12:15:02 +01:00
parent 1bc0f42f71
commit 2b14cae5a6
No known key found for this signature in database
GPG Key ID: 24CCAE84BAB9AFC1
6 changed files with 87 additions and 1 deletions

19
demo Executable file
View File

@ -0,0 +1,19 @@
#!/bin/bash
########################
# include the magic
########################
. demo-magic.sh
# hide the evidence
clear
pe "./k8sgpt analyze --explain"
pe "./k8sgpt filter list"
pe "./k8sgpt integration list"
pe "./k8sgpt integration activate trivy"
pe "./k8sgpt analyze --filter VulnerabilityReport -o json | jq ."

View File

@ -77,6 +77,11 @@ func (a *Analysis) textOutput() ([]byte, error) {
output.WriteString(fmt.Sprintf("%s %s(%s)\n", color.CyanString("%d", n),
color.YellowString(result.Name), color.CyanString(result.ParentObject)))
for _, err := range result.Error {
if hasAIFailure(err.Text) {
err.Text = "Unable to remediate issue. Please refer to the documentation for more information."
}
output.WriteString(fmt.Sprintf("- %s %s\n", color.RedString("Error:"), color.RedString(err.Text)))
if err.KubernetesDoc != "" {
output.WriteString(fmt.Sprintf(" %s %s\n", color.RedString("Kubernetes Doc:"), color.RedString(err.KubernetesDoc)))
@ -86,3 +91,7 @@ func (a *Analysis) textOutput() ([]byte, error) {
}
return []byte(output.String()), nil
}
func hasAIFailure(text string) bool {
return strings.Contains(text, "As an AI language model")
}

View File

@ -0,0 +1,41 @@
package alex
import (
"github.com/k8sgpt-ai/k8sgpt/pkg/common"
)
// implement the IIterator interface
type Alex struct {
}
func NewAlex() *Alex {
return &Alex{}
}
func (a *Alex) Deploy(namespace string) error {
return nil
}
func (a *Alex) UnDeploy(namespace string) error {
return nil
}
func (a *Alex) AddAnalyzer(analyzers *map[string]common.IAnalyzer) {
(*analyzers)["Alex"] = NewAlexAnalyzer()
}
func (a *Alex) RemoveAnalyzer() error {
return nil
}
func (a *Alex) GetAnalyzerName() string {
return "alex"
}
func (a *Alex) IsActivate() bool {
return true
}

View File

@ -0,0 +1,15 @@
package alex
import "github.com/k8sgpt-ai/k8sgpt/pkg/common"
type AlexAnalyzer struct {
}
func NewAlexAnalyzer() *AlexAnalyzer {
return &AlexAnalyzer{}
}
func (*AlexAnalyzer) Analyze(analysis common.Analyzer) ([]common.Result, error) {
return nil, nil
}

View File

@ -20,6 +20,7 @@ import (
"github.com/fatih/color"
"github.com/k8sgpt-ai/k8sgpt/pkg/common"
"github.com/k8sgpt-ai/k8sgpt/pkg/integration/alex"
"github.com/k8sgpt-ai/k8sgpt/pkg/integration/trivy"
"github.com/k8sgpt-ai/k8sgpt/pkg/util"
"github.com/spf13/viper"
@ -45,6 +46,7 @@ type Integration struct {
var integrations = map[string]IIntegration{
"trivy": trivy.NewTrivy(),
"alex": alex.NewAlex(),
}
func NewIntegration() *Integration {

View File

@ -53,7 +53,7 @@ func (TrivyAnalyzer) Analyze(a common.Analyzer) ([]common.Result, error) {
// For each pod there may be multiple vulnerabilities
var failures []common.Failure
for _, vuln := range report.Report.Vulnerabilities {
if vuln.Severity == "CRITICAL" {
if vuln.Severity == "CRITICAL" || vuln.Severity == "HIGH" {
// get the vulnerability ID
// get the vulnerability description
failures = append(failures, common.Failure{