diff --git a/doc/source/index.rst b/doc/source/index.rst index 57d07ba6..d719dead 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -1,7 +1,7 @@ Opentelekomcloud.Cloud ====================== -Collection version 0.14.1 +Collection version 0.14.2 diff --git a/doc/source/swr.rst b/doc/source/swr.rst index e60015b5..db420afc 100644 --- a/doc/source/swr.rst +++ b/doc/source/swr.rst @@ -13,3 +13,4 @@ Software Repository for Containers (SWR) Modules swr_repository_permissions swr_repository_permissions_info swr_organization_permissions + swr_organization_permissions_info diff --git a/galaxy.yml b/galaxy.yml index d7a08f89..e5e6e247 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -1,6 +1,6 @@ namespace: opentelekomcloud name: cloud -version: 0.14.1 +version: 0.14.2 readme: README.md authors: - Artem Goncharov diff --git a/meta/runtime.yml b/meta/runtime.yml index c7b03bfa..0d3cb59c 100644 --- a/meta/runtime.yml +++ b/meta/runtime.yml @@ -99,3 +99,4 @@ action_groups: - swr_repository_permissions.py - swr_repository_permissions_info.py - swr_organization_permissions.py + - swr_organization_permissions_info.py diff --git a/plugins/modules/swr_organization_permissions_info.py b/plugins/modules/swr_organization_permissions_info.py new file mode 100644 index 00000000..fc653061 --- /dev/null +++ b/plugins/modules/swr_organization_permissions_info.py @@ -0,0 +1,109 @@ +#!/usr/bin/python +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +DOCUMENTATION = ''' +--- +module: swr_organization_permissions_info +short_description: Get SWR organization permissions info +extends_documentation_fragment: opentelekomcloud.cloud.otc +version_added: "0.14.2" +author: "Ziukina Valeriia (@RusselSand)" +description: + - Get repository permissions info from Software Repository for Containers +options: + namespace: + description: + - Mandatory name of an organisation + type: str + required: true + user_name: + description: + - Optional user name + type: str +requirements: ["openstacksdk", "otcextensions"] +''' + +RETURN = ''' +permissions: + description: Dictionary describing permissions + type: complex + returned: On Success. + contains: + namespace: + description: Name of organization. + type: str + user_id: + description: User ID + type: str + user_name: + description: Username + type: str + user_auth: + description: User permission (7 — manage, 3 — write, 1 — read) + type: int + self_auth: + description: Check if this permission is for user who is making request + type: bool +''' + +EXAMPLES = ''' +# Get SWR repository permissions information +- opentelekomcloud.cloud.swr_organization_permissions_info: + namespace: org_name + register: swr_organization_permissions +''' + +from ansible_collections.opentelekomcloud.cloud.plugins.module_utils.otc import OTCModule + + +class SwrOrgPermissionInfoModule(OTCModule): + argument_spec = dict( + namespace=dict(required=True), + user_name=dict(required=False) + ) + module_kwargs = dict( + supports_check_mode=True + ) + + def run(self): + permissions = self.conn.swr.organization_permissions(namespace=self.params['namespace']) + all_auth = list() + for permission in permissions: + permission_dict = {'namespace': permission['namespace'], + 'user_id': permission['self_auth']['user_id'], + 'user_name': permission['self_auth']['user_name'], + 'user_auth': permission['self_auth']['auth'], + 'self_auth': True} + all_auth.append(permission_dict) + for other_permission in permission['others_auths']: + permission_dict = {'namespace': permission['namespace'], + 'user_id': other_permission['user_id'], + 'user_name': other_permission['user_name'], + 'user_auth': other_permission['auth'], + 'self_auth': False} + all_auth.append(permission_dict) + if self.params['user_name']: + all_auth = list(filter(lambda x: x['user_name'] == self.params['user_name'], all_auth)) + self.exit_json( + changed=False, + permissions=all_auth + ) + + +def main(): + module = SwrOrgPermissionInfoModule() + module() + + +if __name__ == "__main__": + main() diff --git a/tests/integration/targets/swr_organization_permissions_info/aliases b/tests/integration/targets/swr_organization_permissions_info/aliases new file mode 100644 index 00000000..f19d16f5 --- /dev/null +++ b/tests/integration/targets/swr_organization_permissions_info/aliases @@ -0,0 +1 @@ +swr/group1 diff --git a/tests/integration/targets/swr_organization_permissions_info/tasks/main.yaml b/tests/integration/targets/swr_organization_permissions_info/tasks/main.yaml new file mode 100644 index 00000000..2adcbacb --- /dev/null +++ b/tests/integration/targets/swr_organization_permissions_info/tasks/main.yaml @@ -0,0 +1,78 @@ +--- +- name: SWR organization permissions tests + module_defaults: + opentelekomcloud.cloud.swr_organization_permissions_info: + cloud: "{{ test_cloud }}" + block: + - name: Set random prefix + ansible.builtin.set_fact: + prefix: "{{ 99999999 | random | to_uuid | hash('md5') }}" + + - name: Set initial facts + ansible.builtin.set_fact: + organization_name: "{{ ( 'org_' + prefix) }}" + user_id: "cfe93b289ece46cd84a22b17c4e6671e" + user_name: "test_user" + + - name: Create organization + opentelekomcloud.cloud.swr_organization: + namespace: "{{ organization_name }}" + register: organization + + - name: Assert result + ansible.builtin.assert: + that: + - organization is success + + - name: Create user permission in this repository + opentelekomcloud.cloud.swr_organization_permissions: + namespace: "{{ organization_name }}" + user_id: "{{ user_id }}" + user_name: "{{ user_name }}" + user_auth: 7 + register: permission + + - name: Assert result + ansible.builtin.assert: + that: + - permission is success + + - name: List user permissions + opentelekomcloud.cloud.swr_organization_permissions_info: + namespace: "{{ organization_name }}" + register: permissions + + - name: Assert result + ansible.builtin.assert: + that: + - permissions is success + + - name: Get existing user permission + opentelekomcloud.cloud.swr_organization_permissions_info: + namespace: "{{ organization_name }}" + user_name: "{{ user_name }}" + register: permissions + + - name: Assert result + ansible.builtin.assert: + that: + - permissions is success + + - name: Get existing user permission + opentelekomcloud.cloud.swr_organization_permissions_info: + namespace: "{{ organization_name }}" + user_name: "non_existing_user" + register: permissions + + - name: Assert result + ansible.builtin.assert: + that: + - permissions is success + + always: + + - name: Delete organization + opentelekomcloud.cloud.swr_organization: + namespace: "{{ organization_name }}" + state: absent + failed_when: false diff --git a/tests/sanity/ignore.txt b/tests/sanity/ignore.txt index 119d187f..ba8b7029 100644 --- a/tests/sanity/ignore.txt +++ b/tests/sanity/ignore.txt @@ -115,3 +115,4 @@ plugins/modules/swr_domain.py validate-modules:missing-gplv3-license plugins/modules/swr_repository_permissions.py validate-modules:missing-gplv3-license plugins/modules/swr_repository_permissions_info.py validate-modules:missing-gplv3-license plugins/modules/swr_organization_permissions.py validate-modules:missing-gplv3-license +plugins/modules/swr_organization_permissions_info.py validate-modules:missing-gplv3-license