Skip to content

Commit

Permalink
330 organization permissions info implemented + tests added (#333)
Browse files Browse the repository at this point in the history
330 organization permissions info implemented + tests added

Reviewed-by: Anton Sidelnikov
  • Loading branch information
RusselSand authored Mar 25, 2024
1 parent b05be0d commit a9a0e53
Show file tree
Hide file tree
Showing 8 changed files with 193 additions and 2 deletions.
2 changes: 1 addition & 1 deletion doc/source/index.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Opentelekomcloud.Cloud
======================

Collection version 0.14.1
Collection version 0.14.2



Expand Down
1 change: 1 addition & 0 deletions doc/source/swr.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ Software Repository for Containers (SWR) Modules
swr_repository_permissions <swr_repository_permissions_module>
swr_repository_permissions_info <swr_repository_permissions_info_module>
swr_organization_permissions <swr_organization_permissions_module>
swr_organization_permissions_info <swr_organization_permissions_info_module>
2 changes: 1 addition & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace: opentelekomcloud
name: cloud
version: 0.14.1
version: 0.14.2
readme: README.md
authors:
- Artem Goncharov <[email protected]>
Expand Down
1 change: 1 addition & 0 deletions meta/runtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,4 @@ action_groups:
- swr_repository_permissions.py
- swr_repository_permissions_info.py
- swr_organization_permissions.py
- swr_organization_permissions_info.py
109 changes: 109 additions & 0 deletions plugins/modules/swr_organization_permissions_info.py
Original file line number Diff line number Diff line change
@@ -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()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
swr/group1
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions tests/sanity/ignore.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a9a0e53

Please sign in to comment.