Exemplo n.º 1
0
    def updateAdmin(self, admin_id):
        """
        Update an existing admin in the system
        """

        postdata = cherrypy.request.json

        admin = Admin.getFromDict(postdata['admin'])

        admin.setId(admin_id)

        isCrypted = postdata['isCrypted'][0].lower() == 't' \
            if 'isCrypted' in postdata and postdata['isCrypted'] else False

        try:
            self.app.admin_api.updateAdmin(cherrypy.request.db, admin,
                                           isCrypted)

            response = None
        except Exception as ex:
            self._logger.error(str(ex))
            self.handleException(ex)
            response = self.errorResponse(str(ex))

        return self.formatResponse(response)
Exemplo n.º 2
0
    def addAdmin(self):
        """
        Add a new admin to the system
        """

        response = None

        postdata = cherrypy.request.json

        if 'admin' not in postdata:
            raise cherrypy.HTTPError(400)

        adminRequestObject = Admin.getFromDict(postdata['admin'])

        isCrypted = str2bool(postdata['isCrypted'])

        try:
            self.app.admin_api.addAdmin(cherrypy.request.db,
                                        adminRequestObject.getUsername(),
                                        adminRequestObject.getPassword(),
                                        isCrypted,
                                        adminRequestObject.getRealname(),
                                        adminRequestObject.getDescription())
        except Exception as ex:
            self._logger.error(str(ex))
            self.handleException(ex)
            response = self.errorResponse(str(ex))

        return self.formatResponse(response)
Exemplo n.º 3
0
    def getAdmin(self, session: Session, name):
        """
        Get admin from the db.

            Returns:
                Admin tortuga object
            Throws:
                AdminNotFound
                DbError
        """

        return Admin.getFromDbDict(
            self._adminsDbHandler.getAdmin(session, name).__dict__)
Exemplo n.º 4
0
    def getAdminById(self, admin_id):
        """
        Get admin from the db.

            Returns:
                Admin tortuga object
            Throws:
                AdminNotFound
                DbError
        """

        session = DbManager().openSession()

        try:
            return Admin.getFromDbDict(
                self._adminsDbHandler.getAdminById(session, admin_id).__dict__)
        finally:
            DbManager().closeSession()
Exemplo n.º 5
0
    def getAdminList(self):
        """Get admin list.

            Returns:
                [rules]
            Throws:
                UserNotAuthorized
                TortugaException
        """

        url = 'v1/admin'

        try:
            _, responseDict = self.sendSessionRequest(url)

            return Admin.getListFromDict(responseDict)
        except TortugaException:
            raise
        except Exception as ex:
            raise TortugaException(exception=ex)
Exemplo n.º 6
0
    def getAdminById(self, admin_id):
        """Get admin information

            Returns:
                rule
            Throws:
                UserNotAuthorized
                AdminNotFound
                TortugaException
        """

        url = 'v1/admin/%s' % (admin_id)

        try:
            _, responseDict = self.sendSessionRequest(url)

            return Admin.getFromDict(responseDict.get(Admin.ROOT_TAG))
        except TortugaException:
            raise
        except Exception as ex:
            raise TortugaException(exception=ex)
Exemplo n.º 7
0
    def runCommand(self):
        self.parseArgs(
            _("""
Updates a administrative user settings in the Tortuga system.
"""))

        admin = Admin()
        admin.setUsername(self.getArgs().adminUsername)
        admin.setPassword(self.getArgs().adminPassword)
        admin.setRealname(self.getArgs().adminRealname)
        admin.setDescription(self.getArgs().adminDescription)

        admin.setId(self.getArgs().adminId)

        api = self.configureClient(AdminWsApi)
        api.updateAdmin(admin, str(self.getArgs().isCrypted))
Exemplo n.º 8
0
    def runCommand(self):
        self.parseArgs(_("""
Updates a administrative user settings in the Tortuga system.
"""))

        admin = Admin()
        admin.setUsername(self.getArgs().adminUsername)
        admin.setPassword(self.getArgs().adminPassword)
        admin.setRealname(self.getArgs().adminRealname)
        admin.setDescription(self.getArgs().adminDescription)

        admin.setId(self.getArgs().adminId)

        api = AdminWsApi(username=self.getUsername(),
                         password=self.getPassword(),
                         baseurl=self.getUrl(),
                         verify=self._verify)

        api.updateAdmin(admin, self.getArgs().isCrypted)