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

Add support for the sslnegotiation DSN option #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
13 changes: 9 additions & 4 deletions postgres_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ type PostgresConfig struct {
User string `long:"user" description:"The user to sign in as."`
Password string `long:"password" description:"The user's password."`

SSLMode string `long:"sslmode" description:"Whether or not to use SSL." default:"disable" choice:"disable" choice:"require" choice:"verify-ca" choice:"verify-full"`
CACert File `long:"ca-cert" description:"CA cert file location, to verify when connecting with SSL."`
ClientCert File `long:"client-cert" description:"Client cert file location."`
ClientKey File `long:"client-key" description:"Client key file location."`
SSLMode string `long:"sslmode" description:"Whether or not to use SSL." default:"disable" choice:"disable" choice:"require" choice:"verify-ca" choice:"verify-full"`
CACert File `long:"ca-cert" description:"CA cert file location, to verify when connecting with SSL."`
ClientCert File `long:"client-cert" description:"Client cert file location."`
ClientKey File `long:"client-key" description:"Client key file location."`
SSLNegotiation string `long:"sslnegotiation" description:"Controls how SSL encryption is negotiated with the server, if SSL is used. The direct SSL option was introduced in PostgreSQL version 17." default:"postgres" choice:"postgres" choice:"direct"`

BinaryParameters bool `long:"binary-parameters" description:"Whether or not to use binary parameters for prepared statements."`

Expand Down Expand Up @@ -63,6 +64,10 @@ func (config PostgresConfig) ConnectionString() string {
properties["sslkey"] = config.ClientKey.Path()
}

if config.SSLNegotiation != "" {
properties["sslnegotiation"] = config.SSLNegotiation
}

if config.ConnectTimeout != 0 {
properties["connect_timeout"] = strconv.Itoa(int(config.ConnectTimeout.Seconds()))
}
Expand Down
19 changes: 18 additions & 1 deletion postgres_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package flag_test

import (
"github.com/concourse/flag/v2"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
Expand Down Expand Up @@ -42,3 +41,21 @@ var _ = Describe("PostgresConfig", func() {
})
})
})

var _ = Describe("PostgresConfig", func() {
Describe("ConnectionString", func() {
It("adds sslnegotiation correctly", func() {
Expect(flag.PostgresConfig{
Host: "1.2.3.4",
Port: 5432,

User: "some user",
Password: "not-so-important",

SSLNegotiation: "direct",

Database: "atc",
}.ConnectionString()).To(Equal("dbname='atc' host='1.2.3.4' password='not-so-important' port=5432 sslmode='' sslnegotiation='direct' user='some user'"))
})
})
})