コード例 #1
0
    def post(self, uuid=None, perimeter_id=None, category_id=None,
             data_id=None, user_id=None):
        """Create a subject assignment.

        :param uuid: uuid of the policy
        :param perimeter_id: uuid of the subject (not used here)
        :param category_id: uuid of the subject category (not used here)
        :param data_id: uuid of the subject scope (not used here)
        :param user_id: user ID who do the request
        :request body: {
            "id": "UUID of the subject",
            "category_id": "UUID of the category"
            "data_id": "UUID of the scope"
        }
        :return: {
            "subject_data_id": {
                "policy_id": "ID of the policy",
                "subject_id": "ID of the subject",
                "category_id": "ID of the category",
                "assignments": "Assignments list (list of data_id)",
            }
        }
        :internal_api: update_subject_assignment
        """
        try:
            data_id = request.json.get("data_id")
            category_id = request.json.get("category_id")
            perimeter_id = request.json.get("id")
            data = PolicyManager.add_subject_assignment(
                user_id=user_id, policy_id=uuid,
                subject_id=perimeter_id, category_id=category_id,
                data_id=data_id)
        except Exception as e:
            logger.error(e, exc_info=True)
            return {"result": False,
                    "error": str(e)}, 500
        return {"subject_assignments": data}
コード例 #2
0
def add_subject_assignment(policy_id, subject_id, category_id, data_id):
    from python_moondb.core import PolicyManager
    return PolicyManager.add_subject_assignment("", policy_id, subject_id,
                                                category_id, data_id)