Skip to content

Commit

Permalink
add support password for scout redis config (#15)
Browse files Browse the repository at this point in the history
* add support password for scout redis
  • Loading branch information
dshvedchenko authored Sep 8, 2022
1 parent 44faf16 commit 9ea7f0a
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ USAGE:
scout [global options] command [command options] [arguments...]
VERSION:
v1.5.0
v1.6.0
COMMANDS:
help, h Shows a list of commands or help for one command
Expand All @@ -43,6 +43,7 @@ redis:
host: "localhost:9000"
namespace: "test"
queue: "background"
password: "someoptionalpassword" # optional key
aws:
access_key: "super"
secret_key: "secret"
Expand Down
1 change: 1 addition & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type RedisConfig struct {
Host string `yaml:"host"`
Namespace string `yaml:"namespace"`
Queue string `yaml:"queue"`
Password string `yaml:"password"`
}

// AWSConfig is a nested config that contains the necessary parameters to
Expand Down
17 changes: 17 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func (c *ConfigTestSuite) TestConfig_Valid() {
// More to convince myself that the yaml package works than anything
c.assert.Equal(config.Redis.Host, "localhost:9000")
c.assert.Equal(config.Redis.Queue, "background")
c.assert.Equal(config.Redis.Password, "")
c.assert.Equal(config.AWS.Region, "us_best")
c.assert.Equal(config.Queue.Name, "myapp_queue")
c.assert.Equal(config.Queue.Topics["foo_topic"], "FooWorker")
Expand All @@ -85,3 +86,19 @@ func (c *ConfigTestSuite) TestConfig_Sparse() {
c.assert.Equal(config.AWS.Region, "us_best")
c.assert.Equal(len(config.Queue.Topics), 0)
}

var redisAuthConfig = `
redis:
host: localhost:9000
password: jsdf3-402341234
`

// It's ok for stuff to be missing, we'll check that elsewhere
func (c *ConfigTestSuite) TestConfig_RedisPass() {
c.WriteTemp(redisAuthConfig)
config, err := ReadConfig(c.tempfile.Name())
c.assert.NoError(err)

c.assert.Equal(config.Redis.Password, "jsdf3-402341234")
c.assert.Equal(config.Redis.Host, "localhost:9000")
}
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func init() {
Poll SQS queues specified in a config and enqueue Sidekiq jobs with the queue items.
It gracefully stops when sent SIGTERM.`

app.Version = "v1.5.0"
app.Version = "v1.6.0"

app.Flags = []cli.Flag{
cli.StringFlag{
Expand Down
10 changes: 8 additions & 2 deletions worker_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,19 @@ func NewRedisWorkerClient(redis RedisConfig) (WorkerClient, error) {
return nil, errors.New("Sidekiq queue required")
}

workers.Configure(map[string]string{
workerConfig := map[string]string{
"server": redis.Host,
"database": "0",
"pool": "20",
"process": "1",
"namespace": redis.Namespace,
})
}

if redis.Password != "" {
workerConfig["password"] = redis.Password
}

workers.Configure(workerConfig)

return &redisWorkerClient{queue: redis.Queue}, nil
}
Expand Down
13 changes: 13 additions & 0 deletions worker_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var config = RedisConfig{
Host: "localhost:6379",
Namespace: "integration",
Queue: "testq",
Password: "",
}

func TestWorker_Init(t *testing.T) {
Expand Down Expand Up @@ -53,6 +54,18 @@ func TestWorker_Init(t *testing.T) {
},
)
require.NoError(t, err)

// use auth, this doesn't error
_, err = NewRedisWorkerClient(
RedisConfig{
Host: "localhost:6379",
Namespace: "",
Queue: "testq",
Password: "1234",
},
)
require.NoError(t, err)

}

func TestWorker_Push(t *testing.T) {
Expand Down

0 comments on commit 9ea7f0a

Please sign in to comment.