Skip to content

Commit 56a1ea9

Browse files
committed
provider/postgresql: Quote connection string parameters
1 parent 2d894ba commit 56a1ea9

3 files changed

Lines changed: 5 additions & 4 deletions

File tree

builtin/providers/postgresql/GNUmakefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ PSQL?=/opt/local/lib/postgresql96/bin/psql
44
PGDATA?=$(GOPATH)/src/github.com/hashicorp/terraform/builtin/providers/postgresql/data
55

66
initdb::
7-
/opt/local/lib/postgresql96/bin/initdb --no-locale -U postgres -D $(PGDATA)
7+
echo "" > pwfile
8+
/opt/local/lib/postgresql96/bin/initdb --no-locale -U postgres -A md5 --pwfile=pwfile -D $(PGDATA)
89

910
startdb::
1011
2>&1 \
@@ -18,6 +19,7 @@ startdb::
1819

1920
cleandb::
2021
rm -rf $(PGDATA)
22+
rm -f pwfile
2123

2224
freshdb:: cleandb initdb startdb
2325

builtin/providers/postgresql/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type Client struct {
3131
func (c *Config) NewClient() (*Client, error) {
3232
// NOTE: dbname must come before user otherwise dbname will be set to
3333
// user.
34-
const dsnFmt = "host=%s port=%d dbname=%s user=%s password=%s sslmode=%s fallback_application_name=%s connect_timeout=%d"
34+
const dsnFmt = "host='%s' port='%d' dbname='%s' user='%s' password='%s' sslmode='%s' fallback_application_name='%s' connect_timeout='%d'"
3535

3636
logDSN := fmt.Sprintf(dsnFmt, c.Host, c.Port, c.Database, c.Username, "<redacted>", c.SSLMode, c.ApplicationName, c.ConnectTimeoutSec)
3737
log.Printf("[INFO] PostgreSQL DSN: `%s`", logDSN)

builtin/providers/postgresql/provider.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,10 @@ func tfAppName() string {
112112
const VersionPrerelease = terraform.VersionPrerelease
113113
var versionString bytes.Buffer
114114

115-
fmt.Fprintf(&versionString, "'Terraform v%s", terraform.Version)
115+
fmt.Fprintf(&versionString, "Terraform v%s", terraform.Version)
116116
if terraform.VersionPrerelease != "" {
117117
fmt.Fprintf(&versionString, "-%s", terraform.VersionPrerelease)
118118
}
119-
fmt.Fprintf(&versionString, "'")
120119

121120
return versionString.String()
122121
}

0 commit comments

Comments
 (0)