|
3 | 3 | package plugin |
4 | 4 |
|
5 | 5 | import ( |
| 6 | + "crypto/sha256" |
6 | 7 | "fmt" |
7 | 8 | "os/exec" |
| 9 | + "path/filepath" |
8 | 10 | "strings" |
9 | 11 |
|
10 | 12 | "github.com/hashicorp/go-plugin" |
@@ -42,15 +44,31 @@ func createPluginContext( |
42 | 44 | path string, |
43 | 45 | logger *zap.SugaredLogger, |
44 | 46 | ) (*PluginContext, error) { |
45 | | - client := plugin.NewClient( |
46 | | - &plugin.ClientConfig{ |
47 | | - HandshakeConfig: handshakeConfig, |
48 | | - Plugins: loader.pluginMap, |
49 | | - Cmd: exec.Command(path), |
50 | | - Logger: log.NewInternalLogger(logger), |
51 | | - AllowedProtocols: []plugin.Protocol{plugin.ProtocolGRPC}, |
52 | | - }, |
53 | | - ) |
| 47 | + cfg := &plugin.ClientConfig{ |
| 48 | + HandshakeConfig: handshakeConfig, |
| 49 | + Plugins: loader.pluginMap, |
| 50 | + Cmd: exec.Command(path), |
| 51 | + Logger: log.NewInternalLogger(logger), |
| 52 | + AllowedProtocols: []plugin.Protocol{plugin.ProtocolGRPC}, |
| 53 | + } |
| 54 | + |
| 55 | + if len(loader.pluginChecksum) > 0 { |
| 56 | + basename := filepath.Base(path) |
| 57 | + pluginName := strings.TrimSuffix(basename, filepath.Ext(basename)) |
| 58 | + |
| 59 | + checksum, ok := loader.pluginChecksum[pluginName] |
| 60 | + if !ok { |
| 61 | + return nil, fmt.Errorf("the checksum for plugin %s is missing", pluginName) |
| 62 | + } |
| 63 | + |
| 64 | + secureConfig := &plugin.SecureConfig{ |
| 65 | + Checksum:[]byte(checksum), |
| 66 | + Hash: sha256.New(), |
| 67 | + } |
| 68 | + cfg.SecureConfig = secureConfig |
| 69 | + } |
| 70 | + |
| 71 | + client := plugin.NewClient(cfg) |
54 | 72 |
|
55 | 73 | rpcClient, err := client.Client() |
56 | 74 | if err != nil { |
|
0 commit comments