From 123b57df2f476c69e9237623c0a4aaf917498727 Mon Sep 17 00:00:00 2001 From: Preslav Gerchev Date: Thu, 22 Feb 2024 18:42:45 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20Add=20annotations=20to=20all=20a?= =?UTF-8?q?ssets=20in=20the=20inventory.=20(#3406)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🧹 Add annotations to all assets in the inventory. Make the fallback asset a func. Signed-off-by: Preslav * Simplify ParseOrUse. --------- Signed-off-by: Preslav --- apps/cnquery/cmd/sbom.go | 2 +- cli/inventoryloader/inventory.go | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/apps/cnquery/cmd/sbom.go b/apps/cnquery/cmd/sbom.go index 38be14a650..70ac5a9579 100644 --- a/apps/cnquery/cmd/sbom.go +++ b/apps/cnquery/cmd/sbom.go @@ -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") } diff --git a/cli/inventoryloader/inventory.go b/cli/inventoryloader/inventory.go index 4e6181a2bf..a4f35b3561 100644 --- a/cli/inventoryloader/inventory.go +++ b/cli/inventoryloader/inventory.go @@ -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 @@ -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() }