@@ -25,6 +25,11 @@ import (
2525 localauth "github.com/grepplabs/kafka-proxy/plugin/local-auth/shared"
2626 "github.com/hashicorp/go-hclog"
2727 "github.com/hashicorp/go-plugin"
28+
29+ "github.com/grepplabs/kafka-proxy/pkg/registry"
30+ // built-in plugins
31+ _ "github.com/grepplabs/kafka-proxy/pkg/libs/googleid-info"
32+ _ "github.com/grepplabs/kafka-proxy/pkg/libs/googleid-provider"
2833)
2934
3035var (
@@ -148,61 +153,89 @@ func Run(_ *cobra.Command, _ []string) {
148153
149154 var passwordAuthenticator apis.PasswordAuthenticator
150155 if c .Auth .Local .Enable {
151- client := NewLocalAuthPluginClient ()
152- defer client .Kill ()
156+ var err error
157+ factory , ok := registry .GetComponent (new (apis.PasswordAuthenticatorFactory ), c .Auth .Local .Command ).(apis.PasswordAuthenticatorFactory )
158+ if ok {
159+ logrus .Infof ("Using built-in PasswordAuthenticator" )
160+ passwordAuthenticator , err = factory .New (c .Auth .Local .Parameters )
161+ if err != nil {
162+ logrus .Fatal (err )
163+ }
164+ } else {
165+ client := NewPluginClient (localauth .Handshake , localauth .PluginMap , c .Auth .Local .LogLevel , c .Auth .Local .Command , c .Auth .Local .Parameters )
166+ defer client .Kill ()
153167
154- rpcClient , err := client .Client ()
155- if err != nil {
156- logrus .Fatal (err )
157- }
158- raw , err := rpcClient .Dispense ("passwordAuthenticator" )
159- if err != nil {
160- logrus .Fatal (err )
161- }
162- var ok bool
163- passwordAuthenticator , ok = raw .(apis. PasswordAuthenticator )
164- if ! ok {
165- logrus . Fatal ( errors . New ( "unsupported PasswordAuthenticator plugin type" ))
168+ rpcClient , err := client .Client ()
169+ if err != nil {
170+ logrus .Fatal (err )
171+ }
172+ raw , err := rpcClient .Dispense ("passwordAuthenticator" )
173+ if err != nil {
174+ logrus .Fatal (err )
175+ }
176+ passwordAuthenticator , ok = raw .(apis. PasswordAuthenticator )
177+ if ! ok {
178+ logrus . Fatal ( errors . New ( "unsupported PasswordAuthenticator plugin type" ))
179+ }
166180 }
167181 }
168182
169183 var tokenProvider apis.TokenProvider
170184 if c .Auth .Gateway .Client .Enable {
171- client := NewGatewayClientPluginClient ()
172- defer client .Kill ()
185+ var err error
186+ factory , ok := registry .GetComponent (new (apis.TokenProviderFactory ), c .Auth .Gateway .Client .Command ).(apis.TokenProviderFactory )
187+ if ok {
188+ logrus .Infof ("Using built-in TokenProvider" )
189+ tokenProvider , err = factory .New (c .Auth .Gateway .Client .Parameters )
190+ if err != nil {
191+ logrus .Fatal (err )
192+ }
193+ } else {
194+ client := NewPluginClient (gatewayclient .Handshake , gatewayclient .PluginMap , c .Auth .Gateway .Client .LogLevel , c .Auth .Gateway .Client .Command , c .Auth .Gateway .Client .Parameters )
195+ defer client .Kill ()
173196
174- rpcClient , err := client .Client ()
175- if err != nil {
176- logrus .Fatal (err )
177- }
178- raw , err := rpcClient .Dispense ("tokenProvider" )
179- if err != nil {
180- logrus .Fatal (err )
181- }
182- var ok bool
183- tokenProvider , ok = raw .(apis. TokenProvider )
184- if ! ok {
185- logrus . Fatal ( errors . New ( "unsupported TokenProvider plugin type" ))
197+ rpcClient , err := client .Client ()
198+ if err != nil {
199+ logrus .Fatal (err )
200+ }
201+ raw , err := rpcClient .Dispense ("tokenProvider" )
202+ if err != nil {
203+ logrus .Fatal (err )
204+ }
205+ tokenProvider , ok = raw .(apis. TokenProvider )
206+ if ! ok {
207+ logrus . Fatal ( errors . New ( "unsupported TokenProvider plugin type" ))
208+ }
186209 }
187210 }
188211
189212 var tokenInfo apis.TokenInfo
190213 if c .Auth .Gateway .Server .Enable {
191- client := NewGatewayServerPluginClient ()
192- defer client .Kill ()
214+ var err error
215+ factory , ok := registry .GetComponent (new (apis.TokenInfoFactory ), c .Auth .Gateway .Server .Command ).(apis.TokenInfoFactory )
216+ if ok {
217+ logrus .Infof ("Using built-in TokenInfo" )
218+
219+ tokenInfo , err = factory .New (c .Auth .Gateway .Server .Parameters )
220+ if err != nil {
221+ logrus .Fatal (err )
222+ }
223+ } else {
224+ client := NewPluginClient (gatewayserver .Handshake , gatewayserver .PluginMap , c .Auth .Gateway .Server .LogLevel , c .Auth .Gateway .Server .Command , c .Auth .Gateway .Server .Parameters )
225+ defer client .Kill ()
193226
194- rpcClient , err := client .Client ()
195- if err != nil {
196- logrus .Fatal (err )
197- }
198- raw , err := rpcClient .Dispense ("tokenInfo" )
199- if err != nil {
200- logrus .Fatal (err )
201- }
202- var ok bool
203- tokenInfo , ok = raw .(apis. TokenInfo )
204- if ! ok {
205- logrus . Fatal ( errors . New ( "unsupported TokenInfo plugin type" ))
227+ rpcClient , err := client .Client ()
228+ if err != nil {
229+ logrus .Fatal (err )
230+ }
231+ raw , err := rpcClient .Dispense ("tokenInfo" )
232+ if err != nil {
233+ logrus .Fatal (err )
234+ }
235+ tokenInfo , ok = raw .(apis. TokenInfo )
236+ if ! ok {
237+ logrus . Fatal ( errors . New ( "unsupported TokenInfo plugin type" ))
238+ }
206239 }
207240 }
208241
@@ -318,16 +351,6 @@ func SetLogger() {
318351 logrus .SetLevel (level )
319352}
320353
321- func NewGatewayClientPluginClient () * plugin.Client {
322- return NewPluginClient (gatewayclient .Handshake , gatewayclient .PluginMap , c .Auth .Gateway .Client .LogLevel , c .Auth .Gateway .Client .Command , c .Auth .Gateway .Client .Parameters )
323- }
324- func NewGatewayServerPluginClient () * plugin.Client {
325- return NewPluginClient (gatewayserver .Handshake , gatewayserver .PluginMap , c .Auth .Gateway .Server .LogLevel , c .Auth .Gateway .Server .Command , c .Auth .Gateway .Server .Parameters )
326- }
327- func NewLocalAuthPluginClient () * plugin.Client {
328- return NewPluginClient (localauth .Handshake , localauth .PluginMap , c .Auth .Local .LogLevel , c .Auth .Local .Command , c .Auth .Local .Parameters )
329- }
330-
331354func NewPluginClient (handshakeConfig plugin.HandshakeConfig , plugins map [string ]plugin.Plugin , logLevel string , command string , params []string ) * plugin.Client {
332355 jsonFormat := false
333356 if c .Log .Format == "json" {
0 commit comments