go.mondoo.com/cnquery@v0.0.0-20231005093811-59568235f6ea/providers-sdk/v1/plugin/start.go (about) 1 // Copyright (c) Mondoo, Inc. 2 // SPDX-License-Identifier: BUSL-1.1 3 4 package plugin 5 6 import ( 7 "io" 8 9 "github.com/hashicorp/go-hclog" 10 "github.com/hashicorp/go-plugin" 11 "github.com/rs/zerolog" 12 "go.mondoo.com/cnquery/logger" 13 ) 14 15 type Provider struct { 16 Name string 17 ID string 18 Version string 19 ConnectionTypes []string 20 Connectors []Connector 21 } 22 23 type Connector struct { 24 Name string 25 Use string `json:",omitempty"` 26 Short string `json:",omitempty"` 27 Long string `json:",omitempty"` 28 MinArgs uint `json:",omitempty"` 29 MaxArgs uint `json:",omitempty"` 30 Flags []Flag `json:",omitempty"` 31 Aliases []string `json:",omitempty"` 32 Discovery []string `json:",omitempty"` 33 } 34 35 func Start(args []string, impl ProviderPlugin) { 36 logger.CliCompactLogger(logger.LogOutputWriter) 37 zerolog.SetGlobalLevel(zerolog.WarnLevel) 38 39 // disable the plugin's logs 40 pluginLogger := hclog.New(&hclog.LoggerOptions{ 41 Name: "cnquery-plugin", 42 // Level: hclog.LevelFromString("DEBUG"), 43 Level: hclog.Info, 44 Output: io.Discard, 45 }) 46 47 plugin.Serve(&plugin.ServeConfig{ 48 HandshakeConfig: Handshake, 49 Plugins: map[string]plugin.Plugin{ 50 "provider": &ProviderPluginImpl{Impl: impl}, 51 }, 52 Logger: pluginLogger, 53 54 // A non-nil value here enables gRPC serving for this plugin... 55 GRPCServer: plugin.DefaultGRPCServer, 56 }) 57 }