Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ For ease of installation and operation, run Fleet Telemetry on Kubernetes or a s
"redis": { // Redis pub/sub config
"addrs": ["redis:6379"], // one or more addresses (cluster/sentinel supported)
"username": string - optional,
"password": string - optional,
"password": string - optional; overridden by the REDIS_PASSWORD environment variable when set,
"db": int - optional,
"subscriber_set_prefix": string - optional; names the per-VIN subscriber sorted set. When empty, the sorted set is not consulted,
"publish_vin_topics": bool - additionally publish each record to the VIN channel namespace_topic_{vin},
Expand Down
7 changes: 6 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,15 @@ func (r *Redis) options() (*goredis.UniversalOptions, error) {
if err != nil {
return nil, err
}
password := r.Password
if envPassword := os.Getenv("REDIS_PASSWORD"); envPassword != "" {
password = envPassword
}

options := &goredis.UniversalOptions{
Addrs: r.Addrs,
Username: r.Username,
Password: r.Password,
Password: password,
DB: r.DB,
TLSConfig: tlsConfig,
}
Expand Down
24 changes: 24 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,30 @@ var _ = Describe("Test full application config", func() {
})
})

Context("configure redis", func() {
AfterEach(func() {
_ = os.Unsetenv("REDIS_PASSWORD")
})

It("uses the password from config when REDIS_PASSWORD is unset", func() {
redis := &Redis{Addrs: []string{"redis:6379"}, Password: "config-password"}

options, err := redis.options()
Expect(err).NotTo(HaveOccurred())
Expect(options.Password).To(Equal("config-password"))
})

It("overrides the password with the REDIS_PASSWORD env variable when set", func() {
err := os.Setenv("REDIS_PASSWORD", "env-password")
Expect(err).NotTo(HaveOccurred())
redis := &Redis{Addrs: []string{"redis:6379"}, Password: "config-password"}

options, err := redis.options()
Expect(err).NotTo(HaveOccurred())
Expect(options.Password).To(Equal("env-password"))
})
})

Context("VinsToTrack", func() {

AfterEach(func() {
Expand Down
Loading