为mysql和postgres数据库启用ssl:python、sqlalchemy
我想为我的两种类型启用ssl,为mysql和postgres数据库启用ssl:python、sqlalchemy,python,mysql,postgresql,sqlalchemy,Python,Mysql,Postgresql,Sqlalchemy,我想为我的两种类型启用ssl,mysql和postgres用于数据库连接。我的存储库中有证书文件,并使用这些证书在docker上运行代码。我正在使用以下代码: uri = "{0}://{1}@{2}:{3}/{4}".format(db_creds.get('scheme'), self._get_auth_str(db_creds.get('username'),
mysql
和postgres
用于数据库连接。我的存储库中有证书文件,并使用这些证书在docker上运行代码。我正在使用以下代码:
uri = "{0}://{1}@{2}:{3}/{4}".format(db_creds.get('scheme'),
self._get_auth_str(db_creds.get('username'),
db_creds.get('password')),
db_creds.get('hostname'),
str(db_creds.get('port')),
db_creds.get('name'))
ssl_args = {}
if db == 'mysql':
if self.config['ssloption'] == 'true':
self.config['ssloption'] = 'required'
ssl_args = {
'ssl': {
'sslmode': str(self.config['ssloption'])
}
}
if db == 'warehouse':
if self.config['ssloption'] == 'true':
self.config['ssloption'] = 'require'
ssl_args = {
"sslmode": str(self.config['ssloption'])
}
self._connections[db] = create_engine(uri, connect_args=ssl_args, encoding='utf8')
我已经尝试了在线文档中提供的所有选项,但我找不到一种通用的方法来为这两种类型的数据库执行此操作。我想知道我怎样才能在这方面做到完美