Skip to content

Commit a9a0e53

Browse files
authored
330 organization permissions info implemented + tests added (#333)
330 organization permissions info implemented + tests added Reviewed-by: Anton Sidelnikov
1 parent b05be0d commit a9a0e53

File tree

8 files changed

+193
-2
lines changed

8 files changed

+193
-2
lines changed

doc/source/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Opentelekomcloud.Cloud
22
======================
33

4-
Collection version 0.14.1
4+
Collection version 0.14.2
55

66

77

doc/source/swr.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ Software Repository for Containers (SWR) Modules
1313
swr_repository_permissions <swr_repository_permissions_module>
1414
swr_repository_permissions_info <swr_repository_permissions_info_module>
1515
swr_organization_permissions <swr_organization_permissions_module>
16+
swr_organization_permissions_info <swr_organization_permissions_info_module>

galaxy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace: opentelekomcloud
22
name: cloud
3-
version: 0.14.1
3+
version: 0.14.2
44
readme: README.md
55
authors:
66
- Artem Goncharov <[email protected]>

meta/runtime.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,4 @@ action_groups:
9999
- swr_repository_permissions.py
100100
- swr_repository_permissions_info.py
101101
- swr_organization_permissions.py
102+
- swr_organization_permissions_info.py
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#!/usr/bin/python
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
14+
DOCUMENTATION = '''
15+
---
16+
module: swr_organization_permissions_info
17+
short_description: Get SWR organization permissions info
18+
extends_documentation_fragment: opentelekomcloud.cloud.otc
19+
version_added: "0.14.2"
20+
author: "Ziukina Valeriia (@RusselSand)"
21+
description:
22+
- Get repository permissions info from Software Repository for Containers
23+
options:
24+
namespace:
25+
description:
26+
- Mandatory name of an organisation
27+
type: str
28+
required: true
29+
user_name:
30+
description:
31+
- Optional user name
32+
type: str
33+
requirements: ["openstacksdk", "otcextensions"]
34+
'''
35+
36+
RETURN = '''
37+
permissions:
38+
description: Dictionary describing permissions
39+
type: complex
40+
returned: On Success.
41+
contains:
42+
namespace:
43+
description: Name of organization.
44+
type: str
45+
user_id:
46+
description: User ID
47+
type: str
48+
user_name:
49+
description: Username
50+
type: str
51+
user_auth:
52+
description: User permission (7 — manage, 3 — write, 1 — read)
53+
type: int
54+
self_auth:
55+
description: Check if this permission is for user who is making request
56+
type: bool
57+
'''
58+
59+
EXAMPLES = '''
60+
# Get SWR repository permissions information
61+
- opentelekomcloud.cloud.swr_organization_permissions_info:
62+
namespace: org_name
63+
register: swr_organization_permissions
64+
'''
65+
66+
from ansible_collections.opentelekomcloud.cloud.plugins.module_utils.otc import OTCModule
67+
68+
69+
class SwrOrgPermissionInfoModule(OTCModule):
70+
argument_spec = dict(
71+
namespace=dict(required=True),
72+
user_name=dict(required=False)
73+
)
74+
module_kwargs = dict(
75+
supports_check_mode=True
76+
)
77+
78+
def run(self):
79+
permissions = self.conn.swr.organization_permissions(namespace=self.params['namespace'])
80+
all_auth = list()
81+
for permission in permissions:
82+
permission_dict = {'namespace': permission['namespace'],
83+
'user_id': permission['self_auth']['user_id'],
84+
'user_name': permission['self_auth']['user_name'],
85+
'user_auth': permission['self_auth']['auth'],
86+
'self_auth': True}
87+
all_auth.append(permission_dict)
88+
for other_permission in permission['others_auths']:
89+
permission_dict = {'namespace': permission['namespace'],
90+
'user_id': other_permission['user_id'],
91+
'user_name': other_permission['user_name'],
92+
'user_auth': other_permission['auth'],
93+
'self_auth': False}
94+
all_auth.append(permission_dict)
95+
if self.params['user_name']:
96+
all_auth = list(filter(lambda x: x['user_name'] == self.params['user_name'], all_auth))
97+
self.exit_json(
98+
changed=False,
99+
permissions=all_auth
100+
)
101+
102+
103+
def main():
104+
module = SwrOrgPermissionInfoModule()
105+
module()
106+
107+
108+
if __name__ == "__main__":
109+
main()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
swr/group1
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
- name: SWR organization permissions tests
3+
module_defaults:
4+
opentelekomcloud.cloud.swr_organization_permissions_info:
5+
cloud: "{{ test_cloud }}"
6+
block:
7+
- name: Set random prefix
8+
ansible.builtin.set_fact:
9+
prefix: "{{ 99999999 | random | to_uuid | hash('md5') }}"
10+
11+
- name: Set initial facts
12+
ansible.builtin.set_fact:
13+
organization_name: "{{ ( 'org_' + prefix) }}"
14+
user_id: "cfe93b289ece46cd84a22b17c4e6671e"
15+
user_name: "test_user"
16+
17+
- name: Create organization
18+
opentelekomcloud.cloud.swr_organization:
19+
namespace: "{{ organization_name }}"
20+
register: organization
21+
22+
- name: Assert result
23+
ansible.builtin.assert:
24+
that:
25+
- organization is success
26+
27+
- name: Create user permission in this repository
28+
opentelekomcloud.cloud.swr_organization_permissions:
29+
namespace: "{{ organization_name }}"
30+
user_id: "{{ user_id }}"
31+
user_name: "{{ user_name }}"
32+
user_auth: 7
33+
register: permission
34+
35+
- name: Assert result
36+
ansible.builtin.assert:
37+
that:
38+
- permission is success
39+
40+
- name: List user permissions
41+
opentelekomcloud.cloud.swr_organization_permissions_info:
42+
namespace: "{{ organization_name }}"
43+
register: permissions
44+
45+
- name: Assert result
46+
ansible.builtin.assert:
47+
that:
48+
- permissions is success
49+
50+
- name: Get existing user permission
51+
opentelekomcloud.cloud.swr_organization_permissions_info:
52+
namespace: "{{ organization_name }}"
53+
user_name: "{{ user_name }}"
54+
register: permissions
55+
56+
- name: Assert result
57+
ansible.builtin.assert:
58+
that:
59+
- permissions is success
60+
61+
- name: Get existing user permission
62+
opentelekomcloud.cloud.swr_organization_permissions_info:
63+
namespace: "{{ organization_name }}"
64+
user_name: "non_existing_user"
65+
register: permissions
66+
67+
- name: Assert result
68+
ansible.builtin.assert:
69+
that:
70+
- permissions is success
71+
72+
always:
73+
74+
- name: Delete organization
75+
opentelekomcloud.cloud.swr_organization:
76+
namespace: "{{ organization_name }}"
77+
state: absent
78+
failed_when: false

tests/sanity/ignore.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,4 @@ plugins/modules/swr_domain.py validate-modules:missing-gplv3-license
115115
plugins/modules/swr_repository_permissions.py validate-modules:missing-gplv3-license
116116
plugins/modules/swr_repository_permissions_info.py validate-modules:missing-gplv3-license
117117
plugins/modules/swr_organization_permissions.py validate-modules:missing-gplv3-license
118+
plugins/modules/swr_organization_permissions_info.py validate-modules:missing-gplv3-license

0 commit comments

Comments
 (0)