def patch(self, uuid, user_id=None): """Update a pdp :param uuid: uuid of the pdp to update :param user_id: user ID who do the request :return: { "pdp_id1": { "name": "name of the PDP", "security_pipeline": ["may be empty"], "keystone_project_id": "keystone_project_id1 (may be empty)", "description": "description of the PDP (optional)", } } :internal_api: update_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.update_pdp( user_id=user_id, pdp_id=uuid, value=_data) logger.debug("data={}".format(data)) logger.debug("uuid={}".format(uuid)) add_pod(uuid=uuid, data=data[uuid]) return {"pdps": data}
def patch(self, uuid=None, user_id=None): """Update a pdp :param uuid: uuid of the pdp to update :param user_id: user ID who do the request :return: { "pdp_id1": { "name": "...", "security_pipeline": [...], "keystone_project_id": "keystone_project_id1", "description": "...", } } :internal_api: update_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.update_pdp(user_id=user_id, pdp_id=uuid, value=_data) 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}
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)
def update_pdp(pdp_id, value): from python_moondb.core import PDPManager return PDPManager.update_pdp("", pdp_id, value)