Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Pass in config and user-provided annotations. #799

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions apps/cnspec/cmd/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ type scanConfig struct {
PolicyPaths []string
PolicyNames []string
Props map[string]string
Annotations map[string]string
Bundle *policy.Bundle
runtime *providers.Runtime

Expand All @@ -211,6 +212,20 @@ func getCobraScanConfig(cmd *cobra.Command, runtime *providers.Runtime, cliRes *
if err != nil {
log.Fatal().Err(err).Msg("failed to parse inventory")
}

annotations, err := cmd.Flags().GetStringToString("annotation")
if err != nil {
log.Fatal().Err(err).Msg("failed to parse annotations")
}

// merge the config and the user-provided annotations with the latter having precedence
optAnnotations := opts.Annotations
if optAnnotations == nil {
optAnnotations = map[string]string{}
}
for k, v := range annotations {
optAnnotations[k] = v
}
conf := scanConfig{
Features: opts.GetFeatures(),
IsIncognito: viper.GetBool("incognito"),
Expand All @@ -220,6 +235,7 @@ func getCobraScanConfig(cmd *cobra.Command, runtime *providers.Runtime, cliRes *
ScoreThreshold: viper.GetInt("score-threshold"),
Props: props,
runtime: runtime,
Annotations: optAnnotations,
}

// if users want to get more information on available output options,
Expand Down Expand Up @@ -332,6 +348,7 @@ func RunScan(config *scanConfig, scannerOpts ...scan.ScannerOption) (*policy.Rep
Bundle: config.Bundle,
PolicyFilters: config.PolicyNames,
Props: config.Props,
Annotations: config.Annotations,
})
} else {
res, err = scanner.Run(
Expand All @@ -341,6 +358,7 @@ func RunScan(config *scanConfig, scannerOpts ...scan.ScannerOption) (*policy.Rep
Bundle: config.Bundle,
PolicyFilters: config.PolicyNames,
Props: config.Props,
Annotations: config.Annotations,
})
}

Expand Down
2 changes: 2 additions & 0 deletions policy/scan/local_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ func (s *LocalScanner) distributeJob(job *Job, ctx context.Context, upstream *up

justAssets := []*inventory.Asset{}
for _, asset := range assets {
// apply all annotations to the assets to be scanned
asset.asset.AddAnnotations(job.GetAnnotations())
asset.asset.KindString = asset.asset.GetPlatform().Kind
for k, v := range runtimeLabels {
if asset.asset.Labels == nil {
Expand Down
Loading