Skip to content
Permalink
Browse files

[auth][db_manager]removed certs (if any) after postgres connection

  • Loading branch information
luipir committed Jan 13, 2016
1 parent 68478a7 commit 5fb798e220498222509b308c9def56c3bed6f42e
Showing with 41 additions and 3 deletions.
  1. +41 −3 python/plugins/db_manager/db_plugins/postgis/connector.py
@@ -23,7 +23,7 @@
"""

from PyQt4.QtCore import QRegExp
from qgis.core import QgsCredentials
from qgis.core import QgsCredentials, QgsDataSourceURI

from ..connector import DBConnector
from ..plugin import ConnectionError, DbError, Table
@@ -51,8 +51,9 @@ def __init__(self, uri):
username = uri.username() or os.environ.get('PGUSER') or os.environ.get('USER')
password = uri.password() or os.environ.get('PGPASSWORD')

expandedConnInfo = self._connectionInfo()
try:
self.connection = psycopg2.connect(self._connectionInfo().encode('utf-8'))
self.connection = psycopg2.connect(expandedConnInfo.encode('utf-8'))
except self.connection_error_types() as e:
err = unicode(e)
uri = self.uri()
@@ -69,14 +70,51 @@ def __init__(self, uri):
if password:
uri.setPassword(password)

newExpandedConnInfo = uri.connectionInfo(True)
try:
self.connection = psycopg2.connect(uri.connectionInfo(True).encode('utf-8'))
self.connection = psycopg2.connect(newExpandedConnInfo.encode('utf-8'))
QgsCredentials.instance().put(conninfo, username, password)
except self.connection_error_types() as e:
if i == 2:
raise ConnectionError(e)

err = unicode(e)
finally:
# remove certs (if any) of the expanded connectionInfo
expandedUri = QgsDataSourceURI(newExpandedConnInfo)

sslCertFile = expandedUri.param("sslcert")
if sslCertFile:
sslCertFile = sslCertFile.replace("'", "")
os.remove(sslCertFile)

sslKeyFile = expandedUri.param("sslkey")
if sslKeyFile:
sslKeyFile = sslKeyFile.replace("'", "")
os.remove(sslKeyFile)

sslCAFile = expandedUri.param("sslrootcert")
if sslCAFile:
sslCAFile = sslCAFile.replace("'", "")
os.remove(sslCAFile)
finally:
# remove certs (if any) of the expanded connectionInfo
expandedUri = QgsDataSourceURI(expandedConnInfo)

sslCertFile = expandedUri.param("sslcert")
if sslCertFile:
sslCertFile = sslCertFile.replace("'", "")
os.remove(sslCertFile)

sslKeyFile = expandedUri.param("sslkey")
if sslKeyFile:
sslKeyFile = sslKeyFile.replace("'", "")
os.remove(sslKeyFile)

sslCAFile = expandedUri.param("sslrootcert")
if sslCAFile:
sslCAFile = sslCAFile.replace("'", "")
os.remove(sslCAFile)

self.connection.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)

0 comments on commit 5fb798e

Please sign in to comment.
You can’t perform that action at this time.