From b0262890b6d74ef85e2d5f57daa73e9ac7f81879 Mon Sep 17 00:00:00 2001 From: Kin NG <59541661+k1nho@users.noreply.github.com> Date: Mon, 9 Oct 2023 15:16:27 -0400 Subject: [PATCH] feat: Ability to turn off sslmode (#58) --- Makefile | 5 ++++- main.go | 13 +++++++++++-- pkg/database/handler.go | 4 ++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index b4e3440..e719831 100644 --- a/Makefile +++ b/Makefile @@ -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)))) @@ -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 diff --git a/main.go b/main.go index e7d3a74..14bc848 100644 --- a/main.go +++ b/main.go @@ -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 { @@ -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 { @@ -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)} diff --git a/pkg/database/handler.go b/pkg/database/handler.go index 86f56e4..8b0459d 100644 --- a/pkg/database/handler.go +++ b/pkg/database/handler.go @@ -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)