mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-01-27 10:20:10 +00:00
Make sure only supported parameters are written to connection string (#3207)
Close #3206
This commit is contained in:
committed by
GitHub
parent
e1faa38e90
commit
efba02f52e
@@ -617,7 +617,10 @@ class ConfigHandler(object):
|
||||
def escape(value: Any) -> str:
|
||||
return re.sub(r'([\'\\ ])', r'\\\1', str(value))
|
||||
|
||||
return ' '.join('{0}={1}'.format(kw, escape(params[kw])) for kw in keywords if params.get(kw) is not None)
|
||||
key_ver = {'target_session_attrs': 100000, 'gssencmode': 120000, 'channel_binding': 130000,
|
||||
'sslpassword': 130000, 'sslcrldir': 140000, 'sslnegotiation': 170000}
|
||||
return ' '.join('{0}={1}'.format(kw, escape(params[kw])) for kw in keywords
|
||||
if params.get(kw) is not None and self._postgresql.major_version >= key_ver.get(kw, 0))
|
||||
|
||||
def _write_recovery_params(self, fd: ConfigWriter, recovery_params: CaseInsensitiveDict) -> None:
|
||||
if self._postgresql.major_version >= 90500:
|
||||
|
||||
@@ -1182,3 +1182,26 @@ class TestPostgresql2(BaseTestPostgresql):
|
||||
self.assertEqual(dict(self.p.config._recovery_params),
|
||||
{'primary_conninfo': {'host': 'a', 'port': '5433', 'passfile': '/blabla', 'sslmode': 'prefer',
|
||||
'gssencmode': 'prefer', 'channel_binding': 'prefer', 'sslnegotiation': 'postgres'}})
|
||||
|
||||
def test_format_dsn(self):
|
||||
params = {'host': '1', 'port': 2, 'target_session_attrs': 'read-write', 'gssencmode': 'prefer',
|
||||
'channel_binding': 'prefer', 'sslpassword': 'pwd', 'sslcrldir': '/', 'sslnegotiation': 'postgres'}
|
||||
self.p._major_version = 90600
|
||||
self.assertEqual(self.p.config.format_dsn(params), 'host=1 port=2')
|
||||
self.p._major_version = 100000
|
||||
self.assertEqual(self.p.config.format_dsn(params), 'host=1 port=2 target_session_attrs=read-write')
|
||||
self.p._major_version = 120000
|
||||
self.assertEqual(self.p.config.format_dsn(params),
|
||||
'host=1 port=2 gssencmode=prefer target_session_attrs=read-write')
|
||||
self.p._major_version = 130000
|
||||
self.assertEqual(self.p.config.format_dsn(params),
|
||||
'host=1 port=2 sslpassword=pwd gssencmode=prefer '
|
||||
'channel_binding=prefer target_session_attrs=read-write')
|
||||
self.p._major_version = 140000
|
||||
self.assertEqual(self.p.config.format_dsn(params),
|
||||
'host=1 port=2 sslpassword=pwd sslcrldir=/ gssencmode=prefer '
|
||||
'channel_binding=prefer target_session_attrs=read-write')
|
||||
self.p._major_version = 170000
|
||||
self.assertEqual(self.p.config.format_dsn(params),
|
||||
'host=1 port=2 sslpassword=pwd sslcrldir=/ gssencmode=prefer channel_binding=prefer '
|
||||
'target_session_attrs=read-write sslnegotiation=postgres')
|
||||
|
||||
Reference in New Issue
Block a user