Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/component/loki/source/internal/kafkatarget/authentication.go
4096 views
1
package kafkatarget
2
3
// This code is copied from Promtail. The herokutarget package is used to
4
// configure and run the targets that can read heroku entries and forward them
5
// to other loki components.
6
7
import (
8
"crypto/sha256"
9
"crypto/sha512"
10
11
"github.com/xdg-go/scram"
12
)
13
14
// copied from https://github.com/Shopify/sarama/blob/44627b731c60bb90efe25573e7ef2b3f8df3fa23/examples/sasl_scram_client/scram_client.go
15
var (
16
SHA256 scram.HashGeneratorFcn = sha256.New
17
SHA512 scram.HashGeneratorFcn = sha512.New
18
)
19
20
// XDGSCRAMClient implements sarama.SCRAMClient
21
type XDGSCRAMClient struct {
22
*scram.Client
23
*scram.ClientConversation
24
scram.HashGeneratorFcn
25
}
26
27
func (x *XDGSCRAMClient) Begin(userName, password, authzID string) (err error) {
28
x.Client, err = x.HashGeneratorFcn.NewClient(userName, password, authzID)
29
if err != nil {
30
return err
31
}
32
x.ClientConversation = x.Client.NewConversation()
33
return nil
34
}
35
36
func (x *XDGSCRAMClient) Step(challenge string) (response string, err error) {
37
response, err = x.ClientConversation.Step(challenge)
38
return
39
}
40
41
func (x *XDGSCRAMClient) Done() bool {
42
return x.ClientConversation.Done()
43
}
44
45