Skip to content

Commit

Permalink
chore: change prefixes from checks to misconfig
Browse files Browse the repository at this point in the history
Signed-off-by: knqyf263 <knqyf263@gmail.com>
  • Loading branch information
knqyf263 committed Oct 2, 2024
1 parent 6d648a8 commit d8bfa99
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 16 deletions.
8 changes: 4 additions & 4 deletions pkg/commands/artifact/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,19 +618,19 @@ func (r *runner) scan(ctx context.Context, opts flag.Options, initializeScanner
}

func initMisconfScannerOption(ctx context.Context, opts flag.Options) (misconf.ScannerOption, error) {
logger := log.WithPrefix(log.PrefixMisconfiguration)
logger.Info("Misconfiguration scanning is enabled")
ctx = log.WithContextPrefix(ctx, log.PrefixMisconfiguration)
log.InfoContext(ctx, "Misconfiguration scanning is enabled")

var downloadedPolicyPaths []string
var disableEmbedded bool

downloadedPolicyPaths, err := operation.InitBuiltinChecks(ctx, opts.CacheDir, opts.Quiet, opts.SkipCheckUpdate, opts.MisconfOptions.ChecksBundleRepository, opts.RegistryOpts())
if err != nil {
if !opts.SkipCheckUpdate {
logger.Error("Falling back to embedded checks", log.Err(err))
log.ErrorContext(ctx, "Falling back to embedded checks", log.Err(err))
}
} else {
logger.Debug("Checks successfully loaded from disk")
log.DebugContext(ctx, "Checks successfully loaded from disk")
disableEmbedded = true
}

Expand Down
1 change: 0 additions & 1 deletion pkg/commands/operation/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ func InitBuiltinChecks(ctx context.Context, cacheDir string, quiet, skipUpdate b
mu.Lock()
defer mu.Unlock()

ctx = log.WithContextPrefix(ctx, log.PrefixChecksBundle)
client, err := policy.NewClient(cacheDir, quiet, checkBundleRepository)
if err != nil {
return nil, xerrors.Errorf("check client error: %w", err)
Expand Down
14 changes: 5 additions & 9 deletions pkg/k8s/commands/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func clusterRun(ctx context.Context, opts flag.Options, cluster k8s.Cluster) err
trivyk8s.WithExcludeOwned(opts.ExcludeOwned),
}
if opts.Scanners.AnyEnabled(types.MisconfigScanner) && !opts.DisableNodeCollector {
artifacts, err = trivyk8s.New(cluster, k8sOpts...).ListArtifactAndNodeInfo(ctx, nodeCollectorOptions(opts)...)
artifacts, err = trivyk8s.New(cluster, k8sOpts...).ListArtifactAndNodeInfo(ctx, nodeCollectorOptions(ctx, opts)...)
if err != nil {
return xerrors.Errorf("get k8s artifacts with node info error: %w", err)
}
Expand All @@ -59,21 +59,17 @@ func clusterRun(ctx context.Context, opts flag.Options, cluster k8s.Cluster) err
return runner.run(ctx, artifacts)
}

func nodeCollectorOptions(opts flag.Options) []trivyk8s.NodeCollectorOption {
func nodeCollectorOptions(ctx context.Context, opts flag.Options) []trivyk8s.NodeCollectorOption {
nodeCollectorOptions := []trivyk8s.NodeCollectorOption{
trivyk8s.WithScanJobNamespace(opts.NodeCollectorNamespace),
trivyk8s.WithIgnoreLabels(opts.ExcludeNodes),
trivyk8s.WithScanJobImageRef(opts.NodeCollectorImageRef),
trivyk8s.WithTolerations(opts.Tolerations),
}

contentPath, err := operation.InitBuiltinChecks(context.Background(),
opts.CacheDir,
opts.Quiet,
opts.SkipCheckUpdate,
opts.MisconfOptions.ChecksBundleRepository,
opts.RegistryOpts())

ctx = log.WithContextPrefix(ctx, log.PrefixMisconfiguration)
contentPath, err := operation.InitBuiltinChecks(ctx, opts.CacheDir, opts.Quiet, opts.SkipCheckUpdate,
opts.MisconfOptions.ChecksBundleRepository, opts.RegistryOpts())
if err != nil {
log.Error("Falling back to embedded checks", log.Err(err))
nodeCollectorOptions = append(nodeCollectorOptions,
Expand Down
1 change: 0 additions & 1 deletion pkg/log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const (
PrefixLicense = "license"
PrefixVulnerabilityDB = "vulndb"
PrefixJavaDB = "javadb"
PrefixChecksBundle = "checks"
)

// Logger is an alias of slog.Logger
Expand Down
2 changes: 1 addition & 1 deletion pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func NewVersionInfo(cacheDir string) VersionInfo {
log.Debug("Failed to instantiate policy client", log.Err(err))
}
if pc != nil && err == nil {
ctx := log.WithContextPrefix(context.TODO(), log.PrefixChecksBundle)
ctx := log.WithContextPrefix(context.TODO(), log.PrefixMisconfiguration)
pbMetaRaw, err := pc.GetMetadata(ctx)

if err != nil {
Expand Down

0 comments on commit d8bfa99

Please sign in to comment.