Example #1
0
    def _import_pdps(self, json_pdps):
        if not isinstance(json_pdps, list):
            raise InvalidJson("pdps shall be a list!")

        for json_pdp in json_pdps:
            json_to_use = dict()
            JsonUtils.copy_field_if_exists(json_pdp, json_to_use, "name", str)
            JsonUtils.copy_field_if_exists(json_pdp, json_to_use,
                                           "keystone_project_id", str)
            JsonUtils.copy_field_if_exists(json_pdp, json_to_use,
                                           "security_pipeline", list)
            JsonUtils.copy_field_if_exists(json_pdp, json_to_use,
                                           "description", str)

            pdps = PDPManager.get_pdp(self._user_id)
            exists = False
            for pdp_key in pdps:
                if pdps[pdp_key]["name"] == json_to_use["name"]:
                    PDPManager.update_pdp(self._user_id,
                                          pdp_id=pdp_key,
                                          value=json_to_use)
                    exists = True
            if exists is False:
                PDPManager.add_pdp(self._user_id, value=json_to_use)
Example #2
0
File: pdp.py Project: Kryndex/moon
    def post(self, uuid=None, user_id=None):
        """Create pdp.

        :param uuid: uuid of the pdp (not used here)
        :param user_id: user ID who do the request
        :request body: {
            "name": "...",
            "security_pipeline": [...],
            "keystone_project_id": "keystone_project_id1",
            "description": "...",
        }
        :return: {
            "pdp_id1": {
                "name": "...",
                "security_pipeline": [...],
                "keystone_project_id": "keystone_project_id1",
                "description": "...",
            }
        }
        :internal_api: add_pdp
        """
        try:
            data = dict(request.json)
            if not data.get("keystone_project_id"):
                data["keystone_project_id"] = None
            else:
                if check_keystone_pid(data.get("keystone_project_id")):
                    raise exceptions.PdpKeystoneMappingConflict
            data = PDPManager.add_pdp(user_id=user_id,
                                      pdp_id=None,
                                      value=request.json)
            uuid = list(data.keys())[0]
            logger.debug("data={}".format(data))
            logger.debug("uuid={}".format(uuid))
            add_pod(uuid=uuid, data=data[uuid])
        except Exception as e:
            logger.error(e, exc_info=True)
            return {"result": False, "error": str(e)}, 500
        return {"pdps": data}
Example #3
0
    def post(self, uuid=None, user_id=None):
        """Create pdp.

        :param uuid: uuid of the pdp (not used here)
        :param user_id: user ID who do the request
        :request body: {
            "name": "name of the PDP (mandatory)",
            "security_pipeline": ["may be empty"],
            "keystone_project_id": "keystone_project_id1 (may be empty)",
            "description": "description of the PDP (optional)",
        }
        :return: {
            "pdp_id1": {
                "name": "...",
                "security_pipeline": [...],
                "keystone_project_id": "keystone_project_id1",
                "description": "... (optional)",
            }
        }
        :internal_api: add_pdp
        """

        data = dict(request.json)
        if not data.get("keystone_project_id"):
            data["keystone_project_id"] = None
        else:
            if check_keystone_pid(data.get("keystone_project_id")):
                raise exceptions.PdpKeystoneMappingConflict
        data = PDPManager.add_pdp(
            user_id=user_id, pdp_id=None, value=request.json)
        uuid = list(data.keys())[0]
        logger.debug("data={}".format(data))
        logger.debug("uuid={}".format(uuid))
        add_pod(uuid=uuid, data=data[uuid])

        return {"pdps": data}
Example #4
0
def add_pdp(pdp_id=None, value=None):
    from python_moondb.core import PDPManager
    return PDPManager.add_pdp("", pdp_id, value)