Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable role mapping, new user / user groups creation, collaboration, vpcs and accounts in ntnx_projects #281

Merged
merged 16 commits into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
279 changes: 279 additions & 0 deletions plugins/module_utils/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,279 @@
# This file is part of Ansible
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function

__metaclass__ = type


class ACP:
class EntityFilterExpressionList:
PROJECT_ADMIN = [
{
"left_hand_side": {"entity_type": "image"},
"operator": "IN",
"right_hand_side": {"collection": "ALL"},
},
{
"left_hand_side": {"entity_type": "app_icon"},
"operator": "IN",
"right_hand_side": {"collection": "ALL"},
},
{
"left_hand_side": {"entity_type": "category"},
"operator": "IN",
"right_hand_side": {"collection": "ALL"},
},
{
"left_hand_side": {"entity_type": "environment"},
"operator": "IN",
"right_hand_side": {"collection": "SELF_OWNED"},
},
{
"left_hand_side": {"entity_type": "marketplace_item"},
"operator": "IN",
"right_hand_side": {"collection": "SELF_OWNED"},
},
{
"left_hand_side": {"entity_type": "user"},
"operator": "IN",
"right_hand_side": {"collection": "ALL"},
},
{
"left_hand_side": {"entity_type": "user_group"},
"operator": "IN",
"right_hand_side": {"collection": "ALL"},
},
{
"left_hand_side": {"entity_type": "role"},
"operator": "IN",
"right_hand_side": {"collection": "ALL"},
},
{
"left_hand_side": {"entity_type": "directory_service"},
"operator": "IN",
"right_hand_side": {"collection": "ALL"},
},
{
"left_hand_side": {"entity_type": "identity_provider"},
"operator": "IN",
"right_hand_side": {"collection": "ALL"},
},
{
"left_hand_side": {"entity_type": "app_task"},
"operator": "IN",
"right_hand_side": {"collection": "SELF_OWNED"},
},
{
"left_hand_side": {"entity_type": "app_variable"},
"operator": "IN",
"right_hand_side": {"collection": "SELF_OWNED"},
},
{
"left_hand_side": {"entity_type": "vm_recovery_point"},
"operator": "IN",
"right_hand_side": {"collection": "ALL"},
},
{
"left_hand_side": {"entity_type": "virtual_network"},
"operator": "IN",
"right_hand_side": {"collection": "ALL"},
},
]
DEVELOPER = [
{
"left_hand_side": {"entity_type": "image"},
"operator": "IN",
"right_hand_side": {"collection": "ALL"},
},
{
"left_hand_side": {"entity_type": "app_icon"},
"operator": "IN",
"right_hand_side": {"collection": "ALL"},
},
{
"left_hand_side": {"entity_type": "category"},
"operator": "IN",
"right_hand_side": {"collection": "ALL"},
},
{
"left_hand_side": {"entity_type": "environment"},
"operator": "IN",
"right_hand_side": {"collection": "SELF_OWNED"},
},
{
"left_hand_side": {"entity_type": "marketplace_item"},
"operator": "IN",
"right_hand_side": {"collection": "SELF_OWNED"},
},
{
"left_hand_side": {"entity_type": "app_task"},
"operator": "IN",
"right_hand_side": {"collection": "SELF_OWNED"},
},
{
"left_hand_side": {"entity_type": "app_variable"},
"operator": "IN",
"right_hand_side": {"collection": "SELF_OWNED"},
},
]
CONSUMER = [
{
"left_hand_side": {"entity_type": "image"},
"operator": "IN",
"right_hand_side": {"collection": "ALL"},
},
{
"left_hand_side": {"entity_type": "app_icon"},
"operator": "IN",
"right_hand_side": {"collection": "ALL"},
},
{
"left_hand_side": {"entity_type": "category"},
"operator": "IN",
"right_hand_side": {"collection": "ALL"},
},
{
"left_hand_side": {"entity_type": "environment"},
"operator": "IN",
"right_hand_side": {"collection": "SELF_OWNED"},
},
{
"left_hand_side": {"entity_type": "marketplace_item"},
"operator": "IN",
"right_hand_side": {"collection": "SELF_OWNED"},
},
{
"left_hand_side": {"entity_type": "app_task"},
"operator": "IN",
"right_hand_side": {"collection": "SELF_OWNED"},
},
{
"left_hand_side": {"entity_type": "app_variable"},
"operator": "IN",
"right_hand_side": {"collection": "SELF_OWNED"},
},
{
"left_hand_side": {"entity_type": "vm_recovery_point"},
"operator": "IN",
"right_hand_side": {"collection": "ALL"},
},
{
"left_hand_side": {"entity_type": "virtual_network"},
"operator": "IN",
"right_hand_side": {"collection": "ALL"},
},
]
OPERATOR = [
{
"operator": "IN",
"right_hand_side": {"collection": "ALL"},
"left_hand_side": {"entity_type": "app_icon"},
},
{
"operator": "IN",
"right_hand_side": {"collection": "ALL"},
"left_hand_side": {"entity_type": "category"},
},
{
"operator": "IN",
"left_hand_side": {"entity_type": "vm_recovery_point"},
"right_hand_side": {"collection": "ALL"},
},
{
"operator": "IN",
"left_hand_side": {"entity_type": "virtual_network"},
"right_hand_side": {"collection": "ALL"},
},
]

