Skip to content

Commit

Permalink
feat: enforcing the use of auth to connect dicedb
Browse files Browse the repository at this point in the history
  • Loading branch information
vinitparekh17 committed Oct 2, 2024
1 parent 62d3613 commit 088f894
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
13 changes: 9 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@ import (

// Config holds the application configuration
type Config struct {
DiceAddr string
ServerPort string
RequestLimit int // Field for the request limit
RequestWindow int // Field for the time window in seconds
DiceAddr string // Field for the Dice address
Username string // Field for the username
Password string // Field for the password
ServerPort string // Field for the server port
RequestLimit int // Field for the request limit
RequestWindow int // Field for the time window in seconds
}

// LoadConfig loads the application configuration from environment variables or defaults
func LoadConfig() *Config {
return &Config{
// if host and port is combined then it is called
DiceAddr: getEnv("DICE_ADDR", "localhost:7379"), // Default Dice address
Username: getEnv("DICE_USERNAME", "dice"), // Default username
Password: getEnv("DICE_PASSWORD", ""), // Default password is empty
ServerPort: getEnv("SERVER_PORT", ":8080"), // Default server port
RequestLimit: getEnvInt("REQUEST_LIMIT", 1000), // Default request limit
RequestWindow: getEnvInt("REQUEST_WINDOW", 60), // Default request window in seconds
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ module server

go 1.22.5

require github.com/dicedb/go-dice v0.0.0-20240820180649-d97f15fca831

require (
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/dicedb/go-dice v0.0.0-20240820180649-d97f15fca831 // indirect
)
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/dicedb/go-dice v0.0.0-20240820180649-d97f15fca831 h1:Cqyj9WCtoobN6++bFbDSe27q94SPwJD9Z0wmu+SDRuk=
Expand Down
2 changes: 2 additions & 0 deletions internal/db/dicedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ func (db *DiceDB) CloseDiceDB() {
func InitDiceClient(configValue *config.Config) (*DiceDB, error) {
diceClient := dice.NewClient(&dice.Options{
Addr: configValue.DiceAddr,
Username: configValue.Username,
Password: configValue.Password,
DialTimeout: 10 * time.Second,
MaxRetries: 10,
})
Expand Down

0 comments on commit 088f894

Please sign in to comment.