7
7
"sync"
8
8
9
9
"github.com/hashicorp/errwrap"
10
+ log "github.com/hashicorp/go-hclog"
10
11
plugin "github.com/hashicorp/go-plugin"
11
12
"github.com/hashicorp/vault/sdk/helper/consts"
12
13
"github.com/hashicorp/vault/sdk/helper/pluginutil"
@@ -34,7 +35,7 @@ func (b *BackendPluginClient) Cleanup(ctx context.Context) {
34
35
// external plugins, or a concrete implementation of the backend if it is a builtin backend.
35
36
// The backend is returned as a logical.Backend interface. The isMetadataMode param determines whether
36
37
// the plugin should run in metadata mode.
37
- func NewBackend (ctx context.Context , pluginName string , pluginType consts.PluginType , sys pluginutil.LookRunnerUtil , conf * logical.BackendConfig , isMetadataMode bool , autoMTLS bool ) (logical.Backend , error ) {
38
+ func NewBackend (ctx context.Context , pluginName string , pluginType consts.PluginType , sys pluginutil.LookRunnerUtil , conf * logical.BackendConfig , isMetadataMode bool ) (logical.Backend , error ) {
38
39
// Look for plugin in the plugin catalog
39
40
pluginRunner , err := sys .LookupPlugin (ctx , pluginName , pluginType )
40
41
if err != nil {
@@ -58,16 +59,8 @@ func NewBackend(ctx context.Context, pluginName string, pluginType consts.Plugin
58
59
}
59
60
}
60
61
} else {
61
- config := pluginutil.PluginClientConfig {
62
- Name : pluginName ,
63
- PluginType : pluginType ,
64
- Logger : conf .Logger .Named (pluginName ),
65
- IsMetadataMode : isMetadataMode ,
66
- AutoMTLS : autoMTLS ,
67
- Wrapper : sys ,
68
- }
69
62
// create a backendPluginClient instance
70
- backend , err = NewPluginClient (ctx , pluginRunner , config )
63
+ backend , err = NewPluginClient (ctx , sys , pluginRunner , conf . Logger , isMetadataMode )
71
64
if err != nil {
72
65
return nil , err
73
66
}
@@ -76,49 +69,34 @@ func NewBackend(ctx context.Context, pluginName string, pluginType consts.Plugin
76
69
return backend , nil
77
70
}
78
71
79
- // pluginSet returns the go-plugin PluginSet that we can dispense. This ensures
80
- // that plugins that don't support AutoMTLS are run on the appropriate version.
81
- func pluginSet (autoMTLS , metadataMode bool ) map [int ]plugin.PluginSet {
82
- if autoMTLS {
83
- return map [int ]plugin.PluginSet {
84
- 5 : {
85
- "backend" : & GRPCBackendPlugin {
86
- MetadataMode : false ,
87
- AutoMTLSSupported : true ,
88
- },
89
- },
90
- }
91
- }
92
- return map [int ]plugin.PluginSet {
72
+ func NewPluginClient (ctx context.Context , sys pluginutil.RunnerUtil , pluginRunner * pluginutil.PluginRunner , logger log.Logger , isMetadataMode bool ) (logical.Backend , error ) {
73
+ // pluginMap is the map of plugins we can dispense.
74
+ pluginSet := map [int ]plugin.PluginSet {
93
75
// Version 3 used to supports both protocols. We want to keep it around
94
76
// since it's possible old plugins built against this version will still
95
77
// work with gRPC. There is currently no difference between version 3
96
78
// and version 4.
97
79
3 : {
98
80
"backend" : & GRPCBackendPlugin {
99
- MetadataMode : metadataMode ,
81
+ MetadataMode : isMetadataMode ,
100
82
},
101
83
},
102
84
4 : {
103
85
"backend" : & GRPCBackendPlugin {
104
- MetadataMode : metadataMode ,
86
+ MetadataMode : isMetadataMode ,
105
87
},
106
88
},
107
89
}
108
- }
109
90
110
- func NewPluginClient (ctx context.Context , pluginRunner * pluginutil.PluginRunner , config pluginutil.PluginClientConfig ) (logical.Backend , error ) {
111
- ps := pluginSet (config .AutoMTLS , config .IsMetadataMode )
112
-
113
- client , err := pluginRunner .RunConfig (ctx ,
114
- pluginutil .Runner (config .Wrapper ),
115
- pluginutil .PluginSets (ps ),
116
- pluginutil .HandshakeConfig (handshakeConfig ),
117
- pluginutil .Env (),
118
- pluginutil .Logger (config .Logger ),
119
- pluginutil .MetadataMode (config .IsMetadataMode ),
120
- pluginutil .AutoMTLS (config .AutoMTLS ),
121
- )
91
+ namedLogger := logger .Named (pluginRunner .Name )
92
+
93
+ var client * plugin.Client
94
+ var err error
95
+ if isMetadataMode {
96
+ client , err = pluginRunner .RunMetadataMode (ctx , sys , pluginSet , handshakeConfig , []string {}, namedLogger )
97
+ } else {
98
+ client , err = pluginRunner .Run (ctx , sys , pluginSet , handshakeConfig , []string {}, namedLogger )
99
+ }
122
100
if err != nil {
123
101
return nil , err
124
102
}
@@ -148,9 +126,9 @@ func NewPluginClient(ctx context.Context, pluginRunner *pluginutil.PluginRunner,
148
126
}
149
127
150
128
// Wrap the backend in a tracing middleware
151
- if config . Logger .IsTrace () {
129
+ if namedLogger .IsTrace () {
152
130
backend = & backendTracingMiddleware {
153
- logger : config . Logger .With ("transport" , transport ),
131
+ logger : namedLogger .With ("transport" , transport ),
154
132
next : backend ,
155
133
}
156
134
}
0 commit comments