Skip to content

Commit

Permalink
🐛 fix --asset-name flag (#885)
Browse files Browse the repository at this point in the history
* 🐛 fix --asset-name flag
  • Loading branch information
mariuskimmina authored Oct 25, 2023
1 parent e8a6c6d commit 89ad8e2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions apps/cnspec/cmd/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ To manually configure a policy, use this:
viper.BindPFlag("inventory-domainlist", cmd.Flags().Lookup("inventory-domainlist"))
viper.BindPFlag("policy-bundle", cmd.Flags().Lookup("policy-bundle"))
viper.BindPFlag("detect-cicd", cmd.Flags().Lookup("detect-cicd"))
viper.BindPFlag("asset-name", cmd.Flags().Lookup("asset-name"))
viper.BindPFlag("category", cmd.Flags().Lookup("category"))
viper.BindPFlag("score-threshold", cmd.Flags().Lookup("score-threshold"))
viper.BindPFlag("share", cmd.Flags().Lookup("share"))
Expand Down Expand Up @@ -220,6 +221,14 @@ func getCobraScanConfig(cmd *cobra.Command, runtime *providers.Runtime, cliRes *
optAnnotations[k] = v
}

assetName, err := cmd.Flags().GetString("asset-name")
if err != nil {
log.Fatal().Err(err).Msg("failed to parse asset-name")
}
if assetName != "" && cliRes.Asset != nil {
cliRes.Asset.Name = assetName
}

inv, err := inventoryloader.ParseOrUse(cliRes.Asset, viper.GetBool("insecure"), optAnnotations)
if err != nil {
log.Fatal().Err(err).Msg("failed to parse inventory")
Expand Down
8 changes: 8 additions & 0 deletions policy/scan/local_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,14 @@ func (s *LocalScanner) distributeJob(job *Job, ctx context.Context, upstream *up
return nil, false, nil
}

// if there is exactly one asset, assure that the --asset-name is used
// TODO: make it so that the --asset-name is set for the root asset only even if multiple assets are there
// This is a temporary fix that only works if there is only one asset
if len(assets) == 1 && assetList[0].Name != "" && assetList[0].Name != assets[0].asset.Name {
log.Debug().Str("asset", assets[0].asset.Name).Msg("Overriding asset name with --asset-name flag")
assets[0].asset.Name = assetList[0].Name
}

runtimeEnv := execruntime.Detect()
var runtimeLabels map[string]string
// If the runtime is an automated environment and the root asset is CI/CD, then we are doing a
Expand Down

0 comments on commit 89ad8e2

Please sign in to comment.