scram_client.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package kafka // import "github.com/open-telemetry/opentelemetry-collector-contrib/internal/kafka"
  4. import (
  5. "github.com/IBM/sarama"
  6. "github.com/xdg-go/scram"
  7. )
  8. var _ sarama.SCRAMClient = (*XDGSCRAMClient)(nil)
  9. // XDGSCRAMClient uses xdg-go scram to authentication conversation
  10. type XDGSCRAMClient struct {
  11. *scram.Client
  12. *scram.ClientConversation
  13. scram.HashGeneratorFcn
  14. }
  15. // Begin starts the XDGSCRAMClient conversation.
  16. func (x *XDGSCRAMClient) Begin(userName, password, authzID string) (err error) {
  17. x.Client, err = x.HashGeneratorFcn.NewClient(userName, password, authzID)
  18. if err != nil {
  19. return err
  20. }
  21. x.ClientConversation = x.Client.NewConversation()
  22. return nil
  23. }
  24. // Step takes a string provided from a server (or just an empty string for the
  25. // very first conversation step) and attempts to move the authentication
  26. // conversation forward. It returns a string to be sent to the server or an
  27. // error if the server message is invalid. Calling Step after a conversation
  28. // completes is also an error.
  29. func (x *XDGSCRAMClient) Step(challenge string) (response string, err error) {
  30. return x.ClientConversation.Step(challenge)
  31. }
  32. // Done returns true if the conversation is completed or has errored.
  33. func (x *XDGSCRAMClient) Done() bool {
  34. return x.ClientConversation.Done()
  35. }