Skip to content

Commit

Permalink
🧹 Add function to load the asset url schema for all known providers
Browse files Browse the repository at this point in the history
  • Loading branch information
jaym committed Mar 22, 2024
1 parent 19b6627 commit 5406445
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions providers/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

0 comments on commit 5406445

Please sign in to comment.