Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix connect_params being ignored on postgresql_privs #451

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- postgresql_privs - fix connect_params being ignored (https://github.com/ansible-collections/community.postgresql/issues/450).
12 changes: 3 additions & 9 deletions plugins/modules/postgresql_privs.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@
pg_quote_identifier,
check_input,
)
from ansible_collections.community.postgresql.plugins.module_utils.postgres import postgres_common_argument_spec
from ansible_collections.community.postgresql.plugins.module_utils.postgres import postgres_common_argument_spec, get_conn_params
from ansible.module_utils._text import to_native

VALID_PRIVS = frozenset(('SELECT', 'INSERT', 'UPDATE', 'DELETE', 'TRUNCATE',
Expand Down Expand Up @@ -507,19 +507,13 @@ def __init__(self, params, module):
"ca_cert": "sslrootcert"
}

kw = dict((params_map[k], getattr(params, k)) for k in params_map
if getattr(params, k) != '' and getattr(params, k) is not None)

# If a login_unix_socket is specified, incorporate it here.
is_localhost = "host" not in kw or kw["host"] == "" or kw["host"] == "localhost"
if is_localhost and params.login_unix_socket != "":
kw["host"] = params.login_unix_socket
conn_params = get_conn_params(module, module.params, warn_db_default=False)

sslrootcert = params.ca_cert
if psycopg2.__version__ < '2.4.3' and sslrootcert is not None:
raise ValueError('psycopg2 must be at least 2.4.3 in order to user the ca_cert parameter')

self.connection = psycopg2.connect(**kw)
self.connection = psycopg2.connect(**conn_params)
self.cursor = self.connection.cursor()
self.pg_version = self.connection.server_version

Expand Down