From 2b14cae5a68cc8ee015fb4ed56fb39949f112ff3 Mon Sep 17 00:00:00 2001 From: Alex Jones Date: Thu, 15 Jun 2023 12:15:02 +0100 Subject: [PATCH] example of an integration Signed-off-by: Alex Jones --- demo | 19 ++++++++++++++ pkg/analysis/output.go | 9 +++++++ pkg/integration/alex/alex.go | 41 +++++++++++++++++++++++++++++++ pkg/integration/alex/analyzer.go | 15 +++++++++++ pkg/integration/integration.go | 2 ++ pkg/integration/trivy/analyzer.go | 2 +- 6 files changed, 87 insertions(+), 1 deletion(-) create mode 100755 demo create mode 100644 pkg/integration/alex/alex.go create mode 100644 pkg/integration/alex/analyzer.go diff --git a/demo b/demo new file mode 100755 index 0000000..d1f37e6 --- /dev/null +++ b/demo @@ -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 ." diff --git a/pkg/analysis/output.go b/pkg/analysis/output.go index f65503d..7156c29 100644 --- a/pkg/analysis/output.go +++ b/pkg/analysis/output.go @@ -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") +} diff --git a/pkg/integration/alex/alex.go b/pkg/integration/alex/alex.go new file mode 100644 index 0000000..5cd2c26 --- /dev/null +++ b/pkg/integration/alex/alex.go @@ -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 +} diff --git a/pkg/integration/alex/analyzer.go b/pkg/integration/alex/analyzer.go new file mode 100644 index 0000000..059207b --- /dev/null +++ b/pkg/integration/alex/analyzer.go @@ -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 +} diff --git a/pkg/integration/integration.go b/pkg/integration/integration.go index 0e8b6c4..acf34d2 100644 --- a/pkg/integration/integration.go +++ b/pkg/integration/integration.go @@ -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 { diff --git a/pkg/integration/trivy/analyzer.go b/pkg/integration/trivy/analyzer.go index 486a280..62aa9d7 100644 --- a/pkg/integration/trivy/analyzer.go +++ b/pkg/integration/trivy/analyzer.go @@ -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{