Skip to content

Commit 6ca702c

Browse files
authored
postgresql_privs: deprecate password argument in favor of login_password (#407)
Fixes #406
1 parent bbaee4f commit 6ca702c

File tree

11 files changed

+39
-54
lines changed

11 files changed

+39
-54
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
major_changes:
2+
- postgresql_privs - the ``password`` argument is deprecated and will be removed in community.postgresql 4.0.0, use the ``login_password`` argument instead (https://github.com/ansible-collections/community.postgresql/issues/406).

plugins/doc_fragments/postgres.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class ModuleDocFragment(object):
1515
- The username this module should use to establish its PostgreSQL session.
1616
type: str
1717
default: postgres
18+
aliases: [ login ]
1819
login_password:
1920
description:
2021
- The password this module should use to establish its PostgreSQL session.
@@ -26,11 +27,13 @@ class ModuleDocFragment(object):
2627
- If you have connection issues when using C(localhost), try to use C(127.0.0.1) instead.
2728
default: ''
2829
type: str
30+
aliases: [ host ]
2931
login_unix_socket:
3032
description:
3133
- Path to a Unix domain socket for local connections.
3234
type: str
3335
default: ''
36+
aliases: [ unix_socket ]
3437
port:
3538
description:
3639
- Database port to connect to.

plugins/module_utils/postgres.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ def postgres_common_argument_spec():
3838
The options are commonly used by most of PostgreSQL modules.
3939
"""
4040
return dict(
41-
login_user=dict(default='postgres'),
41+
login_user=dict(default='postgres', aliases=['login']),
4242
login_password=dict(default='', no_log=True),
43-
login_host=dict(default=''),
44-
login_unix_socket=dict(default=''),
43+
login_host=dict(default='', aliases=['host']),
44+
login_unix_socket=dict(default='', aliases=['unix_socket']),
4545
port=dict(type='int', default=5432, aliases=['login_port']),
4646
ssl_mode=dict(default='prefer', choices=['allow', 'disable', 'prefer', 'require', 'verify-ca', 'verify-full']),
4747
ca_cert=dict(aliases=['ssl_rootcert']),

plugins/modules/postgresql_privs.py

Lines changed: 28 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -112,41 +112,14 @@
112112
type: bool
113113
aliases:
114114
- admin_option
115-
host:
116-
description:
117-
- Database host address. If unspecified, connect via Unix socket.
118-
type: str
119-
default: ''
120-
aliases:
121-
- login_host
122-
port:
123-
description:
124-
- Database port to connect to.
125-
type: int
126-
default: 5432
127-
aliases:
128-
- login_port
129-
unix_socket:
130-
description:
131-
- Path to a Unix domain socket for local connections.
132-
type: str
133-
default: ''
134-
aliases:
135-
- login_unix_socket
136-
login:
137-
description:
138-
- The username to authenticate with.
139-
type: str
140-
default: postgres
141-
aliases:
142-
- login_user
143115
password:
144116
description:
145117
- The password to authenticate with.
118+
- This option has been B(deprecated) and will be removed in community.postgresql 4.0.0,
119+
use the I(login_password) option instead.
120+
- Mutually exclusive with I(login_password).
146121
type: str
147122
default: ''
148-
aliases:
149-
- login_password
150123
ssl_mode:
151124
description:
152125
- Determines whether or with what priority a secure SSL TCP/IP connection will be negotiated with the server.
@@ -193,7 +166,7 @@
193166
access via privileges granted to any role R is a member of including C(PUBLIC).
194167
- Note that when you use C(PUBLIC) role, the module always reports that the state has been changed.
195168
- Note that when revoking privileges from a role R, you do so as the user
196-
specified via I(login). If R has been granted the same privileges by
169+
specified via I(login_user). If R has been granted the same privileges by
197170
another user also, R can still access database objects via these privileges.
198171
- When revoking privileges, C(RESTRICT) is assumed (see PostgreSQL docs).
199172
@@ -525,9 +498,9 @@ def __init__(self, params, module):
525498
# check which values are empty and don't include in the **kw
526499
# dictionary
527500
params_map = {
528-
"host": "host",
529-
"login": "user",
530-
"password": "password",
501+
"login_host": "host",
502+
"login_user": "user",
503+
"login_password": "password",
531504
"port": "port",
532505
"database": "database",
533506
"ssl_mode": "sslmode",
@@ -537,10 +510,10 @@ def __init__(self, params, module):
537510
kw = dict((params_map[k], getattr(params, k)) for k in params_map
538511
if getattr(params, k) != '' and getattr(params, k) is not None)
539512

540-
# If a unix_socket is specified, incorporate it here.
513+
# If a login_unix_socket is specified, incorporate it here.
541514
is_localhost = "host" not in kw or kw["host"] == "" or kw["host"] == "localhost"
542-
if is_localhost and params.unix_socket != "":
543-
kw["host"] = params.unix_socket
515+
if is_localhost and params.login_unix_socket != "":
516+
kw["host"] = params.login_unix_socket
544517

545518
sslrootcert = params.ca_cert
546519
if psycopg2.__version__ < '2.4.3' and sslrootcert is not None:
@@ -1070,13 +1043,16 @@ def main():
10701043
target_roles=dict(required=False),
10711044
grant_option=dict(required=False, type='bool',
10721045
aliases=['admin_option']),
1073-
host=dict(default='', aliases=['login_host']),
1074-
unix_socket=dict(default='', aliases=['login_unix_socket']),
1075-
login=dict(default='postgres', aliases=['login_user']),
1076-
password=dict(default='', aliases=['login_password'], no_log=True),
1046+
# WARNING: password is deprecated and will be removed in community.postgresql 4.0.0,
1047+
# login_password should be used instead
1048+
password=dict(default='', no_log=True,
1049+
removed_in_version='4.0.0',
1050+
removed_from_collection='community.postgreql'),
10771051
fail_on_role=dict(type='bool', default=True),
10781052
trust_input=dict(type='bool', default=True),
1079-
usage_on_types=dict(type='bool', default=True, removed_in_version='3.0.0', removed_from_collection='community.postgresql'),
1053+
usage_on_types=dict(type='bool', default=True,
1054+
removed_in_version='3.0.0',
1055+
removed_from_collection='community.postgresql'),
10801056
)
10811057

10821058
module = AnsibleModule(
@@ -1089,6 +1065,16 @@ def main():
10891065

10901066
# Create type object as namespace for module params
10911067
p = type('Params', (), module.params)
1068+
1069+
# WARNING: password is deprecated and will be removed in community.postgresql 4.0.0,
1070+
# login_password should be used instead
1071+
# https://github.com/ansible-collections/community.postgresql/issues/406
1072+
if p.password:
1073+
if p.login_password:
1074+
module.fail_json(msg='Use the "password" or "login_password" option but not both '
1075+
'to pass a password to log in with.')
1076+
p.login_password = p.password
1077+
10921078
# param "schema": default, allowed depends on param "type"
10931079
if p.type in ['table', 'sequence', 'function', 'procedure', 'type', 'default_privs']:
10941080
if p.objs == 'schemas' or p.schema == 'not-specified':

tests/sanity/ignore-2.10.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ tests/utils/shippable/check_matrix.py replace-urlopen
22
tests/utils/shippable/timing.py shebang
33
plugins/modules/postgresql_db.py use-argspec-type-path
44
plugins/modules/postgresql_db.py validate-modules:use-run-command-not-popen
5-
plugins/modules/postgresql_privs.py validate-modules:parameter-documented-multiple-times
65
plugins/modules/postgresql_tablespace.py validate-modules:mutually_exclusive-unknown

tests/sanity/ignore-2.11.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ tests/utils/shippable/check_matrix.py replace-urlopen
22
tests/utils/shippable/timing.py shebang
33
plugins/modules/postgresql_db.py use-argspec-type-path
44
plugins/modules/postgresql_db.py validate-modules:use-run-command-not-popen
5-
plugins/modules/postgresql_privs.py validate-modules:parameter-documented-multiple-times
65
plugins/modules/postgresql_tablespace.py validate-modules:mutually_exclusive-unknown

tests/sanity/ignore-2.12.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ tests/utils/shippable/check_matrix.py replace-urlopen
22
tests/utils/shippable/timing.py shebang
33
plugins/modules/postgresql_db.py use-argspec-type-path
44
plugins/modules/postgresql_db.py validate-modules:use-run-command-not-popen
5-
plugins/modules/postgresql_privs.py validate-modules:parameter-documented-multiple-times
65
plugins/modules/postgresql_tablespace.py validate-modules:mutually_exclusive-unknown

tests/sanity/ignore-2.13.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ tests/utils/shippable/check_matrix.py replace-urlopen
22
tests/utils/shippable/timing.py shebang
33
plugins/modules/postgresql_db.py use-argspec-type-path
44
plugins/modules/postgresql_db.py validate-modules:use-run-command-not-popen
5-
plugins/modules/postgresql_privs.py validate-modules:parameter-documented-multiple-times
65
plugins/modules/postgresql_tablespace.py validate-modules:mutually_exclusive-unknown

tests/sanity/ignore-2.14.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ tests/utils/shippable/check_matrix.py replace-urlopen
22
tests/utils/shippable/timing.py shebang
33
plugins/modules/postgresql_db.py use-argspec-type-path
44
plugins/modules/postgresql_db.py validate-modules:use-run-command-not-popen
5-
plugins/modules/postgresql_privs.py validate-modules:parameter-documented-multiple-times
65
plugins/modules/postgresql_tablespace.py validate-modules:mutually_exclusive-unknown

tests/sanity/ignore-2.15.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ tests/utils/shippable/check_matrix.py replace-urlopen
22
tests/utils/shippable/timing.py shebang
33
plugins/modules/postgresql_db.py use-argspec-type-path
44
plugins/modules/postgresql_db.py validate-modules:use-run-command-not-popen
5-
plugins/modules/postgresql_privs.py validate-modules:parameter-documented-multiple-times
65
plugins/modules/postgresql_tablespace.py validate-modules:mutually_exclusive-unknown

0 commit comments

Comments
 (0)