Esempio n. 1
0
    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 (mandatory)",
            "description": "description of the subject (optional)",
            "password": "******",
            "email": "email address of the subject (optional)"
        }
        :return: {
                "subject_id": {
                    "name": "name of the subject",
                    "keystone_id": "keystone id of the subject",
                    "description": "description of the subject (optional)",
                    "password": "******",
                    "email": "email address of the subject (optional)"
            }
        }
        :internal_api: set_subject
        """

        data = PolicyManager.add_subject(user_id=user_id,
                                         policy_id=uuid,
                                         perimeter_id=perimeter_id,
                                         value=request.json)

        return {"subjects": data}
Esempio n. 2
0
    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}
Esempio n. 3
0
def add_subject(policy_id, perimeter_id=None, value=None):
    from python_moondb.core import PolicyManager
    return PolicyManager.add_subject("", policy_id, perimeter_id, value)