go.mondoo.com/cnquery@v0.0.0-20231005093811-59568235f6ea/providers-sdk/v1/plugin/plugin.go (about) 1 // Copyright (c) Mondoo, Inc. 2 // SPDX-License-Identifier: BUSL-1.1 3 4 package plugin 5 6 import llx "go.mondoo.com/cnquery/llx" 7 8 //go:generate protoc --proto_path=../../../:. --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative plugin.proto 9 10 // ParseArgsFun is a function to take a list of incoming arguments and parse 11 // them. This is used for 3 possible use-cases: 12 // 13 // 1. Arguments get transformed. 14 // eg: sshd.config(path: ..) => turn the path into the file field 15 // here we return the new set of arguments, ie: 16 // in: {"path": ..} 17 // out: {"file": file(..)} 18 // 19 // 2. Arguments lead to a resource lookup 20 // eg: user(name: "bob") => look up the user with this name. 21 // here we use the argument to look up the resource ie: 22 // in: {"name": "bob"} ==> call users.list and find the user 23 // out: the user(..) object that was previously initialized by users.list 24 // 25 // 3. Arguments lead to additional processing and pre-caching. 26 // eg: service.field(id: ..) => needs to call the API to get the object 27 // since we don't want to do this twice, we initialize the object 28 // right during argument processing and return it. 29 // in: {"id": ..} ==> calls I/O, then creates the new object 30 // out: service.field which is fully initialized 31 // NOTE: please remember to initialize all arguments that are provided 32 // by users, since you have to return a complete object 33 type ParseArgsFun func(runtime *Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, Resource, error) 34 35 // CreateResource is an auto-generated method to create a resource. 36 // It takes a list of arguments from which the resource is initialized. 37 // (Note: if necessary, parse arguments beforehand). 38 type CreateResource func(runtime *Runtime, args map[string]*llx.RawData) (Resource, error) 39 40 // ResourceFactory is generated for every resource and helps to initialize it 41 // and parse its arguments. This is focused on everything that is done 42 // within a plugin, not beyond (recording, upstream etc). 43 type ResourceFactory struct { 44 Init ParseArgsFun 45 Create CreateResource 46 }