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}
def post(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 (mandatory)", "object_description": "description of the object (optional)" } :return: { "object_id": { "name": "name of the object", "description": "description of the object (optional)" } } :internal_api: set_object """ data = PolicyManager.add_object(user_id=user_id, policy_id=uuid, perimeter_id=perimeter_id, value=request.json) return {"objects": data}
def add_object(policy_id, perimeter_id=None, value=None): from python_moondb.core import PolicyManager return PolicyManager.add_object("", policy_id, perimeter_id, value)