示例#1
0
文件: perimeter.py 项目: Kryndex/moon
    def patch(self, uuid=None, perimeter_id=None, user_id=None):
        """Create or update a object.

        :param uuid: uuid of the policy
        :param perimeter_id: must not be used here
        :param user_id: user ID who do the request
        :request body: {
            "object_name": "name of the object",
            "object_description": "description of the object"
        }
        :return: {
                "object_id": {
                    "name": "name of the object",
                    "description": "description of the object"
            }
        }
        :internal_api: set_object
        """
        try:
            data = PolicyManager.get_objects(user_id=user_id, policy_id=None)
            if 'name' in request.json:
                for data_id, data_value in data.items():
                    if data_value['name'] == request.json['name']:
                        perimeter_id = data_id
                        break
            data = PolicyManager.add_object(user_id=user_id,
                                            policy_id=uuid,
                                            perimeter_id=perimeter_id,
                                            value=request.json)
        except Exception as e:
            logger.error(e, exc_info=True)
            return {"result": False, "error": str(e)}, 500
        return {"objects": data}
示例#2
0
    def get(self, uuid=None, perimeter_id=None, user_id=None):
        """Retrieve all objects or a specific one if perimeter_id is
        given for a given policy

        :param uuid: uuid of the policy
        :param perimeter_id: uuid of the object
        :param user_id: user ID who do the request
        :return: {
                "object_id": {
                    "name": "name of the object",
                    "description": "description of the object (optional)"
            }
        }
        :internal_api: get_objects
        """

        data = PolicyManager.get_objects(user_id=user_id,
                                         policy_id=uuid,
                                         perimeter_id=perimeter_id)

        return {"objects": data}
示例#3
0
文件: perimeter.py 项目: Kryndex/moon
    def get(self, uuid=None, perimeter_id=None, user_id=None):
        """Retrieve all objects or a specific one if perimeter_id is
        given for a given policy

        :param uuid: uuid of the policy
        :param perimeter_id: uuid of the object
        :param user_id: user ID who do the request
        :return: {
                "object_id": {
                    "name": "name of the object",
                    "description": "description of the object"
            }
        }
        :internal_api: get_objects
        """
        try:
            data = PolicyManager.get_objects(user_id=user_id,
                                             policy_id=uuid,
                                             perimeter_id=perimeter_id)
        except Exception as e:
            logger.error(e, exc_info=True)
            return {"result": False, "error": str(e)}, 500
        return {"objects": data}
示例#4
0
文件: test_data.py 项目: Kryndex/moon
def get_objects(policy_id, perimeter_id=None):
    from python_moondb.core import PolicyManager
    return PolicyManager.get_objects("", policy_id, perimeter_id)