def format_on_new(content, project_id=None, make_public=False): BaseTopic.format_on_new(content, project_id=project_id, make_public=make_public) content["_admin"]["onboardingState"] = "CREATED" content["_admin"]["operationalState"] = "DISABLED" content["_admin"]["usageState"] = "NOT_IN_USE"
def get_one_by_id(db, session, topic, id): # find owned by this project _filter = BaseTopic._get_project_filter(session, write=False, show_all=False) _filter["id"] = id desc_list = db.get_list(topic, _filter) if len(desc_list) == 1: return desc_list[0] elif len(desc_list) > 1: raise DbException( "Found more than one {} with id='{}' belonging to this project" .format(topic[:-1], id), HTTPStatus.CONFLICT) # not found any: try to find public _filter = BaseTopic._get_project_filter(session, write=False, show_all=True) _filter["id"] = id desc_list = db.get_list(topic, _filter) if not desc_list: raise DbException( "Not found any {} with id='{}'".format(topic[:-1], id), HTTPStatus.NOT_FOUND) elif len(desc_list) == 1: return desc_list[0] else: raise DbException( "Found more than one public {} with id='{}'; and no one belonging to this project" .format(topic[:-1], id), HTTPStatus.CONFLICT)
def format_on_edit(final_content, edit_content): BaseTopic.format_on_edit(final_content, edit_content) if edit_content.get("password"): salt = uuid4().hex final_content["_admin"]["salt"] = salt final_content["password"] = sha256( edit_content["password"].encode('utf-8') + salt.encode('utf-8')).hexdigest()
def format_on_new(content, project_id=None, make_public=False): BaseTopic.format_on_new(content, make_public=False) content["_id"] = content["username"] salt = uuid4().hex content["_admin"]["salt"] = salt if content.get("password"): content["password"] = sha256(content["password"].encode('utf-8') + salt.encode('utf-8')).hexdigest()
def format_on_new(self, content, project_id=None, make_public=False): BaseTopic.format_on_new(content, project_id=project_id, make_public=make_public) content["schema_version"] = schema_version = "1.1" # encrypt passwords if content.get("password"): content["password"] = self.db.encrypt( content["password"], schema_version=schema_version, salt=content["_id"]) content["_admin"]["operationalState"] = "PROCESSING"
def delete(self, session, _id, force=False, dry_run=False): """ Delete item by its internal _id :param session: contains the used login username, working project, and admin rights :param _id: server internal id :param force: indicates if deletion must be forced in case of conflict :param dry_run: make checking but do not delete :return: dictionary with deleted item _id. It raises EngineException on error: not found, conflict, ... """ if dry_run or force: # delete completely return BaseTopic.delete(self, session, _id, force, dry_run) else: # if not sent to kafka v = BaseTopic.delete(self, session, _id, force, dry_run=True) self.db.set_one("sdns", {"_id": _id}, {"_admin.to_delete": True}) # TODO change status self._send_msg("delete", {"_id": _id}) return v # TODO indicate an offline operation to return 202 ACCEPTED
def edit(self, session, _id, indata=None, kwargs=None, force=False, content=None): if not session["admin"]: raise EngineException("needed admin privileges", http_code=HTTPStatus.UNAUTHORIZED) return BaseTopic.edit(self, session, _id, indata=indata, kwargs=kwargs, force=force, content=content)
def delete(self, session, _id, force=False, dry_run=False): """ Delete item by its internal _id :param session: contains the used login username, working project, and admin rights :param _id: server internal id :param force: indicates if deletion must be forced in case of conflict :param dry_run: make checking but do not delete :return: dictionary with deleted item _id. It raises EngineException on error: not found, conflict, ... """ # TODO add admin to filter, validate rights v = BaseTopic.delete(self, session, _id, force, dry_run=True) if dry_run: return v = self.db.del_one(self.topic, {"_id": _id}) self.fs.file_delete(_id, ignore_non_exist=True) self.fs.file_delete(_id + "_", ignore_non_exist=True) # remove temp folder self._send_msg("delete", {"_id": _id}) return v
def new(self, rollback, session, indata=None, kwargs=None, headers=None, force=False, make_public=False): if not session["admin"]: raise EngineException("needed admin privileges", http_code=HTTPStatus.UNAUTHORIZED) return BaseTopic.new(self, rollback, session, indata=indata, kwargs=kwargs, headers=headers, force=force, make_public=make_public)
def __init__(self, db, fs, msg): BaseTopic.__init__(self, db, fs, msg)
def format_on_new(content, project_id=None, make_public=False): BaseTopic.format_on_new(content, None) content["_id"] = content["name"]