Skip to content

Commit

Permalink
Merge pull request #127 from 0xPolygon/config-ssl-mode
Browse files Browse the repository at this point in the history
Allow ssl mode to be configured
  • Loading branch information
christophercampbell authored Feb 26, 2025
2 parents e451625 + a4f77f5 commit f08ec98
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
working-directory: test

- name: Archive code coverage results
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: code-coverage-report
path: test/coverage.out
Expand All @@ -52,12 +52,12 @@ jobs:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis

- name: Download code coverage results
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: code-coverage-report

- name: Analyze with SonarCloud
uses: sonarsource/sonarcloud-github-action@master
uses: sonarsource/sonarqube-scan-action@master
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
1 change: 1 addition & 0 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Host = "cdk-data-availability-db"
Port = "5432"
EnableLog = false
MaxConns = 200
SSLMode = "disable"
[RPC]
Host = "0.0.0.0"
Expand Down
7 changes: 5 additions & 2 deletions db/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ type Config struct {

// MaxConns is the maximum number of connections in the pool.
MaxConns int `mapstructure:"MaxConns"`

// SSLMode: "require", "verify-full", "verify-ca", and "disable"
SSLMode string `mapstructure:"SSLMode"`
}

// InitContext initializes DB connection by the given config
func InitContext(ctx context.Context, cfg Config) (*sqlx.DB, error) {
psqlInfo := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=disable",
cfg.Host, cfg.Port, cfg.User, cfg.Password, cfg.Name)
psqlInfo := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=%s",
cfg.Host, cfg.Port, cfg.User, cfg.Password, cfg.Name, cfg.SSLMode)

conn, err := sqlx.ConnectContext(ctx, "postgres", psqlInfo)
if err != nil {
Expand Down

0 comments on commit f08ec98

Please sign in to comment.