mirror of
https://github.com/kubescape/kubescape.git
synced 2026-04-15 06:58:11 +00:00
Add mock logger
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/armosec/kubescape/cautils/logger/helpers"
|
||||
"github.com/armosec/kubescape/cautils/logger/mocklogger"
|
||||
"github.com/armosec/kubescape/cautils/logger/prettylogger"
|
||||
"github.com/armosec/kubescape/cautils/logger/zaplogger"
|
||||
"github.com/mattn/go-isatty"
|
||||
@@ -27,6 +28,7 @@ type ILogger interface {
|
||||
|
||||
var l ILogger
|
||||
|
||||
// Return initialized logger. If logger not initialized, will call InitializeLogger() with the default value
|
||||
func L() ILogger {
|
||||
if l == nil {
|
||||
InitializeLogger("")
|
||||
@@ -34,13 +36,35 @@ func L() ILogger {
|
||||
return l
|
||||
}
|
||||
|
||||
/* InitializeLogger initialize desired logger
|
||||
|
||||
Use:
|
||||
InitializeLogger("<logger name>")
|
||||
|
||||
Supported logger names
|
||||
- "zap": Logger from package "go.uber.org/zap"
|
||||
- "pretty", "colorful": Human friendly colorful logger
|
||||
- "mock", "empty", "ignore": Logger will be totally ignored
|
||||
|
||||
e.g.
|
||||
InitializeLogger("mock") -> will initialize the mock logger
|
||||
|
||||
Default:
|
||||
If isatty.IsTerminal(os.Stdout.Fd()):
|
||||
"pretty"
|
||||
else
|
||||
"zap"
|
||||
|
||||
*/
|
||||
func InitializeLogger(loggerName string) {
|
||||
|
||||
switch strings.ToLower(loggerName) {
|
||||
case "zap":
|
||||
l = zaplogger.NewZapLogger()
|
||||
case "pretty":
|
||||
case "pretty", "colorful":
|
||||
l = prettylogger.NewPrettyLogger()
|
||||
case "mock", "empty", "ignore":
|
||||
l = mocklogger.NewMockLogger()
|
||||
default:
|
||||
if isatty.IsTerminal(os.Stdout.Fd()) {
|
||||
l = prettylogger.NewPrettyLogger()
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package mocklogger
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/armosec/kubescape/cautils/logger/helpers"
|
||||
)
|
||||
|
||||
type MockLogger struct {
|
||||
}
|
||||
|
||||
func NewMockLogger() *MockLogger {
|
||||
return &MockLogger{}
|
||||
}
|
||||
|
||||
func (zl *MockLogger) GetLevel() string { return "" }
|
||||
func (zl *MockLogger) SetWriter(w *os.File) {}
|
||||
func (zl *MockLogger) GetWriter() *os.File { return nil }
|
||||
func (zl *MockLogger) SetLevel(level string) error { return nil }
|
||||
func (zl *MockLogger) Fatal(msg string, details ...helpers.IDetails) {}
|
||||
func (zl *MockLogger) Error(msg string, details ...helpers.IDetails) {}
|
||||
func (zl *MockLogger) Warning(msg string, details ...helpers.IDetails) {}
|
||||
func (zl *MockLogger) Success(msg string, details ...helpers.IDetails) {}
|
||||
func (zl *MockLogger) Info(msg string, details ...helpers.IDetails) {}
|
||||
func (zl *MockLogger) Debug(msg string, details ...helpers.IDetails) {}
|
||||
@@ -35,7 +35,6 @@ func NewZapLogger() *ZapLogger {
|
||||
func (zl *ZapLogger) GetLevel() string { return zl.cfg.Level.Level().String() }
|
||||
func (zl *ZapLogger) SetWriter(w *os.File) {}
|
||||
func (zl *ZapLogger) GetWriter() *os.File { return nil }
|
||||
func GetWriter() *os.File { return nil }
|
||||
|
||||
func (zl *ZapLogger) SetLevel(level string) error {
|
||||
l := zapcore.Level(1)
|
||||
|
||||
@@ -77,7 +77,7 @@ var resultsCmd = &cobra.Command{
|
||||
var r reporter.IReport
|
||||
switch formatVersion {
|
||||
case "v2":
|
||||
r = reporterv2.NewReportEventReceiver(clusterConfig.GetConfigObj())
|
||||
r = reporterv2.NewReportEventReceiver(clusterConfig.GetConfigObj(), "")
|
||||
default:
|
||||
logger.L().Warning("Deprecated results version. run with '--format-version' flag", helpers.String("your version", formatVersion), helpers.String("latest version", "v2"))
|
||||
r = reporterv1.NewReportEventReceiver(clusterConfig.GetConfigObj())
|
||||
|
||||
@@ -4,7 +4,7 @@ type PostScanRequest struct {
|
||||
Format string `json:"format"` // Format results (table, json, junit ...) - default json
|
||||
ExcludedNamespaces []string `json:"excludedNamespaces"` // used for host sensor namespace
|
||||
IncludeNamespaces []string `json:"includeNamespaces"` // DEPRECATED?
|
||||
FailThreshold uint16 `json:"failThreshold"` // Failure score threshold
|
||||
FailThreshold float32 `json:"failThreshold"` // Failure score threshold
|
||||
Submit bool `json:"submit"` // Submit results to Armo BE - default will
|
||||
HostSensor bool `json:"hostSensor"` // Deploy ARMO K8s host sensor to collect data from certain controls
|
||||
KeepLocal bool `json:"keepLocal"` // Do not submit results
|
||||
|
||||
@@ -17,7 +17,7 @@ func (scanRequest *PostScanRequest) ToScanInfo() *cautils.ScanInfo {
|
||||
|
||||
scanInfo.Local = scanRequest.KeepLocal
|
||||
scanInfo.Submit = scanRequest.Submit
|
||||
scanInfo.HostSensor.SetBool(scanRequest.HostSensor)
|
||||
scanInfo.HostSensorEnabled.SetBool(scanRequest.HostSensor)
|
||||
|
||||
return &scanInfo
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ func setScanInfo() *cautils.ScanInfo {
|
||||
scanInfo.Format = "prometheus"
|
||||
scanInfo.ScanAll = true
|
||||
scanInfo.FrameworkScan = true
|
||||
scanInfo.HostSensor.Set(os.Getenv("KS_ENABLE_HOST_SENSOR"))
|
||||
scanInfo.HostSensorEnabled.Set(os.Getenv("KS_ENABLE_HOST_SENSOR"))
|
||||
scanInfo.Output = "results"
|
||||
scanInfo.FailThreshold = 100
|
||||
scanInfo.SetPolicyIdentifiers(getter.NativeFrameworks, reporthandling.KindFramework)
|
||||
|
||||
Reference in New Issue
Block a user