@@ -4,13 +4,13 @@ import (
44 "bytes"
55 "context"
66 "encoding/binary"
7+ "errors"
78 "fmt"
89 "io"
910 "time"
1011
1112 "github.com/grepplabs/kafka-proxy/pkg/apis"
1213 "github.com/grepplabs/kafka-proxy/proxy/protocol"
13- "github.com/pkg/errors"
1414 "github.com/sirupsen/logrus"
1515)
1616
@@ -100,7 +100,7 @@ func (b *SASLPlainAuth) sendSaslAuthenticateRequest(conn DeadlineReaderWriter) e
100100 }
101101 _ , err = conn .Write (authBytes )
102102 if err != nil {
103- return errors . Wrap ( err , "Failed to write SASL auth header" )
103+ return fmt . Errorf ( "failed to write SASL auth header: %w" , err )
104104 }
105105
106106 err = conn .SetReadDeadline (time .Now ().Add (b .readTimeout ))
@@ -116,7 +116,7 @@ func (b *SASLPlainAuth) sendSaslAuthenticateRequest(conn DeadlineReaderWriter) e
116116 if err == io .EOF {
117117 return fmt .Errorf ("SASL/PLAIN auth for user %s failed" , b .username )
118118 }
119- return errors . Wrap ( err , "Failed to read response while authenticating with SASL" )
119+ return fmt . Errorf ( "failed to read response while authenticating with SASL: %w" , err )
120120 }
121121 return nil
122122}
@@ -141,7 +141,7 @@ func (b *SASLHandshake) sendAndReceiveHandshake(conn DeadlineReaderWriter) error
141141
142142 _ , err = conn .Write (bytes .Join ([][]byte {sizeBuf , reqBuf }, nil ))
143143 if err != nil {
144- return errors . Wrap ( err , "Failed to send SASL handshake" )
144+ return fmt . Errorf ( "failed to send SASL handshake: %w" , err )
145145 }
146146
147147 err = conn .SetReadDeadline (time .Now ().Add (b .readTimeout ))
@@ -153,23 +153,22 @@ func (b *SASLHandshake) sendAndReceiveHandshake(conn DeadlineReaderWriter) error
153153 header := make ([]byte , 8 ) // response header
154154 _ , err = io .ReadFull (conn , header )
155155 if err != nil {
156- return errors . Wrap ( err , "Failed to read SASL handshake header" )
156+ return fmt . Errorf ( "failed to read SASL handshake header: %w" , err )
157157 }
158158 length := binary .BigEndian .Uint32 (header [:4 ])
159159 payload := make ([]byte , length - 4 )
160160 _ , err = io .ReadFull (conn , payload )
161161 if err != nil {
162- return errors . Wrap ( err , "Failed to read SASL handshake payload" )
162+ return fmt . Errorf ( "failed to read SASL handshake payload: %w" , err )
163163 }
164164 res := & protocol.SaslHandshakeResponseV0orV1 {}
165165 err = protocol .Decode (payload , res )
166166 if err != nil {
167- return errors . Wrap ( err , "Failed to parse SASL handshake" )
167+ return fmt . Errorf ( "failed to parse SASL handshake: %w" , err )
168168 }
169- if res .Err != protocol .ErrNoError {
170- return errors . Wrap ( res . Err , "Invalid SASL Mechanism" )
169+ if ! errors . Is ( res .Err , protocol .ErrNoError ) {
170+ return fmt . Errorf ( "invalid SASL Mechanism: %w" , res . Err )
171171 }
172-
173172 logrus .Debugf ("Successful SASL handshake. Available mechanisms: %v" , res .EnabledMechanisms )
174173 return nil
175174}
@@ -231,7 +230,7 @@ func (b *SASLOAuthBearerAuth) sendSaslAuthenticateRequest(token string, conn Dea
231230
232231 _ , err = conn .Write (bytes .Join ([][]byte {sizeBuf , reqBuf }, nil ))
233232 if err != nil {
234- return errors . Wrap ( err , "Failed to send SASL auth request" )
233+ return fmt . Errorf ( "failed to send SASL auth request: %w" , err )
235234 }
236235
237236 err = conn .SetReadDeadline (time .Now ().Add (b .readTimeout ))
@@ -243,22 +242,22 @@ func (b *SASLOAuthBearerAuth) sendSaslAuthenticateRequest(token string, conn Dea
243242 header := make ([]byte , 8 ) // response header
244243 _ , err = io .ReadFull (conn , header )
245244 if err != nil {
246- return errors . Wrap ( err , "Failed to read SASL auth header" )
245+ return fmt . Errorf ( "failed to read SASL auth header: %w" , err )
247246 }
248247 length := binary .BigEndian .Uint32 (header [:4 ])
249248 payload := make ([]byte , length - 4 )
250249 _ , err = io .ReadFull (conn , payload )
251250 if err != nil {
252- return errors . Wrap ( err , "Failed to read SASL auth payload" )
251+ return fmt . Errorf ( "failed to read SASL auth payload: %w" , err )
253252 }
254253
255254 res := & protocol.SaslAuthenticateResponseV0 {}
256255 err = protocol .Decode (payload , res )
257256 if err != nil {
258- return errors . Wrap ( err , "Failed to parse SASL auth response" )
257+ return fmt . Errorf ( "failed to parse SASL auth response: %w" , err )
259258 }
260- if res .Err != protocol .ErrNoError {
261- return errors . Wrapf ( res . Err , "SASL authentication failed, error message is '%v'" , res .ErrMsg )
259+ if ! errors . Is ( res .Err , protocol .ErrNoError ) {
260+ return fmt . Errorf ( "SASL authentication failed, error message is '%v'" , res .ErrMsg )
262261 }
263262 return nil
264263}
0 commit comments