-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
330 organization permissions info implemented + tests added (#333)
330 organization permissions info implemented + tests added Reviewed-by: Anton Sidelnikov
- Loading branch information
1 parent
b05be0d
commit a9a0e53
Showing
8 changed files
with
193 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
1 change: 1 addition & 0 deletions
1
tests/integration/targets/swr_organization_permissions_info/aliases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
swr/group1 |
78 changes: 78 additions & 0 deletions
78
tests/integration/targets/swr_organization_permissions_info/tasks/main.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters