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

feat: add SHIORI_PG_SSLMODE #536

Merged
merged 3 commits into from
Jul 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ services:
SHIORI_PG_NAME: shiori
SHIORI_PG_HOST: postgres
SHIORI_PG_PORT: 5432
SHIORI_PG_SSLMODE: disable
SHIORI_MYSQL_USER: shiori
SHIORI_MYSQL_PASS: shiori
SHIORI_MYSQL_NAME: shiori
Expand Down
17 changes: 9 additions & 8 deletions docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ Shiori uses an SQLite3 database stored in the above data directory by default. I

### PostgreSQL

| Variable | Description |
|---------------------|--------------------------------------------|
| `SHIORI_DBMS` | Must be set to `postgresql` |
| `SHIORI_PG_USER` | Name of PostgreSQL user |
| `SHIORI_PG_PASS` | Password for the above user |
| `SHIORI_PG_NAME` | Name of database to use |
| `SHIORI_PG_HOST` | Address of PostgreSQL server |
| `SHIORI_PG_PORT` | Port number used by PostgreSQL server |
| Variable | Description |
|---------------------|-----------------------------------------------------|
| `SHIORI_DBMS` | Must be set to `postgresql` |
| `SHIORI_PG_USER` | Name of PostgreSQL user |
| `SHIORI_PG_PASS` | Password for the above user |
| `SHIORI_PG_NAME` | Name of database to use |
| `SHIORI_PG_HOST` | Address of PostgreSQL server |
| `SHIORI_PG_PORT` | Port number used by PostgreSQL server |
| `SHIORI_PG_SSLMODE` | PostgreSQL connection SSL mode (default: `disable`) |
8 changes: 6 additions & 2 deletions internal/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,12 @@ func openPostgreSQLDatabase(ctx context.Context) (database.DB, error) {
user, _ := os.LookupEnv("SHIORI_PG_USER")
password, _ := os.LookupEnv("SHIORI_PG_PASS")
dbName, _ := os.LookupEnv("SHIORI_PG_NAME")
sslmode, ok := os.LookupEnv("SHIORI_PG_SSLMODE")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep in mind that in this case ok will be true in the case SHIORI_PG_SSLMODE is an empty string. Unsure how Posgres will react to that. Maybe is better to check for sslMode == "".

if !ok {
sslmode = "disable"
}

connString := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=disable",
host, port, user, password, dbName)
connString := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=%s",
host, port, user, password, dbName, sslmode)
return database.OpenPGDatabase(ctx, connString)
}