Ejemplo n.º 1
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
Ejemplo n.º 2
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)