mirror of
https://github.com/k8sgpt-ai/k8sgpt.git
synced 2025-09-06 01:31:15 +00:00
chore: fixing filters
Signed-off-by: Alex Jones <alexsimonjones@gmail.com>
This commit is contained in:
@@ -2,9 +2,12 @@ package integration
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/k8sgpt-ai/k8sgpt/pkg/common"
|
||||
"github.com/k8sgpt-ai/k8sgpt/pkg/integration/trivy"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
type IIntegration interface {
|
||||
@@ -17,6 +20,8 @@ type IIntegration interface {
|
||||
// RemoveAnalyzer removes an analyzer from the cluster
|
||||
RemoveAnalyzer() error
|
||||
|
||||
GetAnalyzerName() string
|
||||
|
||||
IsActivate() bool
|
||||
}
|
||||
|
||||
@@ -24,7 +29,7 @@ type Integration struct {
|
||||
}
|
||||
|
||||
var integrations = map[string]IIntegration{
|
||||
"VulnerabilityReport": trivy.NewTrivy(),
|
||||
"trivy": trivy.NewTrivy(),
|
||||
}
|
||||
|
||||
func NewIntegration() *Integration {
|
||||
@@ -55,6 +60,18 @@ func (*Integration) Activate(name string, namespace string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Update filters
|
||||
activeFilters := viper.GetStringSlice("active_filters")
|
||||
|
||||
activeFilters = append(activeFilters, integrations[name].GetAnalyzerName())
|
||||
|
||||
viper.Set("active_filters", activeFilters)
|
||||
|
||||
if err := viper.WriteConfig(); err != nil {
|
||||
color.Red("Error writing config file: %s", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -67,6 +84,24 @@ func (*Integration) Deactivate(name string, namespace string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Update filters
|
||||
// This might be a bad idea, but we cannot reference analyzer here
|
||||
activeFilters := viper.GetStringSlice("active_filters")
|
||||
|
||||
// Remove filter
|
||||
for i, v := range activeFilters {
|
||||
if v == integrations[name].GetAnalyzerName() {
|
||||
activeFilters = append(activeFilters[:i], activeFilters[i+1:]...)
|
||||
break
|
||||
}
|
||||
}
|
||||
viper.Set("active_filters", activeFilters)
|
||||
|
||||
if err := viper.WriteConfig(); err != nil {
|
||||
color.Red("Error writing config file: %s", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user