saslHandshake sends the SASL handshake message. This will determine whether the Mechanism is supported by the cluster. If it's not, this function will error out with UnsupportedSASLMechanism. If the mechanism is unsupported, the handshake request will reply with the list of the cluster's configur
(mechanism string)
| 1572 | // |
| 1573 | // See http://kafka.apache.org/protocol.html#The_Messages_SaslHandshake |
| 1574 | func (c *Conn) saslHandshake(mechanism string) error { |
| 1575 | // The wire format for V0 and V1 is identical, but the version |
| 1576 | // number will affect how the SASL authentication |
| 1577 | // challenge/responses are sent |
| 1578 | var resp saslHandshakeResponseV0 |
| 1579 | |
| 1580 | version, err := c.negotiateVersion(saslHandshake, v0, v1) |
| 1581 | if err != nil { |
| 1582 | return err |
| 1583 | } |
| 1584 | |
| 1585 | err = c.writeOperation( |
| 1586 | func(deadline time.Time, id int32) error { |
| 1587 | return c.writeRequest(saslHandshake, version, id, &saslHandshakeRequestV0{Mechanism: mechanism}) |
| 1588 | }, |
| 1589 | func(deadline time.Time, size int) error { |
| 1590 | return expectZeroSize(func() (int, error) { |
| 1591 | return (&resp).readFrom(&c.rbuf, size) |
| 1592 | }()) |
| 1593 | }, |
| 1594 | ) |
| 1595 | if err == nil && resp.ErrorCode != 0 { |
| 1596 | err = Error(resp.ErrorCode) |
| 1597 | } |
| 1598 | return err |
| 1599 | } |
| 1600 | |
| 1601 | // saslAuthenticate sends the SASL authenticate message. This function must |
| 1602 | // be immediately preceded by a successful saslHandshake. |