def post(self, uuid=None, perimeter_id=None, user_id=None): """Create or update a subject. :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 subject", "description": "description of the subject", "password": "******", "email": "email address of the subject" } :return: { "subject_id": { "name": "name of the subject", "keystone_id": "keystone id of the subject", "description": "description of the subject", "password": "******", "email": "email address of the subject" } } :internal_api: set_subject """ try: if not perimeter_id: data = PolicyManager.get_subjects(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_subject(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 {"subjects": data}
def get(self, uuid=None, perimeter_id=None, user_id=None): """Retrieve all subjects 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 subject :param user_id: user ID who do the request :return: { "subject_id": { "name": "name of the subject", "keystone_id": "keystone id of the subject", "description": "a description (optional)" } } :internal_api: get_subjects """ data = PolicyManager.get_subjects(user_id=user_id, policy_id=uuid, perimeter_id=perimeter_id) return {"subjects": data}
def get(self, uuid=None, perimeter_id=None, user_id=None): """Retrieve all subjects 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 subject :param user_id: user ID who do the request :return: { "subject_id": { "name": "name of the subject", "keystone_id": "keystone id of the subject", "description": "a description" } } :internal_api: get_subjects """ try: data = PolicyManager.get_subjects(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 {"subjects": data}
def get_subjects(policy_id, perimeter_id=None): from python_moondb.core import PolicyManager return PolicyManager.get_subjects("", policy_id, perimeter_id)