Skip to content

Commit

Permalink
Merge branch 'sslmode'
Browse files Browse the repository at this point in the history
  • Loading branch information
elwinar committed Nov 15, 2020
2 parents 92bfad9 + a8d8b33 commit 2ca0334
Show file tree
Hide file tree
Showing 5 changed files with 267 additions and 22 deletions.
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,17 @@ values of rambler:

```json
{
"database": "",
"directory": ".",
"driver": "mysql",
"protocol": "tcp",
"host": "localhost",
"password": "",
"port": 3306,
"protocol": "tcp",
"schema": "public",
"sslmode": "disable"
"table": "migrations",
"user": "root",
"password": "",
"database": "",
"schema": "",
"directory": ".",
"table": "migrations"
}
```

Expand All @@ -95,16 +96,17 @@ are prefixed with `RAMBLER_`.

| Env Var | Config |
|-------------------|-----------|
| RAMBLER_DATABASE | database |
| RAMBLER_DIRECTORY | directory |
| RAMBLER_DRIVER | driver |
| RAMBLER_PROTOCOL | protocol |
| RAMBLER_HOST | host |
| RAMBLER_PORT | port |
| RAMBLER_USER | user |
| RAMBLER_PASSWORD | password |
| RAMBLER_DATABASE | database |
| RAMBLER_PORT | port |
| RAMBLER_PROTOCOL | protocol |
| RAMBLER_SCHEMA | schema |
| RAMBLER_DIRECTORY | directory |
| RAMBLER_SSLMODE | sslmode |
| RAMBLER_TABLE | table |
| RAMBLER_USER | user |

#### Drivers

Expand Down
1 change: 1 addition & 0 deletions driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type Config struct {
Database string `json:"database"`
Schema string `json:"schema"` // For PostgreSQL
Table string `json:"table"`
SSLMode string `json:"sslmode"` // For PostgreSQL
}

// Conn is the interface used by the program to manipulate the database.
Expand Down
8 changes: 6 additions & 2 deletions driver/postgresql/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ func (d Driver) New(config driver.Config) (driver.Conn, error) {
config.Schema = "public"
}

if config.SSLMode == "" {
config.SSLMode = "disable"
}

db, err := sql.Open("postgres", fmt.Sprintf(
"host=%s port=%d user=%s password=%s dbname=%s search_path=%s sslmode=disable",
config.Host, config.Port, config.User, config.Password, config.Database, config.Schema,
"host=%s port=%d user=%s password=%s dbname=%s search_path=%s sslmode=%s",
config.Host, config.Port, config.User, config.Password, config.Database, config.Schema, config.SSLMode,
))
if err != nil {
return nil, err
Expand Down
19 changes: 10 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ go 1.12
require (
github.com/bradfitz/slice v0.0.0-20180809154707-2b758aa73013
github.com/client9/xson v0.0.0-20180321172152-0e50cdfc08c0
github.com/go-sql-driver/mysql v1.4.1
github.com/google/go-cmp v0.3.0
github.com/imdario/mergo v0.3.7
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
github.com/go-sql-driver/mysql v1.5.0
github.com/google/go-cmp v0.4.0
github.com/imdario/mergo v0.3.11
github.com/karalabe/xgo v0.0.0-20190301120235-2d6d1848fb02 // indirect
github.com/kelseyhightower/envconfig v1.4.0
github.com/lib/pq v1.1.1
github.com/mattn/go-sqlite3 v1.10.0
github.com/urfave/cli v1.20.0
go4.org v0.0.0-20190313082347-94abd6928b1d // indirect
google.golang.org/appengine v1.6.0 // indirect
gopkg.in/yaml.v2 v2.2.2 // indirect
github.com/lib/pq v1.8.0
github.com/mattn/go-sqlite3 v1.14.4
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/urfave/cli v1.22.5
go4.org v0.0.0-20200411211856-f5505b9728dd // indirect
google.golang.org/appengine v1.6.7 // indirect
)
Loading

0 comments on commit 2ca0334

Please sign in to comment.