Ver Fonte

Pass the PostgreSQL "PGSSLMODE" environment variable through to Borg (#370).

Dan Helfman há 1 ano atrás
pai
commit
75d11aa9cd
3 ficheiros alterados com 15 adições e 3 exclusões
  1. 2 0
      NEWS
  2. 5 3
      borgmatic/hooks/postgresql.py
  3. 8 0
      tests/unit/hooks/test_postgresql.py

+ 2 - 0
NEWS

@@ -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.

+ 5 - 3
borgmatic/hooks/postgresql.py

@@ -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()
 
@@ -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:
@@ -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
 
 

+ 8 - 0
tests/unit/hooks/test_postgresql.py

@@ -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'}