예제 #1
0
 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"
예제 #2
0
    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)
예제 #3
0
 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()
예제 #4
0
 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()
예제 #5
0
    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"
예제 #6
0
 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
예제 #7
0
 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)
예제 #8
0
 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
예제 #9
0
 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)
예제 #10
0
 def __init__(self, db, fs, msg):
     BaseTopic.__init__(self, db, fs, msg)
예제 #11
0
 def format_on_new(content, project_id=None, make_public=False):
     BaseTopic.format_on_new(content, None)
     content["_id"] = content["name"]