def patch(self, uuid=None, perimeter_id=None, user_id=None): """Create or update a action. :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: { "name": "name of the action", "description": "description of the action" } :return: { "action_id": { "name": "name of the action", "description": "description of the action" } } :internal_api: set_action """ try: data = PolicyManager.get_actions(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_action(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 {"actions": data}
def post(self, uuid=None, perimeter_id=None, user_id=None): """Create or update a action. :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: { "name": "name of the action (mandatory)", "description": "description of the action (optional)" } :return: { "action_id": { "name": "name of the action", "description": "description of the action (optional)" } } :internal_api: set_action """ data = PolicyManager.add_action(user_id=user_id, policy_id=uuid, perimeter_id=perimeter_id, value=request.json) return {"actions": data}
def add_action(policy_id, perimeter_id=None, value=None): from python_moondb.core import PolicyManager return PolicyManager.add_action("", policy_id, perimeter_id, value)