Ejemplo n.º 1
0
    def getTokens(self):
        """
        Get available personal access tokens of the logged in user.
        """
        self.__require_privilaged_access()
        with DBSession(self.__config_db) as session:
            user = self.getLoggedInUser()
            sessionTokens = session.query(Session) \
                .filter(Session.user_name == user) \
                .filter(Session.can_expire.is_(False)) \
                .all()

            result = []
            for t in sessionTokens:
                result.append(
                    SessionTokenData(t.token, t.description,
                                     str(t.last_access)))

            return result
Ejemplo n.º 2
0
    def newToken(self, description):
        """
        Generate a new personal access token with the given description.
        """
        self.__require_privilaged_access()
        with DBSession(self.__config_db) as session:
            token = generate_session_token()
            user = self.getLoggedInUser()
            groups = ';'.join(self.__auth_session.groups)
            session_token = Session(token, user, groups, description, False)

            session.add(session_token)
            session.commit()

            LOG.info(
                "New personal access token '%s...' has been generated "
                "by '%s'.", token[:5], self.getLoggedInUser())

            return SessionTokenData(token, description,
                                    str(session_token.last_access))