Skip to content

Commit 8702d3f

Browse files
committed
Move plugin interface to apis package
1 parent b8fc691 commit 8702d3f

File tree

11 files changed

+39
-29
lines changed

11 files changed

+39
-29
lines changed

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@ plugin.auth-user:
9191
plugin.auth-ldap:
9292
CGO_ENABLED=0 go build -o build/auth-ldap $(BUILD_FLAGS) -ldflags "$(LDFLAGS)" cmd/plugin-auth-ldap/main.go
9393

94-
plugin.googleid-provider:
95-
CGO_ENABLED=0 go build -o build/googleid-provider $(BUILD_FLAGS) -ldflags "$(LDFLAGS)" cmd/plugin-googleid-provider/main.go
94+
plugin.google-id-provider:
95+
CGO_ENABLED=0 go build -o build/google-id-provider $(BUILD_FLAGS) -ldflags "$(LDFLAGS)" cmd/plugin-googleid-provider/main.go
96+
97+
all: build plugin.auth-user plugin.auth-ldap plugin.google-id-provider
9698

9799
clean:
98100
@rm -rf build

cmd/kafka-proxy/server.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"time"
2020

2121
"errors"
22+
"github.com/grepplabs/kafka-proxy/pkg/apis"
2223
gatewayclient "github.com/grepplabs/kafka-proxy/plugin/gateway-client/shared"
2324
localauth "github.com/grepplabs/kafka-proxy/plugin/local-auth/shared"
2425
"github.com/hashicorp/go-hclog"
@@ -144,7 +145,7 @@ func init() {
144145
func Run(_ *cobra.Command, _ []string) {
145146
logrus.Infof("Starting kafka-proxy version %s", config.Version)
146147

147-
var passwordAuthenticator localauth.PasswordAuthenticator
148+
var passwordAuthenticator apis.PasswordAuthenticator
148149
if c.Auth.Local.Enable {
149150
client := NewLocalAuthPluginClient()
150151
defer client.Kill()
@@ -158,13 +159,13 @@ func Run(_ *cobra.Command, _ []string) {
158159
logrus.Fatal(err)
159160
}
160161
var ok bool
161-
passwordAuthenticator, ok = raw.(localauth.PasswordAuthenticator)
162+
passwordAuthenticator, ok = raw.(apis.PasswordAuthenticator)
162163
if !ok {
163164
logrus.Fatal(errors.New("unsupported plugin type"))
164165
}
165166
}
166167

167-
var tokenProvider gatewayclient.TokenProvider
168+
var tokenProvider apis.TokenProvider
168169
if c.Auth.Gateway.Client.Enable {
169170
client := NewGatewayClientPluginClient()
170171
defer client.Kill()
@@ -178,7 +179,7 @@ func Run(_ *cobra.Command, _ []string) {
178179
logrus.Fatal(err)
179180
}
180181
var ok bool
181-
tokenProvider, ok = raw.(gatewayclient.TokenProvider)
182+
tokenProvider, ok = raw.(apis.TokenProvider)
182183
if !ok {
183184
logrus.Fatal(errors.New("unsupported plugin type"))
184185
}

cmd/plugin-googleid-provider/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@ func (f *TokenProvider) flagSet() *flag.FlagSet {
5151
func main() {
5252
tokenProvider := &TokenProvider{}
5353
fs := tokenProvider.flagSet()
54-
fs.Parse(os.Args[1:])
5554
fs.IntVar(&tokenProvider.timeout, "timeout", 5, "Request timeout")
5655

56+
fs.Parse(os.Args[1:])
57+
5758
plugin.Serve(&plugin.ServeConfig{
5859
HandshakeConfig: shared.Handshake,
5960
Plugins: map[string]plugin.Plugin{

plugin/gateway-client/shared/grpc.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package shared
22

33
import (
4+
"github.com/grepplabs/kafka-proxy/pkg/apis"
45
"github.com/grepplabs/kafka-proxy/plugin/gateway-client/proto"
56
"github.com/hashicorp/go-plugin"
67
"golang.org/x/net/context"
@@ -12,8 +13,8 @@ type GRPCClient struct {
1213
client proto.TokenProviderClient
1314
}
1415

15-
func (m *GRPCClient) GetToken(username, password string) (int32, string, error) {
16-
resp, err := m.client.GetToken(context.Background(), &proto.TokenRequest{})
16+
func (m *GRPCClient) GetToken(claims []string) (int32, string, error) {
17+
resp, err := m.client.GetToken(context.Background(), &proto.TokenRequest{Claims: claims})
1718
if err != nil {
1819
return 0, "", err
1920
}
@@ -23,7 +24,7 @@ func (m *GRPCClient) GetToken(username, password string) (int32, string, error)
2324
// Here is the gRPC server that GRPCClient talks to.
2425
type GRPCServer struct {
2526
broker *plugin.GRPCBroker
26-
Impl TokenProvider
27+
Impl apis.TokenProvider
2728
}
2829

2930
func (m *GRPCServer) GetToken(

plugin/gateway-client/shared/interface.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"golang.org/x/net/context"
66
"google.golang.org/grpc"
77

8+
"github.com/grepplabs/kafka-proxy/pkg/apis"
89
"github.com/grepplabs/kafka-proxy/plugin/gateway-client/proto"
910
"github.com/hashicorp/go-plugin"
1011
"net/rpc"
@@ -21,12 +22,8 @@ var PluginMap = map[string]plugin.Plugin{
2122
"tokenProvider": &TokenProviderPlugin{},
2223
}
2324

24-
type TokenProvider interface {
25-
GetToken(claims []string) (int32, string, error)
26-
}
27-
2825
type TokenProviderPlugin struct {
29-
Impl TokenProvider
26+
Impl apis.TokenProvider
3027
}
3128

3229
func (p *TokenProviderPlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error {

plugin/gateway-client/shared/rpc.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package shared
22

33
import (
4+
"github.com/grepplabs/kafka-proxy/pkg/apis"
45
"net/rpc"
56
)
67

@@ -15,7 +16,7 @@ func (m *RPCClient) GetToken(claims []string) (int32, string, error) {
1516
}
1617

1718
type RPCServer struct {
18-
Impl TokenProvider
19+
Impl apis.TokenProvider
1920
}
2021

2122
func (m *RPCServer) GetToken(args map[string]interface{}, resp *map[string]interface{}) error {

plugin/local-auth/shared/grpc.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package shared
22

33
import (
4+
"github.com/grepplabs/kafka-proxy/pkg/apis"
45
"github.com/grepplabs/kafka-proxy/plugin/local-auth/proto"
56
"github.com/hashicorp/go-plugin"
67
"golang.org/x/net/context"
@@ -26,7 +27,7 @@ func (m *GRPCClient) Authenticate(username, password string) (bool, int32, error
2627
// Here is the gRPC server that GRPCClient talks to.
2728
type GRPCServer struct {
2829
broker *plugin.GRPCBroker
29-
Impl PasswordAuthenticator
30+
Impl apis.PasswordAuthenticator
3031
}
3132

3233
func (m *GRPCServer) Authenticate(

plugin/local-auth/shared/interface.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"golang.org/x/net/context"
66
"google.golang.org/grpc"
77

8+
"github.com/grepplabs/kafka-proxy/pkg/apis"
89
"github.com/grepplabs/kafka-proxy/plugin/local-auth/proto"
910
"github.com/hashicorp/go-plugin"
1011
"net/rpc"
@@ -21,12 +22,8 @@ var PluginMap = map[string]plugin.Plugin{
2122
"passwordAuthenticator": &PasswordAuthenticatorPlugin{},
2223
}
2324

24-
type PasswordAuthenticator interface {
25-
Authenticate(username, password string) (bool, int32, error)
26-
}
27-
2825
type PasswordAuthenticatorPlugin struct {
29-
Impl PasswordAuthenticator
26+
Impl apis.PasswordAuthenticator
3027
}
3128

3229
func (p *PasswordAuthenticatorPlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error {

plugin/local-auth/shared/rpc.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package shared
22

33
import (
4+
"github.com/grepplabs/kafka-proxy/pkg/apis"
45
"net/rpc"
56
)
67

@@ -16,7 +17,7 @@ func (m *RPCClient) Authenticate(username, password string) (bool, int32, error)
1617
}
1718

1819
type RPCServer struct {
19-
Impl PasswordAuthenticator
20+
Impl apis.PasswordAuthenticator
2021
}
2122

2223
func (m *RPCServer) Authenticate(args map[string]interface{}, resp *map[string]interface{}) error {

proxy/client.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ func NewClient(conns *ConnSet, c *config.Config, netAddressMappingFunc config.Ne
5656
forbiddenApiKeys[int16(apiKey)] = struct{}{}
5757
}
5858
}
59+
if c.Auth.Local.Enable && passwordAuthenticator == nil {
60+
return nil, errors.New("Auth.Local.Enable is enabled but passwordAuthenticator is nil")
61+
}
62+
63+
if c.Auth.Gateway.Client.Enable && tokenProvider == nil {
64+
return nil, errors.New("Auth.Gateway.Client.Enable is enabled but tokenProvider is nil")
65+
}
5966

6067
return &Client{conns: conns, config: c, tlsConfig: tlsConfig, tcpConnOptions: tcpConnOptions, stopRun: make(chan struct{}, 1),
6168
saslPlainAuth: &SASLPlainAuth{
@@ -66,10 +73,11 @@ func NewClient(conns *ConnSet, c *config.Config, netAddressMappingFunc config.Ne
6673
password: c.Kafka.SASL.Password,
6774
},
6875
authClient: &AuthClient{
69-
enabled: c.Auth.Gateway.Client.Enable,
70-
magic: c.Auth.Gateway.Client.Magic,
71-
method: c.Auth.Gateway.Client.Method,
72-
timeout: c.Auth.Gateway.Client.Timeout,
76+
enabled: c.Auth.Gateway.Client.Enable,
77+
magic: c.Auth.Gateway.Client.Magic,
78+
method: c.Auth.Gateway.Client.Method,
79+
timeout: c.Auth.Gateway.Client.Timeout,
80+
tokenProvider: tokenProvider,
7381
},
7482
processorConfig: ProcessorConfig{
7583
MaxOpenRequests: c.Kafka.MaxOpenRequests,

0 commit comments

Comments
 (0)