Skip to content

Commit 983014e

Browse files
committed
support v1 saslhandshake with v0 saslauthenticate
1 parent fab6980 commit 983014e

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

protocol/conn.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ type RawExchanger interface {
8484
RawExchange(rw io.ReadWriter) (Message, error)
8585
}
8686

87+
type DependentMessage interface {
88+
DependsOnVersion() ApiKey
89+
}
90+
8791
func (c *Conn) RoundTrip(msg Message) (Message, error) {
8892
correlationID := atomic.AddInt32(&c.idgen, +1)
8993
versions, _ := c.versions.Load().(map[ApiKey]int16)
@@ -93,7 +97,14 @@ func (c *Conn) RoundTrip(msg Message) (Message, error) {
9397
p.Prepare(apiVersion)
9498
}
9599

96-
if raw, ok := msg.(RawExchanger); ok && raw.Required(int(apiVersion)) {
100+
dp, isDependent := msg.(DependentMessage)
101+
102+
requiredVersion := apiVersion
103+
if isDependent {
104+
requiredVersion = versions[dp.DependsOnVersion()]
105+
}
106+
107+
if raw, ok := msg.(RawExchanger); ok && raw.Required(int(requiredVersion)) {
97108
return raw.RawExchange(c)
98109
}
99110

protocol/saslauthenticate/saslauthenticate.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ type Request struct {
1515
AuthBytes []byte `kafka:"min=v0,max=v1"`
1616
}
1717

18+
func (*Request) DependsOnVersion() protocol.ApiKey {
19+
return protocol.SaslHandshake
20+
}
21+
1822
func (r *Request) RawExchange(rw io.ReadWriter) (protocol.Message, error) {
1923
if err := r.writeTo(rw); err != nil {
2024
return nil, err
@@ -63,4 +67,7 @@ type Response struct {
6367

6468
func (r *Response) ApiKey() protocol.ApiKey { return protocol.SaslAuthenticate }
6569

66-
var _ protocol.RawExchanger = (*Request)(nil)
70+
var (
71+
_ protocol.RawExchanger = (*Request)(nil)
72+
_ protocol.DependentMessage = (*Request)(nil)
73+
)

0 commit comments

Comments
 (0)