Skip to content

Commit

Permalink
Pass the PostgreSQL "PGSSLMODE" environment variable through to Borg …
Browse files Browse the repository at this point in the history
…(#370).
  • Loading branch information
witten committed Jan 25, 2024
1 parent ad1d104 commit 75d11aa
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
1.8.8.dev0
* #370: For the PostgreSQL hook, pass the "PGSSLMODE" environment variable through to Borg when the
database's configuration omits the "ssl_mode" option.
* #818: Allow the "--repository" flag to match across multiple configuration files.
* #820: Fix broken repository detection in the "rcreate" action with Borg 1.4. The issue did not
occur with other versions of Borg.
Expand Down
8 changes: 5 additions & 3 deletions borgmatic/hooks/postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def make_dump_path(config): # pragma: no cover

def make_extra_environment(database, restore_connection_params=None):
'''
Make the extra_environment dict from the given database configuration.
If restore connection params are given, this is for a restore operation.
Make the extra_environment dict from the given database configuration. If restore connection
params are given, this is for a restore operation.
'''
extra = dict()

Expand All @@ -40,7 +40,8 @@ def make_extra_environment(database, restore_connection_params=None):
except (AttributeError, KeyError):
pass

extra['PGSSLMODE'] = database.get('ssl_mode', 'disable')
if 'ssl_mode' in database:
extra['PGSSLMODE'] = database['ssl_mode']
if 'ssl_cert' in database:
extra['PGSSLCERT'] = database['ssl_cert']
if 'ssl_key' in database:
Expand All @@ -49,6 +50,7 @@ def make_extra_environment(database, restore_connection_params=None):
extra['PGSSLROOTCERT'] = database['ssl_root_cert']
if 'ssl_crl' in database:
extra['PGSSLCRL'] = database['ssl_crl']

return extra


Expand Down
8 changes: 8 additions & 0 deletions tests/unit/hooks/test_postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ def test_make_extra_environment_without_cli_password_or_configured_password_does
assert 'PGPASSWORD' not in extra


def test_make_extra_environment_without_ssl_mode_does_not_set_ssl_mode():
database = {'name': 'foo'}

extra = module.make_extra_environment(database)

assert 'PGSSLMODE' not in extra


def test_database_names_to_dump_passes_through_individual_database_name():
database = {'name': 'foo'}

Expand Down

0 comments on commit 75d11aa

Please sign in to comment.