Hi,

Please find the attached updated patch.

Thanks,
Khushboo

On Wed, Mar 14, 2018 at 1:07 PM, Khushboo Vashi <
khushboo.va...@enterprisedb.com> wrote:

>
>
> On Wed, Mar 14, 2018 at 12:48 PM, Murtuza Zabuawala <murtuza.zabuawala@
> enterprisedb.com> wrote:
>
>>  ../pgadmin4/web/pgadmin/tools/import_export/__init__.py +310 without
>> your patch applied.
>>
>> Yes, good point. Will update and send the patch.
>
>>
>> On Wed, Mar 14, 2018 at 12:39 PM, Murtuza Zabuawala <
>> murtuza.zabuaw...@enterprisedb.com> wrote:
>>
>>> Hi Khushboo,
>>>
>>> We can simplify this, we don't need to create any extra column,
>>>
>>> Check: ../pgadmin4/web/pgadmin/tools/import_export/__init__.py +322
>>> where we are setting ENV variable we can create common utility function
>>> (let say in ../tools/utils/__init__.py) which will set all required the
>>> environment variables and then we will pass that function in p.start(..)
>>> method.
>>>
>>>
>>> --
>>> Regards,
>>> Murtuza Zabuawala
>>> EnterpriseDB: http://www.enterprisedb.com
>>> The Enterprise PostgreSQL Company
>>>
>>>
>>> On Wed, Mar 14, 2018 at 11:03 AM, Khushboo Vashi <
>>> khushboo.va...@enterprisedb.com> wrote:
>>>
>>>> Hi,
>>>>
>>>> Please find the attached patch to fix RM #3122 : Backup not working on
>>>> certificate (SSL) protected servers.
>>>>
>>>> The attached patch fixes the issue in the following modules:
>>>>
>>>> 1. Backup
>>>> 2. Restore
>>>> 3. Import/Export
>>>> 4. Maintenance
>>>>
>>>> Thanks,
>>>> Khushboo
>>>>
>>>>
>>>>
>>>
>>
>
diff --git a/web/pgadmin/misc/bgprocess/processes.py b/web/pgadmin/misc/bgprocess/processes.py
index c456b4f..cefb51a 100644
--- a/web/pgadmin/misc/bgprocess/processes.py
+++ b/web/pgadmin/misc/bgprocess/processes.py
@@ -19,7 +19,8 @@ from datetime import datetime
 from pickle import dumps, loads
 from subprocess import Popen
 
-from pgadmin.utils import IS_PY2, u, file_quote, fs_encoding
+from pgadmin.utils import IS_PY2, u, file_quote, fs_encoding, \
+    get_complete_file_path
 
 import pytz
 from dateutil import parser
@@ -62,6 +63,7 @@ class BatchProcess(object):
         self.id = self.desc = self.cmd = self.args = self.log_dir = \
             self.stdout = self.stderr = self.stime = self.etime = \
             self.ecode = None
+        self.env = dict()
 
         if 'id' in kwargs:
             self._retrieve_process(kwargs['id'])
@@ -330,6 +332,9 @@ class BatchProcess(object):
         env['OUTDIR'] = self.log_dir
         env['PGA_BGP_FOREGROUND'] = "1"
 
+        if self.env:
+            env.update(self.env)
+
         if cb is not None:
             cb(env)
 
@@ -622,3 +627,18 @@ class BatchProcess(object):
             p.acknowledge = get_current_time()
 
         db.session.commit()
+
+    def set_env_variables(self, server, **kwargs):
+        """Set environment variables"""
+        if server and server.sslcert is not None and \
+                server.sslkey is not None and \
+                server.sslrootcert is not None:
+            # SSL environment variables
+            self.env['PGSSLMODE'] = server.ssl_mode
+            self.env['PGSSLCERT'] = get_complete_file_path(server.sslcert)
+            self.env['PGSSLKEY'] = get_complete_file_path(server.sslkey)
+            self.env['PGSSLROOTCERT'] = \
+                get_complete_file_path(server.sslrootcert)
+
+        if 'env' in kwargs:
+            self.env.update(kwargs['env'])
diff --git a/web/pgadmin/tools/backup/__init__.py b/web/pgadmin/tools/backup/__init__.py
index 940ef5b..8936e53 100644
--- a/web/pgadmin/tools/backup/__init__.py
+++ b/web/pgadmin/tools/backup/__init__.py
@@ -300,6 +300,7 @@ def create_backup_job(sid):
         '--database',
         server.maintenance_db
     ]
+
     if 'role' in data and data['role']:
         args.append('--role')
         args.append(data['role'])
@@ -323,6 +324,7 @@ def create_backup_job(sid):
             cmd=utility, args=args
         )
         manager.export_password_env(p.id)
+        p.set_env_variables(server)
         p.start()
         jid = p.id
     except Exception as e:
@@ -486,6 +488,7 @@ def create_backup_objects_job(sid):
             cmd=utility, args=args
         )
         manager.export_password_env(p.id)
+        p.set_env_variables(server)
         p.start()
         jid = p.id
     except Exception as e:
diff --git a/web/pgadmin/tools/import_export/__init__.py b/web/pgadmin/tools/import_export/__init__.py
index 3f83fd4..9690475 100644
--- a/web/pgadmin/tools/import_export/__init__.py
+++ b/web/pgadmin/tools/import_export/__init__.py
@@ -307,13 +307,13 @@ def create_import_export_job(sid):
         )
         manager.export_password_env(p.id)
 
-        def export_pg_env(env):
-            env['PGHOST'] = server.host
-            env['PGPORT'] = str(server.port)
-            env['PGUSER'] = server.username
-            env['PGDATABASE'] = data['database']
-
-        p.start(export_pg_env)
+        env = dict()
+        env['PGHOST'] = server.host
+        env['PGPORT'] = str(server.port)
+        env['PGUSER'] = server.username
+        env['PGDATABASE'] = data['database']
+        p.set_env_variables(server, env=env)
+        p.start()
         jid = p.id
     except Exception as e:
         current_app.logger.exception(e)
diff --git a/web/pgadmin/tools/maintenance/__init__.py b/web/pgadmin/tools/maintenance/__init__.py
index 8416a20..088922b 100644
--- a/web/pgadmin/tools/maintenance/__init__.py
+++ b/web/pgadmin/tools/maintenance/__init__.py
@@ -236,6 +236,7 @@ def create_maintenance_job(sid, did):
             cmd=utility, args=args
         )
         manager.export_password_env(p.id)
+        p.set_env_variables(server)
         p.start()
         jid = p.id
     except Exception as e:
diff --git a/web/pgadmin/tools/restore/__init__.py b/web/pgadmin/tools/restore/__init__.py
index 6afa7b4..db1d522 100644
--- a/web/pgadmin/tools/restore/__init__.py
+++ b/web/pgadmin/tools/restore/__init__.py
@@ -329,6 +329,7 @@ def create_restore_job(sid):
             cmd=utility, args=args
         )
         manager.export_password_env(p.id)
+        p.set_env_variables(server)
         p.start()
         jid = p.id
     except Exception as e:

Reply via email to