diff --git a/llx/builtin_resource.go b/llx/builtin_resource.go index 88b5aa704f..f142ed5692 100644 --- a/llx/builtin_resource.go +++ b/llx/builtin_resource.go @@ -8,7 +8,6 @@ import ( "strconv" "time" - "github.com/rs/zerolog/log" "go.mondoo.com/cnquery/types" ) @@ -86,21 +85,17 @@ func _resourceWhereV2(e *blockExecutor, bind *RawData, chunk *Chunk, ref uint64, // get all mandatory args resourceInfo := e.ctx.runtime.Schema().Lookup(resource.MqlName()) - args := map[string]*Primitive{ - "list": ArrayPrimitive(resList, ct), - } + copyFields := []string{} for k, v := range resourceInfo.Fields { if k != "list" && v.IsMandatory { - log.Error().Msg("found a mandatory argument for list, which is not supported: " + k + " for list of " + resource.MqlName()) - // e.ctx.runtime.WatchAndUpdate(resource, k, blockId, func(res interface{}, err error) { - // if err == nil { - // args[k] = v - // } - // }) + copyFields = append(copyFields, k) } } + args := map[string]*Primitive{ + "list": ArrayPrimitive(resList, ct), + } - resResource, err := e.ctx.runtime.CreateResourceWithID(resource.MqlName(), blockId, args) + resResource, err := e.ctx.runtime.CloneResource(resource, blockId, copyFields, args) var data *RawData if err != nil { diff --git a/llx/runtime.go b/llx/runtime.go index b7e1b04c9f..c5538da948 100644 --- a/llx/runtime.go +++ b/llx/runtime.go @@ -9,7 +9,7 @@ type Runtime interface { AssetMRN() string Unregister(watcherUID string) error CreateResource(name string, args map[string]*Primitive) (Resource, error) - CreateResourceWithID(name string, id string, args map[string]*Primitive) (Resource, error) + CloneResource(src Resource, id string, fields []string, args map[string]*Primitive) (Resource, error) WatchAndUpdate(resource Resource, field string, watcherUID string, callback func(res interface{}, err error)) error Schema() Schema Close() diff --git a/providers/runtime.go b/providers/runtime.go index 091fd4bc31..775c282b94 100644 --- a/providers/runtime.go +++ b/providers/runtime.go @@ -260,12 +260,29 @@ func (r *Runtime) CreateResource(name string, args map[string]*llx.Primitive) (l return &llx.MockResource{Name: typ.ResourceName(), ID: string(res.Data.Value)}, nil } -func (r *Runtime) CreateResourceWithID(name string, id string, args map[string]*llx.Primitive) (llx.Resource, error) { +func (r *Runtime) CloneResource(src llx.Resource, id string, fields []string, args map[string]*llx.Primitive) (llx.Resource, error) { + name := src.MqlName() + srcID := src.MqlID() + provider, _, err := r.lookupResourceProvider(name) if err != nil { return nil, err } + for i := range fields { + field := fields[i] + data, err := provider.Instance.Plugin.GetData(&plugin.DataReq{ + Connection: provider.Connection.Id, + Resource: name, + ResourceId: srcID, + Field: field, + }) + if err != nil { + return nil, err + } + args[field] = data.Data + } + args["__id"] = llx.StringPrimitive(id) _, err = provider.Instance.Plugin.StoreData(&plugin.StoreReq{