DEFAULT = [
{
"operator": "IN",
"left_hand_side": {"entity_type": "blueprint"},
"right_hand_side": {"collection": "ALL"},
},
{
"operator": "IN",
"left_hand_side": {"entity_type": "environment"},
"right_hand_side": {"collection": "ALL"},
},
{
"operator": "IN",
"left_hand_side": {"entity_type": "marketplace_item"},
"right_hand_side": {"collection": "ALL"},
},
]

PERMISSION_TO_ACCESS_MAP = {
"View_Image": {
"operator": "IN",
"left_hand_side": {"entity_type": "image"},
"right_hand_side": {"collection": "ALL"},
},
"View_App_Icon": {
"operator": "IN",
"right_hand_side": {"collection": "ALL"},
"left_hand_side": {"entity_type": "app_icon"},
},
"View_Name_Category": {
"operator": "IN",
"right_hand_side": {"collection": "ALL"},
"left_hand_side": {"entity_type": "category"},
},
"Create_Or_Update_Name_Category": {
"operator": "IN",
"right_hand_side": {"collection": "ALL"},
"left_hand_side": {"entity_type": "category"},
},
"View_Environment": {
"operator": "IN",
"left_hand_side": {"entity_type": "environment"},
"right_hand_side": {"collection": "SELF_OWNED"},
},
"View_Marketplace_Item": {
"operator": "IN",
"left_hand_side": {"entity_type": "marketplace_item"},
"right_hand_side": {"collection": "SELF_OWNED"},
},
"View_User": {
"operator": "IN",
"right_hand_side": {"collection": "ALL"},
"left_hand_side": {"entity_type": "user"},
},
"View_User_Group": {
"operator": "IN",
"right_hand_side": {"collection": "ALL"},
"left_hand_side": {"entity_type": "user_group"},
},
"View_Role": {
"operator": "IN",
"right_hand_side": {"collection": "ALL"},
"left_hand_side": {"entity_type": "role"},
},
"View_Directory_Service": {
"operator": "IN",
"right_hand_side": {"collection": "ALL"},
"left_hand_side": {"entity_type": "directory_service"},
},
"Search_Sirectory_Service": {
"operator": "IN",
"right_hand_side": {"collection": "ALL"},
"left_hand_side": {"entity_type": "directory_service"},
},
"View_Identity_Provider": {
"operator": "IN",
"right_hand_side": {"collection": "ALL"},
"left_hand_side": {"entity_type": "identity_provider"},
},
"View_App_Task": {
"operator": "IN",
"left_hand_side": {"entity_type": "app_task"},
"right_hand_side": {"collection": "SELF_OWNED"},
},
"View_App_Variable": {
"operator": "IN",
"left_hand_side": {"entity_type": "app_variable"},
"right_hand_side": {"collection": "SELF_OWNED"},
},
}
23 changes: 20 additions & 3 deletions plugins/module_utils/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,17 @@ def list(

return resp

def get_spec(self, old_spec=None):
# "params" can be used to override module.params to create spec by other modules backened
def get_spec(self, old_spec=None, params=None):
spec = copy.deepcopy(old_spec) or self._get_default_spec()
for ansible_param, ansible_config in self.module.params.items():

ansible_params = None
if params:
ansible_params = params
else:
ansible_params = self.module.params

for ansible_param, ansible_config in ansible_params.items():
build_spec_method = self.build_spec_methods.get(ansible_param)
if build_spec_method and ansible_config:
spec, error = build_spec_method(spec, ansible_config)
Expand All @@ -236,7 +244,16 @@ def get_uuid(
entities = resp.get("entities") if resp else None
if entities:
for entity in entities:
if entity["spec"]["name"] == value:

name = ""
if entity.get("spec", {}).get("name"):
name = entity["spec"]["name"]
elif entity.get("status", {}).get("name"):
name = entity["status"]["name"]
else:
continue

if name == value:
return entity["metadata"]["uuid"]
return None

Expand Down
40 changes: 40 additions & 0 deletions plugins/module_utils/prism/accounts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This file is part of Ansible
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function

__metaclass__ = type

from .prism import Prism


class Account(Prism):
kind = "account"

def __init__(self, module):
resource_type = "/accounts"
super(Account, self).__init__(module, resource_type=resource_type)

@classmethod
def build_account_reference_spec(cls, uuid):
spec = {"kind": cls.kind, "uuid": uuid}
return spec


# Helper functions


def get_account_uuid(config, module):
if "name" in config:
accounts = Account(module)
name = config["name"]
uuid = accounts.get_uuid(name)
if not uuid:
error = "Account {0} not found.".format(name)
return None, error
elif "uuid" in config:
uuid = config["uuid"]
else:
error = "Config {0} doesn't have name or uuid key".format(config)
return None, error

return uuid, None
Loading