Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow ssl mode to be configured #127

Merged
merged 5 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading