Skip to content

Commit

Permalink
chore: support reading db config from env (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
forcodedancing authored Feb 26, 2024
1 parent 6c96cc3 commit c6ca66e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ func NewApp(cfg *config.Config) *App {
if password == "" {
password = getDBPass(&cfg.DBConfig)
}
if username == "" || password == "" { // read password from ENV
username, password = config.GetDBUsernamePasswordFromEnv()
}

dbPath := fmt.Sprintf("%s:%s@%s", username, password, cfg.DBConfig.DBPath)

Expand Down
7 changes: 7 additions & 0 deletions config/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"encoding/base64"
"fmt"
"os"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
Expand Down Expand Up @@ -44,3 +45,9 @@ func GetSecret(secretName, region string) (string, error) {
return decodedBinarySecret, nil
}
}

func GetDBUsernamePasswordFromEnv() (string, string) {
username := os.Getenv("DB_USERNAME")
password := os.Getenv("DB_PASSWORD")
return username, password
}

0 comments on commit c6ca66e

Please sign in to comment.