Skip to content

Commit

Permalink
Merge pull request #20 from positivelong/master
Browse files Browse the repository at this point in the history
feature: Redis supports password retrieval from files
  • Loading branch information
liuwenping authored May 19, 2023
2 parents 789ba36 + 6e82b6c commit ba612d7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions filebeat/input/redis/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var defaultConfig = config{
Network: "tcp",
MaxConn: 10,
Password: "",
PasswordFile: "",
}

type config struct {
Expand All @@ -39,4 +40,5 @@ type config struct {
Network string `config:"network"`
MaxConn int `config:"maxconn" validate:"min=1"`
Password string `config:"password"`
PasswordFile string `config:"password_file"`
}
17 changes: 17 additions & 0 deletions filebeat/input/redis/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package redis

import (
"os"
"time"

rd "github.com/garyburd/redigo/redis"
Expand Down Expand Up @@ -58,6 +59,22 @@ func NewInput(cfg *common.Config, outletFactory channel.Connector, context input
return nil, err
}

// 读取文件内容
var content = ""
if config.PasswordFile != "" {
info, err := os.ReadFile(config.PasswordFile)
if err != nil {
logp.Err("Read Password File Error: %s", err)
} else {
content = string(info)
}
}

// 将文件内容赋值给 config.Password
if content != "" {
config.Password = content
}

outlet, err := outletFactory(cfg, context.DynamicFields)
if err != nil {
return nil, err
Expand Down

0 comments on commit ba612d7

Please sign in to comment.