Skip to content

Commit

Permalink
feat: Ability to turn off sslmode (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
k1nho authored Oct 9, 2023
1 parent 682eb5c commit b026289
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: all lint test run local build setup-test-env teardown-test-env
.PHONY: all lint test run dev local build setup-test-env teardown-test-env

ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))

Expand All @@ -19,6 +19,9 @@ test:
run:
go run main.go

dev:
go run main.go -ssl-disable

local:
go build -o build/pizza-oven main.go

Expand Down
13 changes: 11 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ func main() {
var err error

// Initialize & parse flags
var configPath string
var (
configPath string
sslmode = "require"
)
flag.StringVar(&configPath, "config", "", "path to .yaml file config")
debugMode := flag.Bool("debug", false, "run in debug mode")
disableSSL := flag.Bool("ssl-disable", false, "set 'disable' ssl mode")
flag.Parse()

if *debugMode {
Expand All @@ -40,6 +44,11 @@ func main() {
sugarLogger := logger.Sugar()
sugarLogger.Infof("initiated zap logger with level: %d", sugarLogger.Level())

if *disableSSL {
sslmode = "disable"
sugarLogger.Warn("SSL mode is disabled")
}

// Load the environment variables from the .env file
err = godotenv.Load()
if err != nil {
Expand All @@ -60,7 +69,7 @@ func main() {
gitProvider := os.Getenv("GIT_PROVIDER")

// Initialize the database handler
pizzaOven := database.NewPizzaOvenDbHandler(databaseHost, databasePort, databaseUser, databasePwd, databaseDbName)
pizzaOven := database.NewPizzaOvenDbHandler(databaseHost, databasePort, databaseUser, databasePwd, databaseDbName, sslmode)

// Initializes configuration using a provided yaml file
config := &server.Config{NeverEvictRepos: make(map[string]bool)}
Expand Down
4 changes: 2 additions & 2 deletions pkg/database/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ type PizzaOvenDbHandler struct {

// NewPizzaOvenDbHandler builds a PizzaOvenDbHandler based on the provided
// database connection parameters
func NewPizzaOvenDbHandler(host, port, user, pwd, dbName string) *PizzaOvenDbHandler {
connectString := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=require", host, port, user, pwd, dbName)
func NewPizzaOvenDbHandler(host, port, user, pwd, dbName, sslmode string) *PizzaOvenDbHandler {
connectString := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=%s", host, port, user, pwd, dbName, sslmode)

// Acquire the *sql.DB instance
dbPool, err := sql.Open("postgres", connectString)
Expand Down

0 comments on commit b026289

Please sign in to comment.