Skip to content

Commit

Permalink
🧹 Add annotations to all assets in the inventory. (#3406)
Browse files Browse the repository at this point in the history
* 🧹 Add annotations to all assets in the inventory. Make the fallback asset a func.

Signed-off-by: Preslav <[email protected]>

* Simplify ParseOrUse.

---------

Signed-off-by: Preslav <[email protected]>
  • Loading branch information
preslavgerchev authored Feb 22, 2024
1 parent 1548a89 commit 123b57d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion apps/cnquery/cmd/sbom.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ var sbomCmdRun = func(cmd *cobra.Command, runtime *providers.Runtime, cliRes *pl
if len(boms) > 1 {
filename = fmt.Sprintf("%s-%d.%s", path.Base(outputTarget), i, path.Ext(outputTarget))
}
err := os.WriteFile(filename, output.Bytes(), 0600)
err := os.WriteFile(filename, output.Bytes(), 0o600)
if err != nil {
log.Fatal().Err(err).Msg("failed to write SBOM to file")
}
Expand Down
13 changes: 8 additions & 5 deletions cli/inventoryloader/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func parseDomainListInventory(data []byte) (*inventory.Inventory, error) {

// ParseOrUse tries to load the inventory and if nothing exists it
// will instead use the provided asset.
func ParseOrUse(cliAsset *inventory.Asset, insecure bool, annotations map[string]string) (*inventory.Inventory, error) {
func ParseOrUse(asset *inventory.Asset, insecure bool, annotations map[string]string) (*inventory.Inventory, error) {
var v1inventory *inventory.Inventory
var err error

Expand All @@ -147,13 +147,16 @@ func ParseOrUse(cliAsset *inventory.Asset, insecure bool, annotations map[string
}

// add asset from cli to inventory
if (len(v1inventory.Spec.GetAssets()) == 0) && cliAsset != nil {
cliAsset.AddAnnotations(annotations)
v1inventory.AddAssets(cliAsset)
if len(v1inventory.Spec.GetAssets()) == 0 && asset != nil {
v1inventory.AddAssets(asset)
}

for _, asset := range v1inventory.Spec.GetAssets() {
asset.AddAnnotations(annotations)
}

// if the --insecure flag is set, we overwrite the individual setting for the asset
if insecure == true {
if insecure {
v1inventory.MarkConnectionsInsecure()
}

Expand Down

0 comments on commit 123b57d

Please sign in to comment.