Skip to content

Commit

Permalink
🐛 fix --asset-name flag (#2365)
Browse files Browse the repository at this point in the history
  • Loading branch information
mariuskimmina authored Oct 25, 2023
1 parent c699657 commit 48bba9c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions apps/cnquery/cmd/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ To manually configure a query pack, use this:
viper.BindPFlag("inventory-domainlist", cmd.Flags().Lookup("inventory-domainlist"))
viper.BindPFlag("querypack-bundle", cmd.Flags().Lookup("querypack-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"))

// for all assets
Expand Down Expand Up @@ -176,6 +177,15 @@ func getCobraScanConfig(cmd *cobra.Command, runtime *providers.Runtime, cliRes *
for k, v := range annotations {
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 explorer/scan/local_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,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
}

justAssets := []*inventory.Asset{}
for _, asset := range assets {
asset.asset.KindString = asset.asset.GetPlatform().Kind
Expand Down

0 comments on commit 48bba9c

Please sign in to comment.