-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NETOBSERV-974 Add SASL support (#112)
* Add SASL support * Address feedback, split buildFlowExporter for linter
- Loading branch information
Showing
33 changed files
with
5,074 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package agent | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/segmentio/kafka-go/sasl" | ||
"github.com/segmentio/kafka-go/sasl/plain" | ||
"github.com/segmentio/kafka-go/sasl/scram" | ||
) | ||
|
||
func buildSASLConfig(cfg *Config) (sasl.Mechanism, error) { | ||
// Read client ID | ||
id, err := os.ReadFile(cfg.KafkaSASLClientIDPath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
strID := strings.TrimSpace(string(id)) | ||
// Read password | ||
pwd, err := os.ReadFile(cfg.KafkaSASLClientSecretPath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
strPwd := strings.TrimSpace(string(pwd)) | ||
var mechanism sasl.Mechanism | ||
switch cfg.KafkaSASLType { | ||
case "plain": | ||
mechanism = plain.Mechanism{Username: strID, Password: strPwd} | ||
case "scramSHA512": | ||
mechanism, err = scram.Mechanism(scram.SHA512, strID, strPwd) | ||
default: | ||
err = fmt.Errorf("unknown SASL type: %s", cfg.KafkaSASLType) | ||
} | ||
if err != nil { | ||
return nil, err | ||
} | ||
return mechanism, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Empty file.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.