Skip to content

Commit

Permalink
Reduce duplicate code.
Browse files Browse the repository at this point in the history
  • Loading branch information
mihkelparna1 committed Feb 13, 2024
1 parent a0c712d commit 947ccfc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 30 deletions.
27 changes: 11 additions & 16 deletions cmd/backfill-redis/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,26 +210,21 @@ func main() {

func redisClient() *redis.Client {

// #nosec G402
tlsConfig := &tls.Config{
InsecureSkipVerify: *insecureSkipVerify,
}

if *enableTLS {
return redis.NewClient(&redis.Options{
Addr: fmt.Sprintf("%s:%s", *redisHostname, *redisPort),
Password: *redisPassword,
Network: "tcp",
TLSConfig: tlsConfig,
DB: 0, // default DB
})
}
return redis.NewClient(&redis.Options{
opts := &redis.Options{
Addr: fmt.Sprintf("%s:%s", *redisHostname, *redisPort),
Password: *redisPassword,
Network: "tcp",
DB: 0, // default DB
})
}

// #nosec G402
if *enableTLS {
opts.TLSConfig = &tls.Config{
InsecureSkipVerify: *insecureSkipVerify,
}
}

return redis.NewClient(opts)
}

// unmarshalEntryImpl decodes the base64-encoded entry to a specific entry type (types.EntryImpl).
Expand Down
26 changes: 12 additions & 14 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,24 +188,22 @@ func ConfigureAPI(treeID uint) {
}

func NewRedisClient() *redis.Client {
if viper.GetBool("redis_server.enable-tls") {
return redis.NewClient(&redis.Options{
Addr: fmt.Sprintf("%v:%v", viper.GetString("redis_server.address"), viper.GetUint64("redis_server.port")),
Password: viper.GetString("redis_server.password"),
Network: "tcp",
TLSConfig: &tls.Config{
// #nosec G402
InsecureSkipVerify: viper.GetBool("redis_server.insecure-skip-verify"),
},
DB: 0, // default DB
})
}
return redis.NewClient(&redis.Options{

opts := &redis.Options{
Addr: fmt.Sprintf("%v:%v", viper.GetString("redis_server.address"), viper.GetUint64("redis_server.port")),
Password: viper.GetString("redis_server.password"),
Network: "tcp",
DB: 0, // default DB
})
}

// #nosec G402
if viper.GetBool("redis_server.enable-tls") {
opts.TLSConfig = &tls.Config{
InsecureSkipVerify: viper.GetBool("redis_server.insecure-skip-verify"),
}
}

return redis.NewClient(opts)
}

func StopAPI() {
Expand Down

0 comments on commit 947ccfc

Please sign in to comment.