Skip to content

Commit

Permalink
Use ssl to connect to databases in lambdas (#2334)
Browse files Browse the repository at this point in the history
## 🎫 Ticket

https://jira.cms.gov/browse/DPC-4415

## 🛠 Changes

Conditionally force sslmode depending on environment

## ℹ️ Context
In our upgrade to postgres 16, we have to use ssl. We had ssl turned off
for our lambdas so they could run against our local database (for
testing), which are not set up for ssl. New code runs in sslmode except
when 'testing' (which includes running locally)

## 🧪 Validation
Tested both locally (test and run-local)
Uploaded export to test and it worked.
Uploaded import to test but unsure how to test?
  • Loading branch information
jdettmannnava authored Nov 21, 2024
1 parent 4d4f909 commit 52df5e8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lambda/opt-out-export/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import (
var createConnection = func(dbName string, dbUser string, dbPassword string) (*sql.DB, error) {
var dbHost string = os.Getenv("DB_HOST")
var dbPort int = 5432
psqlInfo := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable", dbHost, dbPort, dbUser, dbPassword, dbName)
var sslmode string = "require"
if isTesting {
sslmode = "disable"
}
psqlInfo := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=%s", dbHost, dbPort, dbUser, dbPassword, dbName, sslmode)

db, err := sql.Open("postgres", psqlInfo)
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion lambda/opt-out-import/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,11 @@ func createConnection(dbUser string, dbPassword string) (*sql.DB, error) {
var dbName string = "dpc_consent"
var dbHost string = os.Getenv("DB_HOST")
var dbPort int = 5432
psqlInfo := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable", dbHost, dbPort, dbUser, dbPassword, dbName)
var sslmode string = "require"
if isTesting {
sslmode = "disable"
}
psqlInfo := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=%s", dbHost, dbPort, dbUser, dbPassword, dbName, sslmode)

db, err := sql.Open("postgres", psqlInfo)
if err != nil {
Expand Down

0 comments on commit 52df5e8

Please sign in to comment.