From 5406445758873ede543dda40d0372d30710882cb Mon Sep 17 00:00:00 2001 From: Jay Mundrawala Date: Fri, 22 Mar 2024 11:46:46 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20Add=20function=20to=20load=20the?= =?UTF-8?q?=20asset=20url=20schema=20for=20all=20known=20providers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- providers/providers.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/providers/providers.go b/providers/providers.go index 0fd65176db..2cdc429e28 100644 --- a/providers/providers.go +++ b/providers/providers.go @@ -24,6 +24,7 @@ import ( "github.com/spf13/afero" "github.com/ulikunitz/xz" "go.mondoo.com/cnquery/v10/cli/config" + "go.mondoo.com/cnquery/v10/providers-sdk/v1/inventory" "go.mondoo.com/cnquery/v10/providers-sdk/v1/plugin" "go.mondoo.com/cnquery/v10/providers-sdk/v1/resources" "golang.org/x/exp/slices" @@ -869,3 +870,29 @@ func convertToFields(keysAndValues ...interface{}) map[string]interface{} { } return fields } + +func LoadAssetUrlSchema() (*inventory.AssetUrlSchema, error) { + providers, err := ListAll() + if err != nil { + return nil, err + } + + s, err := inventory.NewAssetUrlSchema("technology") + if err != nil { + return nil, err + } + + for _, provider := range providers { + for _, b := range provider.AssetUrlTrees { + if err := s.Add(b); err != nil { + return nil, err + } + } + } + + if err := s.RefreshCache(); err != nil { + return nil, err + } + + return s, nil +}