saslAuthenticate sends the SASL authenticate message. This function must be immediately preceded by a successful saslHandshake. See http://kafka.apache.org/protocol.html#The_Messages_SaslAuthenticate
(data []byte)
| 1603 | // |
| 1604 | // See http://kafka.apache.org/protocol.html#The_Messages_SaslAuthenticate |
| 1605 | func (c *Conn) saslAuthenticate(data []byte) ([]byte, error) { |
| 1606 | // if we sent a v1 handshake, then we must encapsulate the authentication |
| 1607 | // request in a saslAuthenticateRequest. otherwise, we read and write raw |
| 1608 | // bytes. |
| 1609 | version, err := c.negotiateVersion(saslHandshake, v0, v1) |
| 1610 | if err != nil { |
| 1611 | return nil, err |
| 1612 | } |
| 1613 | if version == v1 { |
| 1614 | var request = saslAuthenticateRequestV0{Data: data} |
| 1615 | var response saslAuthenticateResponseV0 |
| 1616 | |
| 1617 | err := c.writeOperation( |
| 1618 | func(deadline time.Time, id int32) error { |
| 1619 | return c.writeRequest(saslAuthenticate, v0, id, request) |
| 1620 | }, |
| 1621 | func(deadline time.Time, size int) error { |
| 1622 | return expectZeroSize(func() (remain int, err error) { |
| 1623 | return (&response).readFrom(&c.rbuf, size) |
| 1624 | }()) |
| 1625 | }, |
| 1626 | ) |
| 1627 | if err == nil && response.ErrorCode != 0 { |
| 1628 | err = Error(response.ErrorCode) |
| 1629 | } |
| 1630 | return response.Data, err |
| 1631 | } |
| 1632 | |
| 1633 | // fall back to opaque bytes on the wire. the broker is expecting these if |
| 1634 | // it just processed a v0 sasl handshake. |
| 1635 | c.wb.writeInt32(int32(len(data))) |
| 1636 | if _, err := c.wb.Write(data); err != nil { |
| 1637 | return nil, err |
| 1638 | } |
| 1639 | if err := c.wb.Flush(); err != nil { |
| 1640 | return nil, err |
| 1641 | } |
| 1642 | |
| 1643 | var respLen int32 |
| 1644 | if _, err := readInt32(&c.rbuf, 4, &respLen); err != nil { |
| 1645 | return nil, err |
| 1646 | } |
| 1647 | |
| 1648 | resp, _, err := readNewBytes(&c.rbuf, int(respLen), int(respLen)) |
| 1649 | return resp, err |
| 1650 | } |
no test coverage detected