File: plain.go

package info (click to toggle)
golang-github-segmentio-kafka-go 0.4.49%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,292 kB
  • sloc: sh: 17; makefile: 10
file content (30 lines) | stat: -rw-r--r-- 727 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package plain

import (
	"context"
	"fmt"

	"github.com/segmentio/kafka-go/sasl"
)

// Mechanism implements the PLAIN mechanism and passes the credentials in clear
// text.
type Mechanism struct {
	Username string
	Password string
}

func (Mechanism) Name() string {
	return "PLAIN"
}

func (m Mechanism) Start(ctx context.Context) (sasl.StateMachine, []byte, error) {
	// Mechanism is stateless, so it can also implement sasl.Session
	return m, []byte(fmt.Sprintf("\x00%s\x00%s", m.Username, m.Password)), nil
}

func (m Mechanism) Next(ctx context.Context, challenge []byte) (bool, []byte, error) {
	// kafka will return error if it rejected the credentials, so we'd only
	// arrive here on success.
	return true, nil, nil
}