| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
# Copyright (c) 2021, Red Hat |
| 5 |
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 6 |
|
| 7 |
from __future__ import absolute_import, division, print_function |
| 8 |
|
| 9 |
__metaclass__ = type |
| 10 |
|
| 11 |
# STARTREMOVE (downstream) |
| 12 |
DOCUMENTATION = r""" |
| 13 |
|
| 14 |
module: openshift_adm_prune_auth |
| 15 |
|
| 16 |
short_description: Removes references to the specified roles, clusterroles, users, and groups |
| 17 |
|
| 18 |
version_added: "2.2.0" |
| 19 |
|
| 20 |
author: |
| 21 |
- Aubin Bikouo (@abikouo) |
| 22 |
|
| 23 |
description: |
| 24 |
- This module allow administrators to remove references to the specified roles, clusterroles, users, and groups. |
| 25 |
- Analogous to C(oc adm prune auth). |
| 26 |
|
| 27 |
extends_documentation_fragment: |
| 28 |
- kubernetes.core.k8s_auth_options |
| 29 |
|
| 30 |
options: |
| 31 |
resource: |
| 32 |
description: |
| 33 |
- The specified resource to remove. |
| 34 |
choices: |
| 35 |
- roles |
| 36 |
- clusterroles |
| 37 |
- users |
| 38 |
- groups |
| 39 |
type: str |
| 40 |
required: True |
| 41 |
name: |
| 42 |
description: |
| 43 |
- Use to specify an object name to remove. |
| 44 |
- Mutually exclusive with option I(label_selectors). |
| 45 |
- If neither I(name) nor I(label_selectors) are specified, prune all resources in the namespace. |
| 46 |
type: str |
| 47 |
namespace: |
| 48 |
description: |
| 49 |
- Use to specify an object namespace. |
| 50 |
- Ignored when I(resource) is set to C(clusterroles). |
| 51 |
type: str |
| 52 |
label_selectors: |
| 53 |
description: |
| 54 |
- Selector (label query) to filter on. |
| 55 |
- Mutually exclusive with option I(name). |
| 56 |
type: list |
| 57 |
elements: str |
| 58 |
|
| 59 |
requirements: |
| 60 |
- python >= 3.6 |
| 61 |
- kubernetes >= 12.0.0 |
| 62 |
""" |
| 63 |
|
| 64 |
EXAMPLES = r""" |
| 65 |
- name: Prune all roles from default namespace |
| 66 |
openshift_adm_prune_auth: |
| 67 |
resource: roles |
| 68 |
namespace: testing |
| 69 |
|
| 70 |
- name: Prune clusterroles using label selectors |
| 71 |
openshift_adm_prune_auth: |
| 72 |
resource: roles |
| 73 |
namespace: testing |
| 74 |
label_selectors: |
| 75 |
- phase=production |
| 76 |
""" |
| 77 |
|
| 78 |
|
| 79 |
RETURN = r""" |
| 80 |
cluster_role_binding: |
| 81 |
type: list |
| 82 |
description: list of cluster role binding deleted. |
| 83 |
returned: always |
| 84 |
role_binding: |
| 85 |
type: list |
| 86 |
description: list of role binding deleted. |
| 87 |
returned: I(resource=users) or I(resource=groups) or I(resource=clusterroles) |
| 88 |
security_context_constraints: |
| 89 |
type: list |
| 90 |
description: list of Security Context Constraints deleted. |
| 91 |
returned: I(resource=users) or I(resource=groups) |
| 92 |
authorization: |
| 93 |
type: list |
| 94 |
description: list of OAuthClientAuthorization deleted. |
| 95 |
returned: I(resource=users) |
| 96 |
group: |
| 97 |
type: list |
| 98 |
description: list of Security Context Constraints deleted. |
| 99 |
returned: I(resource=users) |
| 100 |
""" |
| 101 |
# ENDREMOVE (downstream) |
| 102 |
|
| 103 |
import copy |
| 104 |
|
| 105 |
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import ( |
| 106 |
AUTH_ARG_SPEC, |
| 107 |
) |
| 108 |
|
| 109 |
|
| 110 |
def argument_spec(): |
| 111 |
args = copy.deepcopy(AUTH_ARG_SPEC) |
| 112 |
args.update( |
| 113 |
dict( |
| 114 |
resource=dict( |
| 115 |
type="str", |
| 116 |
required=True, |
| 117 |
choices=["roles", "clusterroles", "users", "groups"], |
| 118 |
), |
| 119 |
namespace=dict(type="str"), |
| 120 |
name=dict(type="str"), |
| 121 |
label_selectors=dict(type="list", elements="str"), |
| 122 |
) |
| 123 |
) |
| 124 |
return args |
| 125 |
|
| 126 |
|
| 127 |
def main(): |
| 128 |
from ansible_collections.community.okd.plugins.module_utils.openshift_adm_prune_auth import ( |
| 129 |
OpenShiftAdmPruneAuth, |
| 130 |
) |
| 131 |
|
| 132 |
module = OpenShiftAdmPruneAuth( |
| 133 |
argument_spec=argument_spec(), |
| 134 |
mutually_exclusive=[("name", "label_selectors")], |
| 135 |
supports_check_mode=True, |
| 136 |
) |
| 137 |
module.run_module() |
| 138 |
|
| 139 |
|
| 140 |
if __name__ == "__main__": |
| 141 |
main() |