Skip to content

Commit

Permalink
Escape username and password when building connection URI
Browse files Browse the repository at this point in the history
Fixes #11
  • Loading branch information
Jamie English committed Jan 23, 2020
1 parent 87cea7f commit a06ccf9
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions postgresreplication/resource_replication_slot.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package postgresreplication

import (
"fmt"
"net/url"

"github.com/hashicorp/terraform/helper/schema"
"github.com/jackc/pgx"
"github.com/pkg/errors"
Expand Down Expand Up @@ -47,13 +49,18 @@ func resourceReplicationSlot() *schema.Resource {

func connect(d *schema.ResourceData, m interface{}) (r *pgx.ReplicationConn, err error) {
c := m.(*providerConfiguration)
dbConfig, err := pgx.ParseURI(fmt.Sprintf("postgres://%s:%s@%s:%d/%s?sslmode=%s",
c.user,
c.password,

u, err := url.Parse(fmt.Sprintf("postgres://%s:%d/%s?sslmode=%s",
c.host,
c.port,
d.Get(databaseAttributeName).(string),
c.sslMode))
if err != nil {
return nil, errors.Wrap(err, "error contructing database connection uri.")
}

u.User = url.UserPassword(c.user, c.password)
dbConfig, err := pgx.ParseURI(u.String())

if err != nil {
return nil, errors.Wrap(err, "error setting up database connection.")
Expand Down

0 comments on commit a06ccf9

Please sign in to comment.