Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ add more asset info to mondoo provider #4465

Merged
merged 2 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion providers/mondoo/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (s *Service) initResources(runtime *plugin.Runtime) error {
conn := runtime.Connection.(*connection.Connection)
var err error

_, err = resources.CreateResource(runtime, "mondoo.agent", map[string]*llx.RawData{
_, err = resources.CreateResource(runtime, "mondoo.client", map[string]*llx.RawData{
"mrn": llx.StringData(conn.Upstream.Creds.Mrn),
})
if err != nil {
Expand Down
49 changes: 46 additions & 3 deletions providers/mondoo/resources/mondoo.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ package resources

import (
"context"
"time"

"go.mondoo.com/cnquery/v11/explorer/resources"
"go.mondoo.com/cnquery/v11/llx"
"go.mondoo.com/cnquery/v11/providers/mondoo/connection"
"go.mondoo.com/cnquery/v11/types"
"go.mondoo.com/cnquery/v11/utils/multierr"
"go.mondoo.com/mondoo-go"
)
Expand All @@ -26,6 +28,11 @@ func (m *mqlMondooSpace) assets() ([]any, error) {
State string
Name string
AssetType string `graphql:"asset_type"`
CreatedAt *string
UpdatedAt *string
// Annotations map[string]string
Annotations []keyValue
Labels []keyValue
}
}
} `graphql:"assets(spaceMrn: $spaceMrn)"`
Expand All @@ -43,9 +50,13 @@ func (m *mqlMondooSpace) assets() ([]any, error) {
for i := range q.Assets.Edges {
e := q.Assets.Edges[i]
raw, err := CreateResource(m.MqlRuntime, "mondoo.asset", map[string]*llx.RawData{
"name": llx.StringData(e.Node.Name),
"mrn": llx.StringData(e.Node.Mrn),
"platform": llx.StringData(e.Node.AssetType),
"name": llx.StringData(e.Node.Name),
"mrn": llx.StringData(e.Node.Mrn),
"platform": llx.StringData(e.Node.AssetType),
"annotations": llx.MapData(keyvals2map(e.Node.Annotations), types.Map(types.String, types.String)),
"labels": llx.MapData(keyvals2map(e.Node.Labels), types.Map(types.String, types.String)),
"createdAt": llx.TimeDataPtr(string2time(e.Node.CreatedAt)),
"updatedAt": llx.TimeDataPtr(string2time(e.Node.UpdatedAt)),
})
if err != nil {
return nil, err
Expand All @@ -56,6 +67,38 @@ func (m *mqlMondooSpace) assets() ([]any, error) {
return res, nil
}

type keyValue struct {
Key string
Value *string
}

func keyvals2map(keyvals []keyValue) map[string]any {
if len(keyvals) == 0 {
return nil
}
res := make(map[string]any, len(keyvals))
for i := range keyvals {
cur := keyvals[i]
if cur.Value == nil {
res[cur.Key] = ""
} else {
res[cur.Key] = *cur.Value
}
}
return res
}

func string2time(s *string) *time.Time {
if s == nil {
return nil
}
res, err := time.Parse(time.RFC3339, *s)
if err != nil {
return nil
}
return &res
}

func (m *mqlMondooAsset) id() (string, error) {
return m.Mrn.Data, nil
}
Expand Down
10 changes: 9 additions & 1 deletion providers/mondoo/resources/mondoo.lr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ option provider = "go.mondoo.com/cnquery/v11/providers/mondoo"
option go_package = "go.mondoo.com/cnquery/v11/providers/mondoo/resources"

// Mondoo Client
mondoo.agent @defaults("mrn") {
mondoo.client @defaults("mrn") {
// Client identifier
mrn string
}
Expand All @@ -31,6 +31,14 @@ private mondoo.asset @defaults("name platform") {
mrn string
// Platform name
platform string
// Annotations associated with this asset
annotations map[string]string
// Labels associated with this asset
labels map[string]string
// Time this asset was created
createdAt time
// Time this asset was last updated
updatedAt time
// Asset resources
resources() []mondoo.resource
}
Expand Down
89 changes: 69 additions & 20 deletions providers/mondoo/resources/mondoo.lr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions providers/mondoo/resources/mondoo.lr.manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,20 @@ resources:
min_mondoo_version: 9.0.0
mondoo.asset:
fields:
annotations: {}
createdAt: {}
labels: {}
mrn: {}
name: {}
platform: {}
resources: {}
updatedAt: {}
is_private: true
min_mondoo_version: 9.0.0
mondoo.client:
fields:
mrn: {}
min_mondoo_version: 9.0.0
mondoo.resource:
fields:
id: {}
Expand Down
Loading