mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
* postgresql_privs: add usage_of_types option
* add CI tests
* add changelog fragment
(cherry picked from commit 77bf8b9a66
)
Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
This commit is contained in:
parent
407d776610
commit
90ed2fa5c3
3 changed files with 55 additions and 9 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
minor_changes:
|
||||||
|
- postgresql_privs - add the ``usage_on_types`` option (https://github.com/ansible-collections/community.general/issues/884).
|
|
@ -161,6 +161,15 @@ options:
|
||||||
type: bool
|
type: bool
|
||||||
default: yes
|
default: yes
|
||||||
version_added: '0.2.0'
|
version_added: '0.2.0'
|
||||||
|
usage_on_types:
|
||||||
|
description:
|
||||||
|
- When adding default privileges, the module always implicitly adds ``USAGE ON TYPES``.
|
||||||
|
- To avoid this behavior, set I(usage_on_types) to C(no).
|
||||||
|
- Added to save backwards compatibility.
|
||||||
|
- Used only when adding default privileges, ignored otherwise.
|
||||||
|
type: bool
|
||||||
|
default: yes
|
||||||
|
version_added: '1.2.0'
|
||||||
|
|
||||||
notes:
|
notes:
|
||||||
- Parameters that accept comma separated lists (I(privs), I(objs), I(roles))
|
- Parameters that accept comma separated lists (I(privs), I(objs), I(roles))
|
||||||
|
@ -658,7 +667,7 @@ class Connection(object):
|
||||||
# Manipulating privileges
|
# Manipulating privileges
|
||||||
|
|
||||||
def manipulate_privs(self, obj_type, privs, objs, roles, target_roles,
|
def manipulate_privs(self, obj_type, privs, objs, roles, target_roles,
|
||||||
state, grant_option, schema_qualifier=None, fail_on_role=True):
|
state, grant_option, schema_qualifier=None, fail_on_role=True, usage_on_types=True):
|
||||||
"""Manipulate database object privileges.
|
"""Manipulate database object privileges.
|
||||||
|
|
||||||
:param obj_type: Type of database object to grant/revoke
|
:param obj_type: Type of database object to grant/revoke
|
||||||
|
@ -780,6 +789,7 @@ class Connection(object):
|
||||||
.for_schema(schema_qualifier) \
|
.for_schema(schema_qualifier) \
|
||||||
.set_what(set_what) \
|
.set_what(set_what) \
|
||||||
.for_objs(objs) \
|
.for_objs(objs) \
|
||||||
|
.usage_on_types(usage_on_types) \
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
executed_queries.append(query)
|
executed_queries.append(query)
|
||||||
|
@ -811,6 +821,7 @@ class QueryBuilder(object):
|
||||||
self._state = state
|
self._state = state
|
||||||
self._schema = None
|
self._schema = None
|
||||||
self._objs = None
|
self._objs = None
|
||||||
|
self._usage_on_types = None
|
||||||
self.query = []
|
self.query = []
|
||||||
|
|
||||||
def for_objs(self, objs):
|
def for_objs(self, objs):
|
||||||
|
@ -829,6 +840,10 @@ class QueryBuilder(object):
|
||||||
self._for_whom = who
|
self._for_whom = who
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
def usage_on_types(self, usage_on_types):
|
||||||
|
self._usage_on_types = usage_on_types
|
||||||
|
return self
|
||||||
|
|
||||||
def as_who(self, target_roles):
|
def as_who(self, target_roles):
|
||||||
self._as_who = target_roles
|
self._as_who = target_roles
|
||||||
return self
|
return self
|
||||||
|
@ -893,14 +908,16 @@ class QueryBuilder(object):
|
||||||
obj,
|
obj,
|
||||||
self._for_whom))
|
self._for_whom))
|
||||||
self.add_grant_option()
|
self.add_grant_option()
|
||||||
if self._as_who:
|
|
||||||
self.query.append(
|
if self._usage_on_types:
|
||||||
'ALTER DEFAULT PRIVILEGES FOR ROLE {0} IN SCHEMA {1} GRANT USAGE ON TYPES TO {2}'.format(self._as_who,
|
if self._as_who:
|
||||||
self._schema,
|
self.query.append(
|
||||||
self._for_whom))
|
'ALTER DEFAULT PRIVILEGES FOR ROLE {0} IN SCHEMA {1} GRANT USAGE ON TYPES TO {2}'.format(self._as_who,
|
||||||
else:
|
self._schema,
|
||||||
self.query.append(
|
self._for_whom))
|
||||||
'ALTER DEFAULT PRIVILEGES IN SCHEMA {0} GRANT USAGE ON TYPES TO {1}'.format(self._schema, self._for_whom))
|
else:
|
||||||
|
self.query.append(
|
||||||
|
'ALTER DEFAULT PRIVILEGES IN SCHEMA {0} GRANT USAGE ON TYPES TO {1}'.format(self._schema, self._for_whom))
|
||||||
self.add_grant_option()
|
self.add_grant_option()
|
||||||
|
|
||||||
def build_present(self):
|
def build_present(self):
|
||||||
|
@ -960,6 +977,7 @@ def main():
|
||||||
password=dict(default='', aliases=['login_password'], no_log=True),
|
password=dict(default='', aliases=['login_password'], no_log=True),
|
||||||
fail_on_role=dict(type='bool', default=True),
|
fail_on_role=dict(type='bool', default=True),
|
||||||
trust_input=dict(type='bool', default=True),
|
trust_input=dict(type='bool', default=True),
|
||||||
|
usage_on_types=dict(type='bool', default=True),
|
||||||
)
|
)
|
||||||
|
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
|
@ -968,6 +986,7 @@ def main():
|
||||||
)
|
)
|
||||||
|
|
||||||
fail_on_role = module.params['fail_on_role']
|
fail_on_role = module.params['fail_on_role']
|
||||||
|
usage_on_types = module.params['usage_on_types']
|
||||||
|
|
||||||
# Create type object as namespace for module params
|
# Create type object as namespace for module params
|
||||||
p = type('Params', (), module.params)
|
p = type('Params', (), module.params)
|
||||||
|
@ -1092,6 +1111,7 @@ def main():
|
||||||
grant_option=p.grant_option,
|
grant_option=p.grant_option,
|
||||||
schema_qualifier=p.schema,
|
schema_qualifier=p.schema,
|
||||||
fail_on_role=fail_on_role,
|
fail_on_role=fail_on_role,
|
||||||
|
usage_on_types=usage_on_types,
|
||||||
)
|
)
|
||||||
|
|
||||||
except Error as e:
|
except Error as e:
|
||||||
|
|
|
@ -71,6 +71,7 @@
|
||||||
that:
|
that:
|
||||||
- result is changed
|
- result is changed
|
||||||
|
|
||||||
|
# Also covers https://github.com/ansible-collections/community.general/issues/884
|
||||||
- name: Set table default privs on the schema with hyphen in the name
|
- name: Set table default privs on the schema with hyphen in the name
|
||||||
postgresql_privs:
|
postgresql_privs:
|
||||||
login_user: "{{ pg_user }}"
|
login_user: "{{ pg_user }}"
|
||||||
|
@ -82,11 +83,34 @@
|
||||||
obj: TABLES
|
obj: TABLES
|
||||||
privs: all
|
privs: all
|
||||||
state: present
|
state: present
|
||||||
|
usage_on_types: yes
|
||||||
|
register: result
|
||||||
|
check_mode: yes
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- result is changed
|
||||||
|
- result.queries is search('ON TYPES')
|
||||||
|
|
||||||
|
# Also covers https://github.com/ansible-collections/community.general/issues/884
|
||||||
|
- name: Set table default privs on the schema with hyphen in the name
|
||||||
|
postgresql_privs:
|
||||||
|
login_user: "{{ pg_user }}"
|
||||||
|
password: password
|
||||||
|
db: "{{ db_name_with_hyphens }}"
|
||||||
|
schema: "{{ db_schema_with_hyphens }}"
|
||||||
|
role: "{{ db_user_with_hyphens }}"
|
||||||
|
type: default_privs
|
||||||
|
obj: TABLES
|
||||||
|
privs: all
|
||||||
|
state: present
|
||||||
|
usage_on_types: no
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result is changed
|
- result is changed
|
||||||
|
- result.queries is not search('ON TYPES')
|
||||||
|
|
||||||
- name: Delete table default privs on the schema with hyphen in the name
|
- name: Delete table default privs on the schema with hyphen in the name
|
||||||
postgresql_privs:
|
postgresql_privs:
|
||||||
|
|
Loading…
Reference in a new issue