Example #1
0
def instance_hook(self, input, instance, attrs):

    if attrs.is_create_edit:

        cluster_id = self.server.cluster_id

        with closing(self.odb.session()) as session:

            role = rbac_role(session, cluster_id, input.role_id,
                             input.role_name)
            _service = service(session, cluster_id, input.service_id,
                               input.service_name)
            perm = rbac_permission(session, cluster_id, input.perm_id,
                                   input.perm_name)

            instance.role_id = role.id
            instance.service_id = _service.id
            instance.perm_id = perm.id

            input.role_id = role.id
            input.service_id = _service.id
            input.perm_id = perm.id

        instance.name = '{}:::{}::{}'.format(role.name, _service.name,
                                             perm.name)
Example #2
0
def response_hook(self, input, instance, attrs, service_type):

    if service_type == 'get_list':
        for item in self.response.payload:

            item_name, role_name, service_name, perm_name = get_extra(
                self, item.role_id, item.service_id, item.perm_id)

            item.name = item_name
            item.role_name = role_name
            item.service_name = service_name
            item.perm_name = perm_name

    elif service_type == 'create_edit':

        cluster_id = self.server.cluster_id

        with closing(self.odb.session()) as session:

            role = rbac_role(session, cluster_id, input.role_id,
                             input.role_name)
            _service = service(session, cluster_id, input.service_id,
                               input.service_name)
            perm = rbac_permission(session, cluster_id, input.perm_id,
                                   input.perm_name)

        self.response.payload.role_name = role.name
        self.response.payload.service_name = _service.name
        self.response.payload.perm_name = perm.name
Example #3
0
def instance_hook(self, input, instance, attrs):
    # type: (Service, Bunch, RBACClientRole, Bunch)

    if attrs.is_create_edit:
        with closing(self.odb.session()) as session:
            role = rbac_role(session, self.server.cluster_id, input.role_id, input.role_name)

        instance.role_id = role.id
        instance.name = '{}:::{}'.format(instance.client_def, role.name)
Example #4
0
def instance_hook(self, input, instance, attrs):

    if attrs.is_create_edit:
        is_root = input.name.lower() == 'root'

        if is_root:
            raise ValueError('Root role cannot be changed')

        with closing(self.odb.session()) as session:
            parent = rbac_role(session, self.server.cluster_id,
                               input.parent_id, input.parent_name)
            input.parent_id = parent.id

        if input.parent_id == instance.id:
            raise ValueError('A role cannot be its own parent')
        else:
            instance.parent_id = input.parent_id